From bab1ca8f66fe8564462497ddde5e55af08c2bde2 Mon Sep 17 00:00:00 2001 From: detraz Date: Fri, 26 Oct 2018 01:18:13 +0200 Subject: [PATCH] [Printer] Refactor form et url --- printer/forms.py | 44 +++++++------------------------------------- printer/urls.py | 3 +-- 2 files changed, 8 insertions(+), 39 deletions(-) diff --git a/printer/forms.py b/printer/forms.py index 3bcc19d0..bb970e88 100644 --- a/printer/forms.py +++ b/printer/forms.py @@ -10,6 +10,7 @@ from django.forms import ( Form, ModelForm, ) +from django.utils.translation import ugettext_lazy as _ import itertools @@ -27,12 +28,12 @@ class JobWithOptionsForm(FormRevMixin, ModelForm): prefix = kwargs.pop('prefix', self.Meta.model.__name__) self.user = kwargs.pop('user') super(JobWithOptionsForm, self).__init__(*args, prefix=prefix, **kwargs) - self.fields['printAs'].label = 'Print As' - self.fields['printAs'].empty_label = self.user.pseudo - self.fields['printAs'].queryset = self.user.adherent.club_members.all() - self.fields['disposition'].label = 'disposition' - self.fields['color'].label = 'color' - self.fields['count'].label = 'count' + if not self.user.adherent.club_members.all(): + self.fields.pop('printAs') + else: + self.fields['printAs'].label = _('Print As') + self.fields['printAs'].empty_label = self.user.pseudo + self.fields['printAs'].queryset = self.user.adherent.club_members.all() class Meta: model = JobWithOptions @@ -46,34 +47,3 @@ class JobWithOptionsForm(FormRevMixin, ModelForm): ] -class PrintForm(FormRevMixin, ModelForm): - - jid = forms.IntegerField(widget=forms.HiddenInput()) - - def __init__(self, *args, **kwargs): - prefix = kwargs.pop('prefix', self.Meta.model.__name__) - self.user = kwargs.pop('user') - super(PrintForm, self).__init__(*args, prefix=prefix, **kwargs) - self.fields['printAs'].label = 'Print As' - self.fields['printAs'].empty_label = self.user.pseudo - self.fields['printAs'].queryset = self.user.adherent.club_members.all() - self.fields['disposition'].label = 'disposition' - self.fields['color'].label = 'color' - self.fields['count'].label = 'count' - - self.fields['jid'].widget.attrs['readonly'] = True - self.fields['printAs'].widget.attrs['readonly'] = True - self.fields['filename'].widget.attrs['readonly'] = True - self.fields['price'].widget.attrs['readonly'] = True - self.fields['pages'].widget.attrs['readonly'] = True - - class Meta: - model = JobWithOptions - exclude = [ - 'user', - 'starttime', - 'endtime', - 'status', - 'file', - 'paid', - ] diff --git a/printer/urls.py b/printer/urls.py index 7d5fa0f8..92dbb4ce 100644 --- a/printer/urls.py +++ b/printer/urls.py @@ -13,6 +13,5 @@ from . import views urlpatterns = [ url(r'^new_job/$', views.new_job, name="new-job"), - url(r'^success/$', views.success, name="success"), - url(r'^payment/$', views.payment, name="payment"), + url(r'^print_job/(?P[0-9]+)$', views.print_job, name='print-job') ]