mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-25 04:43:10 +00:00
[Printer] Limit PrintAs to clubs request.user belongs to
This commit is contained in:
parent
909c378c3f
commit
3e4b39bedb
2 changed files with 14 additions and 4 deletions
|
@ -3,7 +3,6 @@
|
||||||
"""printer.forms
|
"""printer.forms
|
||||||
Form to add, edit, cancel printer jobs.
|
Form to add, edit, cancel printer jobs.
|
||||||
Author : Maxime Bombar <bombar@crans.org>.
|
Author : Maxime Bombar <bombar@crans.org>.
|
||||||
Date : 29/06/2018
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
@ -16,6 +15,8 @@ import itertools
|
||||||
|
|
||||||
from re2o.mixins import FormRevMixin
|
from re2o.mixins import FormRevMixin
|
||||||
|
|
||||||
|
from users.models import User
|
||||||
|
|
||||||
from .models import (
|
from .models import (
|
||||||
JobWithOptions,
|
JobWithOptions,
|
||||||
)
|
)
|
||||||
|
@ -24,9 +25,11 @@ from .models import (
|
||||||
class JobWithOptionsForm(FormRevMixin, ModelForm):
|
class JobWithOptionsForm(FormRevMixin, ModelForm):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
||||||
|
self.user = kwargs.pop('user')
|
||||||
super(JobWithOptionsForm, self).__init__(*args, prefix=prefix, **kwargs)
|
super(JobWithOptionsForm, self).__init__(*args, prefix=prefix, **kwargs)
|
||||||
self.fields['printAs'].label = 'Print As'
|
self.fields['printAs'].label = 'Print As'
|
||||||
self.fields['printAs'].empty_label = 'Print As'
|
self.fields['printAs'].empty_label = 'Print As'
|
||||||
|
self.fields['printAs'].queryset = self.user.adherent.club_members.all()
|
||||||
self.fields['disposition'].label = 'disposition'
|
self.fields['disposition'].label = 'disposition'
|
||||||
self.fields['color'].label = 'color'
|
self.fields['color'].label = 'color'
|
||||||
self.fields['count'].label = 'count'
|
self.fields['count'].label = 'count'
|
||||||
|
@ -45,8 +48,10 @@ class JobWithOptionsForm(FormRevMixin, ModelForm):
|
||||||
class PrintForm(FormRevMixin, ModelForm):
|
class PrintForm(FormRevMixin, ModelForm):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
||||||
|
self.user = kwargs.pop('user')
|
||||||
super(PrintForm, self).__init__(*args, prefix=prefix, **kwargs)
|
super(PrintForm, self).__init__(*args, prefix=prefix, **kwargs)
|
||||||
self.fields['printAs'].label = 'Print As'
|
self.fields['printAs'].label = 'Print As'
|
||||||
|
self.fields['printAs'].queryset = self.user.adherent.club_members.all()
|
||||||
self.fields['disposition'].label = 'disposition'
|
self.fields['disposition'].label = 'disposition'
|
||||||
self.fields['color'].label = 'color'
|
self.fields['color'].label = 'color'
|
||||||
self.fields['count'].label = 'count'
|
self.fields['count'].label = 'count'
|
||||||
|
|
|
@ -49,6 +49,7 @@ def new_job(request):
|
||||||
job_formset = formset_factory(JobWithOptionsForm)(
|
job_formset = formset_factory(JobWithOptionsForm)(
|
||||||
request.POST,
|
request.POST,
|
||||||
request.FILES,
|
request.FILES,
|
||||||
|
form_kwargs={'user': request.user},
|
||||||
)
|
)
|
||||||
|
|
||||||
if job_formset.is_valid():
|
if job_formset.is_valid():
|
||||||
|
@ -85,7 +86,10 @@ def new_job(request):
|
||||||
# raise ValidationError("'%(plop)s'", code='plop', params = {'plop': job_data })
|
# raise ValidationError("'%(plop)s'", code='plop', params = {'plop': job_data })
|
||||||
data.append(job_data)
|
data.append(job_data)
|
||||||
i+=1
|
i+=1
|
||||||
job_formset_filled_in = formset_factory(PrintForm, extra=0)(initial=data)
|
job_formset_filled_in = formset_factory(PrintForm, extra=0)(
|
||||||
|
initial=data,
|
||||||
|
form_kwargs={'user': request.user},
|
||||||
|
)
|
||||||
return form(
|
return form(
|
||||||
{
|
{
|
||||||
'jobform': job_formset_filled_in,
|
'jobform': job_formset_filled_in,
|
||||||
|
@ -102,6 +106,7 @@ def new_job(request):
|
||||||
n = int(request.POST['form-TOTAL_FORMS'])
|
n = int(request.POST['form-TOTAL_FORMS'])
|
||||||
job_formset = formset_factory(PrintForm)(
|
job_formset = formset_factory(PrintForm)(
|
||||||
request.POST,
|
request.POST,
|
||||||
|
form_kwargs={'user': request.user},
|
||||||
)
|
)
|
||||||
jids = [request.session['id-form-%s-file' % i] for i in range(n)]
|
jids = [request.session['id-form-%s-file' % i] for i in range(n)]
|
||||||
# raise ValidationError("'%(path)s'", code='path', params = {'path': id_list })
|
# raise ValidationError("'%(path)s'", code='path', params = {'path': id_list })
|
||||||
|
@ -125,8 +130,8 @@ def new_job(request):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
job_formset = formset_factory(JobWithOptionsForm)(
|
job_formset = formset_factory(JobWithOptionsForm)(
|
||||||
None,
|
form_kwargs={'user': request.user}
|
||||||
)
|
)
|
||||||
return form(
|
return form(
|
||||||
{
|
{
|
||||||
'jobform': job_formset,
|
'jobform': job_formset,
|
||||||
|
|
Loading…
Reference in a new issue