8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-10 03:46:27 +00:00
re2o/printer/forms.py

80 lines
2.3 KiB
Python
Raw Normal View History

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
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__)
self.user = kwargs.pop('user')
2018-06-29 03:05:15 +00:00
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'
2018-06-28 18:20:08 +00:00
class Meta:
model = JobWithOptions
fields = [
'file',
'printAs',
2018-06-28 18:20:08 +00:00
'color',
'disposition',
'format',
2018-06-28 18:20:08 +00:00
'count',
]
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',
]