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 3028f4de..100d1402 100644 Binary files a/printer/locale/fr/LC_MESSAGES/django.mo and b/printer/locale/fr/LC_MESSAGES/django.mo differ diff --git a/printer/locale/fr/LC_MESSAGES/django.po b/printer/locale/fr/LC_MESSAGES/django.po index d608a85c..28604a06 100644 --- a/printer/locale/fr/LC_MESSAGES/django.po +++ b/printer/locale/fr/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-10-26 17:50+0200\n" +"POT-Creation-Date: 2018-10-27 04:34+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \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})