- 'REDMINE_URL': settings.REDMINE_URL,
- })
-
-
-@require_GET
-def editor_readonly(request, slug, template_name='wiki/document_details_readonly.html'):
- try:
- book = Book.objects.get(slug=slug)
- revision = request.GET['revision']
- except KeyError:
- raise http.Http404
-
- access_time = datetime.now()
- last_books = request.session.get("wiki_last_books", {})
- last_books[slug] = {
- 'time': access_time,
- 'title': book.title,
- }
-
- if len(last_books) > MAX_LAST_DOCS:
- oldest_key = min(last_books, key=operator.itemgetter('time'))
- del last_books[oldest_key]
- request.session['wiki_last_books'] = last_books
-
- return direct_to_template(request, template_name, extra_context={
- 'book': book,
- 'revision': revision,
- 'readonly': True,
- 'REDMINE_URL': settings.REDMINE_URL,
- })
-
-
-def create_missing(request, slug):
- slug = slug.replace(' ', '-')
-
- if request.method == "POST":
- form = DocumentCreateForm(request.POST, request.FILES)
- if form.is_valid():
-
- if request.user.is_authenticated():
- creator = request.user
- else:
- creator = None
- book = Book.create(creator=creator,
- slug=form.cleaned_data['slug'],
- title=form.cleaned_data['title'],
- text=form.cleaned_data['text'],
- )
-
- return http.HttpResponseRedirect(reverse("wiki_editor", args=[book.slug]))
- else:
- form = DocumentCreateForm(initial={
- "slug": slug,
- "title": slug.replace('-', ' ').title(),
- })
-
- return direct_to_template(request, "wiki/document_create_missing.html", extra_context={
- "slug": slug,
- "form": form,
- })
-
-
-def upload(request):
- if request.method == "POST":
- form = DocumentsUploadForm(request.POST, request.FILES)
- if form.is_valid():
- import slughifi
-
- if request.user.is_authenticated():
- creator = request.user
- else:
- creator = None
-
- zip = form.cleaned_data['zip']
- skipped_list = []
- ok_list = []
- error_list = []
- slugs = {}
- existing = [book.slug for book in Book.objects.all()]
- for filename in zip.namelist():
- if filename[-1] == '/':
- continue
- title = os.path.basename(filename)[:-4]
- slug = slughifi(title)
- if not (slug and filename.endswith('.xml')):
- skipped_list.append(filename)
- elif slug in slugs:
- error_list.append((filename, slug, _('Slug already used for %s' % slugs[slug])))
- elif slug in existing:
- error_list.append((filename, slug, _('Slug already used in repository.')))
- else:
- try:
- zip.read(filename).decode('utf-8') # test read
- ok_list.append((filename, slug, title))
- except UnicodeDecodeError:
- error_list.append((filename, title, _('File should be UTF-8 encoded.')))
- slugs[slug] = filename
-
- if not error_list:
- for filename, slug, title in ok_list:
- Book.create(creator=creator,
- slug=slug,
- title=title,
- text=zip.read(filename).decode('utf-8'),
- )
-
- return direct_to_template(request, "wiki/document_upload.html", extra_context={
- "form": form,
- "ok_list": ok_list,
- "skipped_list": skipped_list,
- "error_list": error_list,
- })
- else:
- form = DocumentsUploadForm()
-
- return direct_to_template(request, "wiki/document_upload.html", extra_context={
- "form": form,