-#
-# View all files
-#
-@with_repo
-def file_list(request, repo):
- paginator = Paginator( repo.file_list('default'), 100);
- bookform = forms.BookUploadForm()
-
- try:
- page = int(request.GET.get('page', '1'))
- except ValueError:
- page = 1
-
- try:
- files = paginator.page(page)
- except (EmptyPage, InvalidPage):
- files = paginator.page(paginator.num_pages)
-
- return direct_to_template(request, 'explorer/file_list.html', extra_context={
- 'files': files, 'page': page, 'bookform': bookform,
- })
-
-@permission_required('explorer.can_add_files')
-@with_repo
-def file_upload(request, repo):
- other_errors = []
- if request.method == 'POST':
- form = forms.BookUploadForm(request.POST, request.FILES)
- if form.is_valid():
- try:
- # prepare the data
- f = request.FILES['file']
- decoded = f.read().decode('utf-8')
-
- def upload_action():
- print 'Adding file: %s' % f.name
- repo._add_file(f.name, f.read().decode('utf-8'))
- repo._commit(
- message="File %s uploaded from platform by %s" %\
- (f.name, request.user.username), \
- user=request.user.username \
- )
-
- # end of upload
-
- repo.in_branch(upload_action, 'default')
-
- # if everything is ok, redirect to the editor
- return HttpResponseRedirect( reverse('editor_view',
- kwargs={'path': f.name}) )
-
- except hg.RepositoryException, e:
- other_errors.append(u'Błąd repozytorium: ' + unicode(e) )
- except UnicodeDecodeError, e:
- other_errors.append(u'Niepoprawne kodowanie pliku: ' + e.reason \
- + u'. Żądane kodowanie: ' + e.encoding)
- # invalid form
+@login_required
+def display_editor(request, path):
+ user = request.GET.get('user', request.user.username)
+ gallery_form = forms.GalleryChoiceForm()
+
+ return render_to_response('explorer/editor.html',
+ # mimetype="text/html",
+ dictionary = {
+ 'fileid': path,
+ 'euser': user,
+ 'gallery_form': gallery_form,
+ 'available_themes': ({'first_letter': t.name[0].upper(), 'name': t.name} for t in Theme.objects.order_by('name')),
+ }, context_instance=RequestContext(request))