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,
|
|
|
|
)
|
|
|
|
|
|
|
|
import itertools
|
|
|
|
|
|
|
|
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-06-29 03:05:15 +00:00
|
|
|
class JobWithOptionsForm(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-15 00:03:13 +00:00
|
|
|
self.user = kwargs.pop('user')
|
2018-06-29 03:05:15 +00:00
|
|
|
super(JobWithOptionsForm, self).__init__(*args, prefix=prefix, **kwargs)
|
2018-09-08 10:46:52 +00:00
|
|
|
self.fields['printAs'].label = 'Print As'
|
2018-10-19 23:46:46 +00:00
|
|
|
self.fields['printAs'].empty_label = self.user.pseudo
|
2018-10-15 00:03:13 +00:00
|
|
|
self.fields['printAs'].queryset = self.user.adherent.club_members.all()
|
2018-09-08 10:46:52 +00:00
|
|
|
self.fields['disposition'].label = 'disposition'
|
|
|
|
self.fields['color'].label = 'color'
|
|
|
|
self.fields['count'].label = 'count'
|
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
|
|
|
|
|
|
|
|
|
|
|
class PrintForm(FormRevMixin, ModelForm):
|
2018-10-21 17:48:10 +00:00
|
|
|
|
|
|
|
jid = forms.IntegerField(widget=forms.HiddenInput())
|
|
|
|
|
2018-09-08 10:46:52 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
2018-10-15 00:03:13 +00:00
|
|
|
self.user = kwargs.pop('user')
|
2018-09-08 10:46:52 +00:00
|
|
|
super(PrintForm, self).__init__(*args, prefix=prefix, **kwargs)
|
|
|
|
self.fields['printAs'].label = 'Print As'
|
2018-10-20 00:07:46 +00:00
|
|
|
self.fields['printAs'].empty_label = self.user.pseudo
|
2018-10-15 00:03:13 +00:00
|
|
|
self.fields['printAs'].queryset = self.user.adherent.club_members.all()
|
2018-09-08 10:46:52 +00:00
|
|
|
self.fields['disposition'].label = 'disposition'
|
|
|
|
self.fields['color'].label = 'color'
|
|
|
|
self.fields['count'].label = 'count'
|
|
|
|
|
2018-10-21 17:48:10 +00:00
|
|
|
self.fields['jid'].widget.attrs['readonly'] = True
|
2018-09-08 10:46:52 +00:00
|
|
|
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',
|
2018-10-21 17:48:10 +00:00
|
|
|
'paid',
|
2018-09-08 10:46:52 +00:00
|
|
|
]
|