From: Jan Szejko Date: Wed, 29 Nov 2017 11:19:41 +0000 (+0100) Subject: mark books final by form X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/91dd7bde79124d1258984b264f8f80188c2383c6?ds=sidebyside;hp=886286a97f29204af33d0061ae51eb1b19ec0441 mark books final by form --- diff --git a/apps/catalogue/forms.py b/apps/catalogue/forms.py index 40c9608e..bf51f40d 100644 --- a/apps/catalogue/forms.py +++ b/apps/catalogue/forms.py @@ -190,7 +190,39 @@ class ReadonlyImageForm(ImageForm): """Form used for not editing an Image.""" def __init__(self, *args, **kwargs): - ret = super(ReadonlyImageForm, self).__init__(*args, **kwargs) + super(ReadonlyImageForm, self).__init__(*args, **kwargs) for field in self.fields.values(): field.widget.attrs.update({"disabled": "disabled"}) - return ret + + +class MarkFinalForm(forms.Form): + username = forms.CharField(initial='lipszyc') + comment = forms.CharField(initial=u'Ostateczna akceptacja merytoryczna przez kierownika literackiego.') + books = forms.CharField(widget=forms.Textarea, help_text=u'linki do książek w redakcji, po jednym na wiersz') + + def clean_books(self): + books_value = self.cleaned_data['books'] + slugs = [line.split('/')[-2] for line in books_value.split('\n') if line.strip()] + books = Book.objects.filter(slug__in=slugs) + if len(books) != len(slugs): + raise forms.ValidationError( + 'Incorrect slug(s): %s' % ' '.join(slug for slug in slugs if not Book.objects.filter(slug=slug))) + return books + + def clean_username(self): + username = self.cleaned_data['username'] + if not User.objects.filter(username=username): + raise forms.ValidationError('Invalid username') + return username + + def save(self): + for book in self.cleaned_data['books']: + for chunk in book.chunk_set.all(): + src = chunk.head.materialize() + chunk.commit( + text=src, + author=User.objects.get(username=self.cleaned_data['username']), + description=self.cleaned_data['comment'], + tags=[Chunk.tag_model.objects.get(slug='editor-proofreading')], + publishable=True + ) diff --git a/apps/catalogue/templates/catalogue/mark_final.html b/apps/catalogue/templates/catalogue/mark_final.html new file mode 100644 index 00000000..9ed740c0 --- /dev/null +++ b/apps/catalogue/templates/catalogue/mark_final.html @@ -0,0 +1,16 @@ +{% extends "catalogue/base.html" %} + +{% block titleextra %}Oznacz książki{% endblock %} + + +{% block leftcolumn %} + +

Oznacz książki

+ +
+ {% csrf_token %} + {{ form.as_p }} + +
+ +{% endblock leftcolumn %} \ No newline at end of file diff --git a/apps/catalogue/templates/catalogue/mark_final_completed.html b/apps/catalogue/templates/catalogue/mark_final_completed.html new file mode 100644 index 00000000..1b37c836 --- /dev/null +++ b/apps/catalogue/templates/catalogue/mark_final_completed.html @@ -0,0 +1,12 @@ +{% extends "catalogue/base.html" %} + +{% block titleextra %}Oznaczono książki{% endblock %} + + +{% block leftcolumn %} + +

Oznaczono książki

+ +

Książki zostały oznaczone.

+ +{% endblock leftcolumn %} \ No newline at end of file diff --git a/apps/catalogue/urls.py b/apps/catalogue/urls.py index 164ec1b5..022839e8 100644 --- a/apps/catalogue/urls.py +++ b/apps/catalogue/urls.py @@ -57,4 +57,7 @@ urlpatterns = patterns('catalogue.views', url(r'^track/(?P[^/]*)/$', PublishTrackFeed()), url(r'^active/$', 'active_users_list', name='active_users_list'), + + url(r'^mark-final/$', 'mark_final', name='mark_final'), + url(r'^mark-final-completed/$', 'mark_final_completed', name='mark_final_completed'), ) diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index 3d1a47f3..fc572c25 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -15,15 +15,18 @@ from django.db.models import Count, Q from django.db import transaction from django import http from django.http import Http404, HttpResponse, HttpResponseForbidden +from django.http.response import HttpResponseRedirect from django.shortcuts import get_object_or_404, render from django.utils.encoding import iri_to_uri from django.utils.http import urlquote_plus from django.utils.translation import ugettext_lazy as _ from django.views.decorators.http import require_POST +from django_cas.decorators import user_passes_test from apiclient import NotAuthorizedError from catalogue import forms from catalogue import helpers +from catalogue.forms import MarkFinalForm from catalogue.helpers import active_tab from catalogue.models import (Book, Chunk, Image, BookPublishRecord, ChunkPublishRecord, ImagePublishRecord, Project) @@ -642,3 +645,17 @@ def active_users_list(request): }) +@user_passes_test(lambda u: u.is_superuser) +def mark_final(request): + if request.method == 'POST': + form = MarkFinalForm(data=request.POST) + if form.is_valid(): + form.save() + return HttpResponseRedirect(reverse('mark_final_completed')) + else: + form = MarkFinalForm() + return render(request, 'catalogue/mark_final.html', {'form': form}) + + +def mark_final_completed(request): + return render(request, 'catalogue/mark_final_completed.html')