summaryrefslogtreecommitdiff
path: root/procurement/views.py
diff options
context:
space:
mode:
authorKyle McFarland <tfkyle@gmail.com>2018-10-21 19:26:32 -0600
committerKyle McFarland <tfkyle@gmail.com>2018-10-21 19:26:32 -0600
commit377985be10cb959fa975e9cddc5161d346f3d2c6 (patch)
tree8caf1ea9b50e487657930ca0fda71fd8920af8ec /procurement/views.py
parent02ede72ce9ddeb4d7d7241503585bb07fe3e2c50 (diff)
downloadcoding-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/views.py')
-rw-r--r--procurement/views.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/procurement/views.py b/procurement/views.py
index 1516455..c1e66c9 100644
--- a/procurement/views.py
+++ b/procurement/views.py
@@ -1,6 +1,6 @@
from django.views.generic import FormView, TemplateView
-from procurement.forms import ComponentSearchForm
+from procurement.forms import ComponentSearchForm, SupplierSearchForm
from procurement.models import Supplier, Component, Representative
@@ -49,6 +49,26 @@ class ComponentSearchView(FormView):
return super(ComponentSearchView, self).get(self.request)
+class SupplierSearchView(FormView):
+ template_name = "procurement/view_suppliers.html"
+ form_class = SupplierSearchForm
+
+ supplier = None
+ component_form = None
+
+ def form_valid(self, form):
+ self.supplier = form.cleaned_data['supplier']
+ if self.supplier:
+ self.component_form = ComponentSearchForm()
+ self.component_form.fields["component"].queryset = self.supplier.components
+ return super(SupplierSearchView, self).get(self.request)
+
+ def get_context_data(self):
+ context = super().get_context_data()
+ context["supplier"] = self.supplier
+ context["component_form"] = self.component_form
+ context["page_name"] = "View Supplier Details"
+ return context
class DocumentationView(TemplateView):
template_name = 'procurement/documentation.html'