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:
parent
63c9a23ced
commit
bb52a108d1
7 changed files with 84 additions and 9 deletions
|
@ -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',
|
||||||
|
]
|
||||||
|
|
Binary file not shown.
|
@ -8,7 +8,7 @@ msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: PACKAGE VERSION\n"
|
"Project-Id-Version: PACKAGE VERSION\n"
|
||||||
"Report-Msgid-Bugs-To: \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"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
|
@ -98,6 +98,12 @@ msgstr "Perforation"
|
||||||
msgid "This is not your print job"
|
msgid "This is not your print job"
|
||||||
msgstr "Ceci n'est pas votre tache"
|
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
|
#: settings.py:20
|
||||||
msgid "A4"
|
msgid "A4"
|
||||||
msgstr "A4"
|
msgstr "A4"
|
||||||
|
@ -178,7 +184,13 @@ msgstr "Début"
|
||||||
msgid "Number"
|
msgid "Number"
|
||||||
msgstr "Exemplaires"
|
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"
|
msgid "for"
|
||||||
msgstr "pour"
|
msgstr "pour"
|
||||||
|
|
||||||
|
@ -243,15 +255,15 @@ msgstr ""
|
||||||
"Le fichier a une taille de %(size)s. La taille maximum autorisée est "
|
"Le fichier a une taille de %(size)s. La taille maximum autorisée est "
|
||||||
"%(max_size)s."
|
"%(max_size)s."
|
||||||
|
|
||||||
#: views.py:84
|
#: views.py:85
|
||||||
msgid "Next"
|
msgid "Next"
|
||||||
msgstr "Suivant"
|
msgstr "Suivant"
|
||||||
|
|
||||||
#: views.py:115
|
#: views.py:117 views.py:143
|
||||||
msgid "Print"
|
msgid "Print"
|
||||||
msgstr "Imprimer"
|
msgstr "Imprimer"
|
||||||
|
|
||||||
#: views.py:144
|
#: views.py:172
|
||||||
msgid "You are not allowed to print"
|
msgid "You are not allowed to print"
|
||||||
msgstr "Vous n'êtes pas autorisé à imprimer"
|
msgstr "Vous n'êtes pas autorisé à imprimer"
|
||||||
|
|
||||||
|
|
|
@ -242,6 +242,14 @@ class JobWithOptions(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model
|
||||||
else:
|
else:
|
||||||
return False, _("This is not your print job")
|
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):
|
def __init__(self, *args, **kwargs):
|
||||||
super(JobWithOptions, self).__init__(*args, **kwargs)
|
super(JobWithOptions, self).__init__(*args, **kwargs)
|
||||||
self.field_permissions = {
|
self.field_permissions = {
|
||||||
|
|
|
@ -34,6 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
<th>{% trans "Status" %}</th>
|
<th>{% trans "Status" %}</th>
|
||||||
<th>{% trans "Number" %}</th>
|
<th>{% trans "Number" %}</th>
|
||||||
<th>{% trans "Price" %}</th>
|
<th>{% trans "Price" %}</th>
|
||||||
|
<th>{% trans "Print again" %}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
{% for job in jobs_list %}
|
{% for job in jobs_list %}
|
||||||
|
@ -45,6 +46,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
<td>{{ job.status }}</td>
|
<td>{{ job.status }}</td>
|
||||||
<td>{{ job.count }}</td>
|
<td>{{ job.count }}</td>
|
||||||
<td>{{ job.price }}</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>
|
</tr>
|
||||||
{% acl_end %}
|
{% acl_end %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -14,5 +14,7 @@ from . import views
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^new_job/$', views.new_job, name="new-job"),
|
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'^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'),
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -26,6 +26,7 @@ from .models import (
|
||||||
)
|
)
|
||||||
from .forms import (
|
from .forms import (
|
||||||
JobWithOptionsForm,
|
JobWithOptionsForm,
|
||||||
|
PrintAgainForm
|
||||||
)
|
)
|
||||||
|
|
||||||
from preferences.models import GeneralOption
|
from preferences.models import GeneralOption
|
||||||
|
@ -91,6 +92,7 @@ def new_job(request):
|
||||||
@login_required
|
@login_required
|
||||||
@can_edit(PrintOperation)
|
@can_edit(PrintOperation)
|
||||||
def print_job(request, printoperation, **_kwargs):
|
def print_job(request, printoperation, **_kwargs):
|
||||||
|
"""Print a job, confirm after new job step"""
|
||||||
jobs_to_edit = JobWithOptions.objects.filter(print_operation=printoperation)
|
jobs_to_edit = JobWithOptions.objects.filter(print_operation=printoperation)
|
||||||
job_modelformset = modelformset_factory(
|
job_modelformset = modelformset_factory(
|
||||||
JobWithOptions,
|
JobWithOptions,
|
||||||
|
@ -118,6 +120,32 @@ def print_job(request, printoperation, **_kwargs):
|
||||||
request
|
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):
|
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,
|
### 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.
|
### Either we weren't able to pay and we need to cancel the jobs.
|
||||||
jobs = JobWithOptions.objects.filter(id__in=users[user][1])
|
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:
|
for job in jobs:
|
||||||
job.status = 'Cancelled'
|
job.status = 'Cancelled'
|
||||||
job.save()
|
job.save()
|
||||||
|
@ -180,6 +208,8 @@ def payment(request, jobs):
|
||||||
def index_jobs(request):
|
def index_jobs(request):
|
||||||
""" Display jobs"""
|
""" Display jobs"""
|
||||||
pagination_number = GeneralOption.get_cached_value('pagination_number')
|
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)
|
jobs_list = re2o_paginator(request, jobs, pagination_number)
|
||||||
return render(request, 'printer/index_jobs.html', {'jobs_list': jobs_list})
|
return render(request, 'printer/index_jobs.html', {'jobs_list': jobs_list})
|
||||||
|
|
Loading…
Reference in a new issue