diff options
author | Kyle McFarland <tfkyle@gmail.com> | 2018-10-21 19:26:32 -0600 |
---|---|---|
committer | Kyle McFarland <tfkyle@gmail.com> | 2018-10-21 19:26:32 -0600 |
commit | 377985be10cb959fa975e9cddc5161d346f3d2c6 (patch) | |
tree | 8caf1ea9b50e487657930ca0fda71fd8920af8ec /procurement/forms.py | |
parent | 02ede72ce9ddeb4d7d7241503585bb07fe3e2c50 (diff) | |
download | coding-assignment-377985be10cb959fa975e9cddc5161d346f3d2c6.zip coding-assignment-377985be10cb959fa975e9cddc5161d346f3d2c6.tar.gz coding-assignment-377985be10cb959fa975e9cddc5161d346f3d2c6.tar.bz2 |
Add view suppliers view and suppliers API endpoint
This adds a simple view (mostly cribbed from the component view but
without the database stats) to view details for a given supplier,
currently lists the components they supply and name/email address pairs for
representatives however there's room to add fields for other representative
contact and company information as well.
On the API side this adds 3 endpoints:
* api/suppliers: returns a list of all suppliers and their
representatives
* api/suppliers/<id>: returns a supplier object containing the
representatives for the given supplier
* api/suppliers/<id>/components: returns a supplier object
containing a list of components supplied by the given supplier
This also contains minor documentation and base template changes, fixing
the navigation menu to use class="active" on the currently selected page
(previously didn't work due to page_name capitalization)
Diffstat (limited to 'procurement/forms.py')
-rw-r--r-- | procurement/forms.py | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/procurement/forms.py b/procurement/forms.py index 4e8b0aa..0aeca9b 100644 --- a/procurement/forms.py +++ b/procurement/forms.py @@ -1,14 +1,24 @@ from django import forms -from procurement.models import Component +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(forms.Form): +class ComponentSearchForm(FormControlBase): + _formcontrol_fields = ["component"] component = forms.ModelChoiceField( queryset=Component.objects.all(), required=False ) - def __init__(self, *args, **kwargs): - super(ComponentSearchForm, self).__init__(*args, **kwargs) - self.fields['component'].widget.attrs.update({"class": "form-control"}) +class SupplierSearchForm(FormControlBase): + _formcontrol_fields = ["supplier"] + supplier = forms.ModelChoiceField( + queryset=Supplier.objects.filter(is_authorized=True), + required=False + ) |