summaryrefslogtreecommitdiff
path: root/procurement/views.py
diff options
context:
space:
mode:
authorworkmai <iain.workman@lightsource.ca>2018-10-04 12:14:39 -0600
committerworkmai <iain.workman@lightsource.ca>2018-10-04 12:14:39 -0600
commit12d1f9fd979c11b9e3a3a89b1595b07569b88f79 (patch)
treeaf591040768b104f4bb840a21a92968848a0ffe6 /procurement/views.py
downloadcoding-assignment-12d1f9fd979c11b9e3a3a89b1595b07569b88f79.zip
coding-assignment-12d1f9fd979c11b9e3a3a89b1595b07569b88f79.tar.gz
coding-assignment-12d1f9fd979c11b9e3a3a89b1595b07569b88f79.tar.bz2
Initial commit of the coding assignment base project
Diffstat (limited to 'procurement/views.py')
-rw-r--r--procurement/views.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/procurement/views.py b/procurement/views.py
new file mode 100644
index 0000000..8891f89
--- /dev/null
+++ b/procurement/views.py
@@ -0,0 +1,54 @@
+from django.views.generic import FormView, TemplateView
+
+from procurement.forms import ComponentSearchForm
+from procurement.models import Supplier, Component
+
+
+class ComponentSearchView(FormView):
+ template_name = 'procurement/source_components.html'
+ form_class = ComponentSearchForm
+
+ component = None
+ supplier_results = None
+
+ def get_context_data(self):
+ context = super().get_context_data()
+
+ try:
+ suppliers_last_updated = Supplier.objects.latest('updated').time_since_update
+ except Supplier.DoesNotExist:
+ suppliers_last_updated = ''
+
+ try:
+ components_last_updated = Component.objects.latest('updated').time_since_update
+ except Component.DoesNotExist:
+ components_last_updated = ''
+
+ context.update({
+ 'page_name': 'Component Search',
+ 'component': self.component,
+ 'supplier_results': self.supplier_results,
+ 'supplier_count': Supplier.objects.all().count(),
+ 'suppliers_last_updated': suppliers_last_updated,
+ 'component_count': Component.objects.all().count(),
+ 'components_last_updated': components_last_updated,
+ })
+ return context
+
+ def form_valid(self, form):
+ self.component = form.cleaned_data['component']
+ if self.component:
+ self.supplier_results = self.component.suppliers.filter(is_authorized=True)
+
+ return super(ComponentSearchView, self).get(self.request)
+
+
+class DocumentationView(TemplateView):
+ template_name = 'procurement/documentation.html'
+
+ def get_context_data(self):
+ context = super().get_context_data()
+ context.update({
+ 'page_name': 'Documentation',
+ })
+ return context