url(r'^$', 'main_page', name='main_page'),
url(r'^lektury/', 'book_list'),
url(r'^lektura/(?P<slug>[a-zA-Z0-9-]+)/polki/', 'book_sets'),
+ url(r'^fragment/(?P<id>[0-9]+)/polki/', 'fragment_sets'),
url(r'^polki/nowa/$', 'new_set'),
url(r'^lektura/(?P<slug>[a-zA-Z0-9-]+)/$', 'book_detail'),
url(r'^tags/$', 'tags_starting_with', name='hint'),
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>Półki zostały zapisane</p>')
+ return HttpResponse('<p>Półki zostały zapisane.</p>')
else:
return HttpResponseRedirect('/')
else:
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('<p>Aby zarządzać swoimi półkami, musisz się zalogować.</p>')
+
+ 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>Półki zostały zapisane.</p>')
+ 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):
--- /dev/null
+<h2>Półki zawierające fragment</h2>
+{% if not user.tag_set.count %}
+ <p>Nie posiadasz żadnych półek. Jeśli chcesz, możesz utworzyć nową półkę poniżej.</p>
+{% else %}
+ <form action="{% url catalogue.views.fragment_sets fragment.id %}" method="POST" accept-charset="utf-8" class="cuteform">
+ <ol>
+ <li>{{ form.set_ids }}</li>
+ <li><input type="submit" value="Zapisz półki"/></li>
+ </ol>
+ </form>
+{% endif %}
+<hr />
+<form action="{% url catalogue.views.new_set %}" method="POST" accept-charset="utf-8" class="cuteform">
+<ol>
+ <li>{{ new_set_form.name }} <input type="submit" value="Utwórz nową półkę"/></li>
+</ol>
+</form>
\ No newline at end of file