From 633b91cf88a2ff369d7d3dbcc8bdc3fd20cc68e9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20St=C4=99pniowski?= Date: Fri, 5 Sep 2008 11:07:38 +0200 Subject: [PATCH] Created fragment_sets view and template. --- catalogue/urls.py | 1 + catalogue/views.py | 27 +++++++++++++++++++++++++- templates/catalogue/fragment_sets.html | 17 ++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 templates/catalogue/fragment_sets.html 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 -- 2.20.1