summaryrefslogtreecommitdiff
path: root/procurement/forms.py
blob: 0aeca9b932fbe6a27d41ca0e10d462dec76f1421 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from django import forms
from procurement.models import Component, Supplier

class FormControlBase(forms.Form):
    _formcontrol_fields = []
    def __init__(self, *args, **kwargs):
        super(FormControlBase, self).__init__(*args, **kwargs)
        for fieldname in self._formcontrol_fields:
            self.fields[fieldname].widget.attrs.update({"class": "form-control"})

class ComponentSearchForm(FormControlBase):
    _formcontrol_fields = ["component"]
    component = forms.ModelChoiceField(
        queryset=Component.objects.all(),
        required=False
    )

class SupplierSearchForm(FormControlBase):
    _formcontrol_fields = ["supplier"]
    supplier = forms.ModelChoiceField(
        queryset=Supplier.objects.filter(is_authorized=True),
        required=False
    )