+ if request.is_ajax():
+ return HttpResponse(u'<p>Półka <strong>%s</strong> została usunięta</p>' % user_set.name)
+ else:
+ return HttpResponseRedirect('/')
+
+
+# ==================
+# = Authentication =
+# ==================
+@require_POST
+@cache.never_cache
+def login(request):
+ form = AuthenticationForm(data=request.POST, prefix='login')
+ if form.is_valid():
+ auth.login(request, form.get_user())
+ response_data = {'success': True, 'errors': {}}
+ else:
+ response_data = {'success': False, 'errors': form.errors}
+ return HttpResponse(LazyEncoder(ensure_ascii=False).encode(response_data))
+
+
+@require_POST
+@cache.never_cache
+def register(request):
+ registration_form = UserCreationForm(request.POST, prefix='registration')
+ if registration_form.is_valid():
+ user = registration_form.save()
+ user = auth.authenticate(
+ username=registration_form.cleaned_data['username'],
+ password=registration_form.cleaned_data['password1']
+ )
+ auth.login(request, user)
+ response_data = {'success': True, 'errors': {}}
+ else:
+ response_data = {'success': False, 'errors': registration_form.errors}
+ return HttpResponse(LazyEncoder(ensure_ascii=False).encode(response_data))
+
+
+@cache.never_cache
+def logout_then_redirect(request):
+ auth.logout(request)
+ return HttpResponseRedirect(request.GET.get('next', '/'))
+
+
+
+# =========
+# = Admin =
+# =========
+@login_required
+@staff_required
+def import_book(request):
+ """docstring for import_book"""
+ book_import_form = forms.BookImportForm(request.POST, request.FILES)
+ if book_import_form.is_valid():
+ try:
+ book_import_form.save()
+ except:
+ info = sys.exc_info()
+ exception = pprint.pformat(info[1])
+ tb = '\n'.join(traceback.format_tb(info[2]))
+ return HttpResponse("An error occurred: %s\n\n%s" % (exception, tb), mimetype='text/plain')
+ return HttpResponse("Book imported successfully")
+ else:
+ return HttpResponse("Error importing file: %r" % book_import_form.errors)
\ No newline at end of file