+#
+# Some useful decorators
+#
+def with_repo(view):
+ """Open a repository for this view"""
+ def view_with_repo(request, *args, **kwargs):
+ kwargs['repo'] = hg.Repository(settings.REPOSITORY_PATH)
+ return view(request, *args, **kwargs)
+ return view_with_repo
+
+#
+def ajax_login_required(view):
+ """Similar ro @login_required, but instead of redirect,
+ just return some JSON stuff with error."""
+ def view_with_auth(request, *args, **kwargs):
+ if request.user.is_authenticated():
+ return view(request, *args, **kwargs)
+ # not authenticated
+ return HttpResponse( json.dumps({'result': 'access_denied'}) );
+ return view_with_auth
+
+#
+# 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)