2018-06-28 18:20:08 +00:00
|
|
|
# -*- mode: python; coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""printer.forms
|
|
|
|
Form to add, edit, cancel printer jobs.
|
|
|
|
Author : Maxime Bombar <bombar@crans.org>.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from django import forms
|
|
|
|
from django.forms import (
|
|
|
|
Form,
|
|
|
|
ModelForm,
|
|
|
|
)
|
2018-10-25 23:18:13 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2018-06-28 18:20:08 +00:00
|
|
|
|
|
|
|
import itertools
|
|
|
|
|
2018-10-26 00:53:57 +00:00
|
|
|
from re2o.field_permissions import FieldPermissionFormMixin
|
2018-06-28 18:20:08 +00:00
|
|
|
from re2o.mixins import FormRevMixin
|
|
|
|
|
2018-10-15 00:03:13 +00:00
|
|
|
from users.models import User
|
|
|
|
|
2018-06-28 18:20:08 +00:00
|
|
|
from .models import (
|
|
|
|
JobWithOptions,
|
2018-11-17 14:29:02 +00:00
|
|
|
Digicode,
|
2018-06-28 18:20:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-10-26 00:53:57 +00:00
|
|
|
class JobWithOptionsForm(FieldPermissionFormMixin, FormRevMixin, ModelForm):
|
2018-06-28 18:20:08 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
2018-10-26 00:53:57 +00:00
|
|
|
user=kwargs.get('user')
|
2018-06-29 03:05:15 +00:00
|
|
|
super(JobWithOptionsForm, self).__init__(*args, prefix=prefix, **kwargs)
|
2018-10-26 00:53:57 +00:00
|
|
|
if 'printAs' in self.fields:
|
2018-10-25 23:18:13 +00:00
|
|
|
self.fields['printAs'].label = _('Print As')
|
2018-10-26 00:53:57 +00:00
|
|
|
self.fields['printAs'].empty_label = user.pseudo
|
|
|
|
self.fields['printAs'].queryset = user.adherent.club_members.all()
|
2018-06-28 18:20:08 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = JobWithOptions
|
|
|
|
fields = [
|
|
|
|
'file',
|
2018-09-08 10:46:52 +00:00
|
|
|
'printAs',
|
2018-06-28 18:20:08 +00:00
|
|
|
'color',
|
|
|
|
'disposition',
|
2018-10-20 13:50:52 +00:00
|
|
|
'format',
|
2018-06-28 18:20:08 +00:00
|
|
|
'count',
|
|
|
|
]
|
2018-09-08 10:46:52 +00:00
|
|
|
|
|
|
|
|
2018-10-27 02:36:24 +00:00
|
|
|
class PrintAgainForm(JobWithOptionsForm):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
user=kwargs.get('user')
|
|
|
|
super(PrintAgainForm, self).__init__(*args, **kwargs)
|
|
|
|
if 'printAs' in self.fields:
|
2018-10-27 03:29:13 +00:00
|
|
|
self.fields['printAs'].empty_label = user.pseudo
|
|
|
|
if self.instance.user != user:
|
|
|
|
self.fields['printAs'].queryset = User.objects.filter(club__in=user.adherent.club_members.all()) | User.objects.filter(id=self.instance.user.id)
|
|
|
|
else:
|
|
|
|
self.fields['printAs'].queryset = user.adherent.club_members.all()
|
2018-10-27 02:36:24 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = JobWithOptions
|
|
|
|
fields = [
|
|
|
|
'printAs',
|
|
|
|
'color',
|
|
|
|
'disposition',
|
|
|
|
'format',
|
|
|
|
'count',
|
2018-11-17 14:29:02 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
class CreateCodeForm(FieldPermissionFormMixin, FormRevMixin, ModelForm):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
|
|
|
# user = kwargs.get('user')
|
|
|
|
super(CreateCodeForm, self).__init__(*args, prefix=prefix, **kwargs)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Digicode
|
|
|
|
fields = [
|
|
|
|
"user",
|
|
|
|
]
|