-@require_POST
-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))
+def search(request):
+ tags = request.GET.get('tags', '')
+ prefix = request.GET.get('q', '')
+ # Prefix must have at least 2 characters
+ if len(prefix) < 2:
+ return HttpResponse('')
+
+ try:
+ tag_list = models.Tag.get_tag_list(tags)
+ except:
+ tag_list = []
+
+ result = _tags_starting_with(prefix, request.user)
+ if len(result) > 0:
+ tag = result[0]
+ if isinstance(tag, models.Book):
+ return HttpResponseRedirect(tag.get_absolute_url())
+ else:
+ tag_list.append(tag)
+
+ return HttpResponseRedirect(reverse('catalogue.views.tagged_object_list',
+ kwargs={'tags': '/'.join(tag.slug for tag in tag_list)}
+ ))
+
+
+def tags_starting_with(request):
+ prefix = request.GET['q']
+ # Prefix must have at least 2 characters
+ if len(prefix) < 2:
+ return HttpResponse('')
+
+ return HttpResponse('\n'.join(tag.name for tag in _tags_starting_with(prefix, request.user)))
+
+
+# ====================
+# = Shelf management =
+# ====================
+@login_required
+@cache.never_cache
+def user_shelves(request):
+ shelves = models.Tag.objects.filter(category='set', user=request.user)
+ new_set_form = forms.NewSetForm()
+ return render_to_response('catalogue/user_shelves.html', locals(),
+ context_instance=RequestContext(request))