- 'REDMINE_URL': settings.REDMINE_URL,
- })
-
-
-@require_GET
-@normalized_name
-def editor_readonly(request, name, template_name='wiki/document_details_readonly.html'):
- name = normalize_name(name)
- storage = getstorage()
-
- try:
- revision = request.GET['revision']
- document = storage.get(name, revision)
- except (KeyError, DocumentNotFound):
- raise http.Http404
-
- access_time = datetime.now()
- last_documents = request.session.get("wiki_last_docs", {})
- last_documents[name] = access_time
-
- if len(last_documents) > MAX_LAST_DOCS:
- oldest_key = min(last_documents, key=last_documents.__getitem__)
- del last_documents[oldest_key]
- request.session['wiki_last_docs'] = last_documents
-
- return direct_to_template(request, template_name, extra_context={
- 'document': document,
- 'document_name': document.name,
- 'document_info': dict(document.info(), readonly=True),
- 'document_meta': document.meta,
- 'REDMINE_URL': settings.REDMINE_URL,
- })
-
-
-@normalized_name
-def create_missing(request, name):
- storage = getstorage()
-
- if request.method == "POST":
- form = DocumentCreateForm(request.POST, request.FILES)
- if form.is_valid():
- doc = storage.create_document(
- name=form.cleaned_data['id'],
- text=form.cleaned_data['text'],
- )
-
- return http.HttpResponseRedirect(reverse("wiki_details", args=[doc.name]))
- else:
- form = DocumentCreateForm(initial={
- "id": name.replace(" ", "_"),
- "title": name.title(),
- })
-
- return direct_to_template(request, "wiki/document_create_missing.html", extra_context={
- "document_name": name,
- "form": form,
- })
-
-
-def upload(request):
- storage = getstorage()
-
- if request.method == "POST":
- form = DocumentsUploadForm(request.POST, request.FILES)
- if form.is_valid():
- zip = form.cleaned_data['zip']
- skipped_list = []
- ok_list = []
- error_list = []
- titles = {}
- existing = storage.all()
- for filename in zip.namelist():
- if filename[-1] == '/':
- continue
- title = normalize_name(os.path.basename(filename)[:-4])
- if not (title and filename.endswith('.xml')):
- skipped_list.append(filename)
- elif title in titles:
- error_list.append((filename, title, _('Title already used for %s' % titles[title])))
- elif title in existing:
- error_list.append((filename, title, _('Title already used in repository.')))
- else:
- ok_list.append((filename, title))
- titles[title] = filename
- if not error_list:
- for filename, title in ok_list:
- storage.create_document(
- name=title,
- text=zip.read(filename)
- )
-
- 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,
- })
- #doc = storage.create_document(
- # name=base,
- # text=form.cleaned_data['text'],
-
-
- return http.HttpResponse('\n'.join(yeslist) + '\n\n' + '\n'.join(nolist))
- else:
- form = DocumentsUploadForm()
-
- return direct_to_template(request, "wiki/document_upload.html", extra_context={
- "form": form,