mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-05 01:16:27 +00:00
["Printer] fix print_as keyerror
This commit is contained in:
parent
91becb9bdb
commit
7c3788f019
3 changed files with 18 additions and 11 deletions
|
@ -14,6 +14,7 @@ from django.utils.translation import ugettext_lazy as _
|
|||
|
||||
import itertools
|
||||
|
||||
from re2o.field_permissions import FieldPermissionFormMixin
|
||||
from re2o.mixins import FormRevMixin
|
||||
|
||||
from users.models import User
|
||||
|
@ -23,17 +24,15 @@ from .models import (
|
|||
)
|
||||
|
||||
|
||||
class JobWithOptionsForm(FormRevMixin, ModelForm):
|
||||
class JobWithOptionsForm(FieldPermissionFormMixin, FormRevMixin, ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
||||
self.user = kwargs.pop('user')
|
||||
user=kwargs.get('user')
|
||||
super(JobWithOptionsForm, self).__init__(*args, prefix=prefix, **kwargs)
|
||||
if not self.user.adherent.club_members.all():
|
||||
self.fields.pop('printAs')
|
||||
else:
|
||||
if 'printAs' in self.fields:
|
||||
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['printAs'].empty_label = user.pseudo
|
||||
self.fields['printAs'].queryset = user.adherent.club_members.all()
|
||||
|
||||
class Meta:
|
||||
model = JobWithOptions
|
||||
|
|
|
@ -19,7 +19,7 @@ from django.utils.translation import ugettext_lazy as _
|
|||
from django.template.defaultfilters import filesizeformat
|
||||
|
||||
from re2o.mixins import RevMixin, AclMixin
|
||||
|
||||
from re2o.field_permissions import FieldPermissionModelMixin
|
||||
import users.models
|
||||
|
||||
from .validators import (
|
||||
|
@ -87,7 +87,7 @@ class PrintOperation(RevMixin, AclMixin, models.Model):
|
|||
return False, _("This is not your print operation task")
|
||||
|
||||
|
||||
class JobWithOptions(RevMixin, AclMixin, models.Model):
|
||||
class JobWithOptions(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
||||
"""
|
||||
This is the main model of printer application :
|
||||
|
||||
|
@ -234,6 +234,15 @@ class JobWithOptions(RevMixin, AclMixin, models.Model):
|
|||
|
||||
return total_price/100
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(JobWithOptions, self).__init__(*args, **kwargs)
|
||||
self.field_permissions = {
|
||||
'printAs': self.can_change_printas,
|
||||
}
|
||||
|
||||
def can_change_printas(self, user_request, *_args, **_kwargs):
|
||||
return user_request.adherent.club_members.all(), None
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self._update_price()
|
||||
super(JobWithOptions, self).save(*args, **kwargs)
|
||||
|
|
|
@ -69,8 +69,7 @@ def new_job(request):
|
|||
job_instance.filename = filename
|
||||
job_instance.print_operation = print_operation
|
||||
job_instance.user=request.user
|
||||
|
||||
job_instance.printAs = job.cleaned_data['printAs'] or request.user
|
||||
job_instance.printAs = job.cleaned_data.get('printAs', request.user)
|
||||
metadata = pdfinfo(request.FILES['form-%s-file' % count].temporary_file_path())
|
||||
job_instance.pages = metadata["Pages"]
|
||||
job_instance.save()
|
||||
|
|
Loading…
Reference in a new issue