From bb52a108d1f9bb4cdf45eb5a53927ba4f38fb199 Mon Sep 17 00:00:00 2001 From: detraz Date: Sat, 27 Oct 2018 04:36:24 +0200 Subject: [PATCH] [Printer] Print again function --- printer/forms.py | 17 ++++++++++++ printer/locale/fr/LC_MESSAGES/django.mo | Bin 3163 -> 3163 bytes printer/locale/fr/LC_MESSAGES/django.po | 22 +++++++++++---- printer/models.py | 8 ++++++ printer/templates/printer/aff_jobs.html | 8 +++++- printer/urls.py | 4 ++- printer/views.py | 34 ++++++++++++++++++++++-- 7 files changed, 84 insertions(+), 9 deletions(-) diff --git a/printer/forms.py b/printer/forms.py index 8dcfa013..7c3d1d50 100644 --- a/printer/forms.py +++ b/printer/forms.py @@ -46,3 +46,20 @@ class JobWithOptionsForm(FieldPermissionFormMixin, FormRevMixin, ModelForm): ] +class PrintAgainForm(JobWithOptionsForm): + def __init__(self, *args, **kwargs): + user=kwargs.get('user') + super(PrintAgainForm, self).__init__(*args, **kwargs) + if 'printAs' in self.fields: + self.fields['printAs'].queryset = User.objects.filter(club__in=user.adherent.club_members.all()) | User.objects.filter(pseudo='dstan') + + + class Meta: + model = JobWithOptions + fields = [ + 'printAs', + 'color', + 'disposition', + 'format', + 'count', + ] diff --git a/printer/locale/fr/LC_MESSAGES/django.mo b/printer/locale/fr/LC_MESSAGES/django.mo index 3028f4de2947fd876f8973d33de2260e89b871d6..100d140264ed575f60cfcb5634d0a26985e15dc8 100644 GIT binary patch delta 20 bcmcaDaa&@;C3bdm1p^Z+W0TD{*_&7ZP!\n" "Language-Team: LANGUAGE \n" @@ -98,6 +98,12 @@ msgstr "Perforation" msgid "This is not your print job" msgstr "Ceci n'est pas votre tache" +#: models.py:251 +#, fuzzy +#| msgid "This is not your print operation task" +msgid "This is not your print operation job" +msgstr "Ceci n'est pas votre tache" + #: settings.py:20 msgid "A4" msgstr "A4" @@ -178,7 +184,13 @@ msgstr "Début" msgid "Number" msgstr "Exemplaires" -#: templates/printer/aff_jobs.html:43 +#: templates/printer/aff_jobs.html:37 +#, fuzzy +#| msgid "Print As" +msgid "Print again" +msgstr "Imprimer à nouveau" + +#: templates/printer/aff_jobs.html:44 msgid "for" msgstr "pour" @@ -243,15 +255,15 @@ msgstr "" "Le fichier a une taille de %(size)s. La taille maximum autorisée est " "%(max_size)s." -#: views.py:84 +#: views.py:85 msgid "Next" msgstr "Suivant" -#: views.py:115 +#: views.py:117 views.py:143 msgid "Print" msgstr "Imprimer" -#: views.py:144 +#: views.py:172 msgid "You are not allowed to print" msgstr "Vous n'êtes pas autorisé à imprimer" diff --git a/printer/models.py b/printer/models.py index 88301e23..7bd2e11a 100644 --- a/printer/models.py +++ b/printer/models.py @@ -242,6 +242,14 @@ class JobWithOptions(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model else: return False, _("This is not your print job") + def can_edit(self, user_request, *args, **kwargs): + if user_request.has_perm('printer.change_jobwithoptions'): + return True, None + elif user_request == self.user or user_request == self.printAs: + return True, None + else: + return False, _("This is not your print operation job") + def __init__(self, *args, **kwargs): super(JobWithOptions, self).__init__(*args, **kwargs) self.field_permissions = { diff --git a/printer/templates/printer/aff_jobs.html b/printer/templates/printer/aff_jobs.html index e33662e1..5eb2f44c 100644 --- a/printer/templates/printer/aff_jobs.html +++ b/printer/templates/printer/aff_jobs.html @@ -34,7 +34,8 @@ with this program; if not, write to the Free Software Foundation, Inc., {% trans "Status" %} {% trans "Number" %} {% trans "Price" %} - + {% trans "Print again" %} + {% for job in jobs_list %} {% can_view job %} @@ -45,6 +46,11 @@ with this program; if not, write to the Free Software Foundation, Inc., {{ job.status }} {{ job.count }} {{ job.price }} + + + + + {% acl_end %} {% endfor %} diff --git a/printer/urls.py b/printer/urls.py index 529062cd..fcf726d1 100644 --- a/printer/urls.py +++ b/printer/urls.py @@ -14,5 +14,7 @@ from . import views urlpatterns = [ url(r'^new_job/$', views.new_job, name="new-job"), url(r'^print_job/(?P[0-9]+)$', views.print_job, name='print-job'), - url(r'^index_jobs/$', views.index_jobs, name="index-jobs") + url(r'^index_jobs/$', views.index_jobs, name="index-jobs"), + url(r'^print_job_again/(?P[0-9]+)$', views.print_job_again, name='print-job-again'), + ] diff --git a/printer/views.py b/printer/views.py index 6928acd2..6b98b24c 100644 --- a/printer/views.py +++ b/printer/views.py @@ -26,6 +26,7 @@ from .models import ( ) from .forms import ( JobWithOptionsForm, + PrintAgainForm ) from preferences.models import GeneralOption @@ -91,6 +92,7 @@ def new_job(request): @login_required @can_edit(PrintOperation) def print_job(request, printoperation, **_kwargs): + """Print a job, confirm after new job step""" jobs_to_edit = JobWithOptions.objects.filter(print_operation=printoperation) job_modelformset = modelformset_factory( JobWithOptions, @@ -118,6 +120,32 @@ def print_job(request, printoperation, **_kwargs): request ) +@login_required +@can_edit(JobWithOptions) +def print_job_again(request, jobwithoptions, **_kwargs): + """Print a job again""" + jobwithoptionsform = formset_factory(PrintAgainForm)( + request.POST or None, + request.FILES or None, + form_kwargs={'user': request.user, 'instance': jobwithoptions}, + ) + if jobwithoptionsform.is_valid(): + for job_form in jobwithoptionsform: + jobwithoptions = job_form.instance + jobwithoptions.pk = None + jobwithoptions.print_operation = PrintOperation.objects.create(user=jobwithoptions.print_operation.user) + jobwithoptions.status = 'Running' + jobwithoptions.save() + return payment(request, [jobwithoptions]) + return form( + { + 'jobform': jobwithoptionsform, + 'action_name': _('Print'), + }, + 'printer/print.html', + request + ) + def payment(request, jobs): """ @@ -160,7 +188,7 @@ def payment(request, jobs): ### If we are here, then either we were able to pay and it's ok, ### Either we weren't able to pay and we need to cancel the jobs. jobs = JobWithOptions.objects.filter(id__in=users[user][1]) - if user.solde - users[user][0] < 0: + if float(user.solde) - float(users[user][0]) < 0: for job in jobs: job.status = 'Cancelled' job.save() @@ -180,6 +208,8 @@ def payment(request, jobs): def index_jobs(request): """ Display jobs""" pagination_number = GeneralOption.get_cached_value('pagination_number') - jobs = JobWithOptions.objects.select_related('user').select_related('print_operation') + jobs = JobWithOptions.objects.select_related('user')\ + .select_related('print_operation')\ + .order_by('starttime').reverse() jobs_list = re2o_paginator(request, jobs, pagination_number) return render(request, 'printer/index_jobs.html', {'jobs_list': jobs_list})