8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-28 15:42:25 +00:00

[Printer] Print again function

This commit is contained in:
detraz 2018-10-27 04:36:24 +02:00 committed by root
parent 63c9a23ced
commit bb52a108d1
7 changed files with 84 additions and 9 deletions

View file

@ -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',
]

View file

@ -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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\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"

View file

@ -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 = {

View file

@ -34,7 +34,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<th>{% trans "Status" %}</th>
<th>{% trans "Number" %}</th>
<th>{% trans "Price" %}</th>
</tr>
<th>{% trans "Print again" %}</th>
</tr>
</thead>
{% for job in jobs_list %}
{% can_view job %}
@ -45,6 +46,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<td>{{ job.status }}</td>
<td>{{ job.count }}</td>
<td>{{ job.price }}</td>
<td>
<a href="{% url 'printer:print-job-again' jobwithoptionsid=job.id %}" class="btn btn-primary btn-sm" role="button">
<i class="fa fa-print"></i>
</a>
</td>
</tr>
{% acl_end %}
{% endfor %}

View file

@ -14,5 +14,7 @@ from . import views
urlpatterns = [
url(r'^new_job/$', views.new_job, name="new-job"),
url(r'^print_job/(?P<printoperationid>[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<jobwithoptionsid>[0-9]+)$', views.print_job_again, name='print-job-again'),
]

View file

@ -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})