From: Marek Stępniowski Date: Fri, 5 Sep 2008 09:07:38 +0000 (+0200) Subject: Created fragment_sets view and template. X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/633b91cf88a2ff369d7d3dbcc8bdc3fd20cc68e9?hp=5761df5a5d4d40ba7c82e1b1277af30cedeb8306 Created fragment_sets view and template. --- diff --git a/catalogue/urls.py b/catalogue/urls.py index c253ba1b0..d454fd478 100644 --- a/catalogue/urls.py +++ b/catalogue/urls.py @@ -6,6 +6,7 @@ urlpatterns = patterns('catalogue.views', url(r'^$', 'main_page', name='main_page'), url(r'^lektury/', 'book_list'), url(r'^lektura/(?P[a-zA-Z0-9-]+)/polki/', 'book_sets'), + url(r'^fragment/(?P[0-9]+)/polki/', 'fragment_sets'), url(r'^polki/nowa/$', 'new_set'), url(r'^lektura/(?P[a-zA-Z0-9-]+)/$', 'book_detail'), url(r'^tags/$', 'tags_starting_with', name='hint'), diff --git a/catalogue/views.py b/catalogue/views.py index 02e77c2d4..08d940164 100644 --- a/catalogue/views.py +++ b/catalogue/views.py @@ -179,7 +179,7 @@ def book_sets(request, slug): book.tags = ([models.Tag.objects.get(pk=id) for id in form.cleaned_data['set_ids']] + list(book.tags.filter(~Q(category='set') | ~Q(user=request.user)))) if request.is_ajax(): - return HttpResponse('

Półki zostały zapisane

') + return HttpResponse('

Półki zostały zapisane.

') else: return HttpResponseRedirect('/') else: @@ -190,6 +190,31 @@ def book_sets(request, slug): context_instance=RequestContext(request)) +def fragment_sets(request, id): + fragment = get_object_or_404(models.Fragment, pk=id) + user_sets = models.Tag.objects.filter(category='set', user=request.user) + fragment_sets = fragment.tags.filter(category='set', user=request.user) + + if not request.user.is_authenticated(): + return HttpResponse('

Aby zarządzać swoimi półkami, musisz się zalogować.

') + + if request.method == 'POST': + form = forms.ObjectSetsForm(fragment, request.user, request.POST) + if form.is_valid(): + fragment.tags = ([models.Tag.objects.get(pk=id) for id in form.cleaned_data['set_ids']] + + list(fragment.tags.filter(~Q(category='set') | ~Q(user=request.user)))) + if request.is_ajax(): + return HttpResponse('

Półki zostały zapisane.

') + else: + return HttpResponseRedirect('/') + else: + form = forms.ObjectSetsForm(book, request.user) + new_set_form = forms.NewSetForm() + + return render_to_response('catalogue/fragment_sets.html', locals(), + context_instance=RequestContext(request)) + + @login_required @require_POST def new_set(request): diff --git a/templates/catalogue/fragment_sets.html b/templates/catalogue/fragment_sets.html new file mode 100644 index 000000000..c7d641ca2 --- /dev/null +++ b/templates/catalogue/fragment_sets.html @@ -0,0 +1,17 @@ +

Półki zawierające fragment

+{% if not user.tag_set.count %} +

Nie posiadasz żadnych półek. Jeśli chcesz, możesz utworzyć nową półkę poniżej.

+{% else %} +
+
    +
  1. {{ form.set_ids }}
  2. +
  3. +
+
+{% endif %} +
+
+
    +
  1. {{ new_set_form.name }}
  2. +
+
\ No newline at end of file