From 51851736391aa456bee9b83369cc8f8b3aa830fb Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 30 Apr 2018 00:23:44 +1000 Subject: [PATCH] Updates for build app - Added 'allocate' page (empty thus far) - Added 'cancel' button and view --- InvenTree/build/forms.py | 8 ++-- InvenTree/build/templates/build/allocate.html | 16 +++++++ InvenTree/build/templates/build/cancel.html | 3 ++ InvenTree/build/templates/build/detail.html | 13 ++++++ InvenTree/build/urls.py | 2 + InvenTree/build/views.py | 42 ++++++++++++++++++- 6 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 InvenTree/build/templates/build/allocate.html create mode 100644 InvenTree/build/templates/build/cancel.html diff --git a/InvenTree/build/forms.py b/InvenTree/build/forms.py index 8eaadc9a5f..ace5a95168 100644 --- a/InvenTree/build/forms.py +++ b/InvenTree/build/forms.py @@ -19,10 +19,10 @@ class EditBuildForm(forms.ModelForm): model = Build fields = [ 'title', - 'notes', 'part', - 'batch', 'quantity', - 'status', - 'completion_date', + 'batch', + 'notes', +# 'status', +# 'completion_date', ] diff --git a/InvenTree/build/templates/build/allocate.html b/InvenTree/build/templates/build/allocate.html new file mode 100644 index 0000000000..8ab194d129 --- /dev/null +++ b/InvenTree/build/templates/build/allocate.html @@ -0,0 +1,16 @@ +{% extends "base.html" %} +{% load static %} + +{% block content %} + +

Allocate Parts for Build

+ +

{{ build.title }}

+ +
+ + + +
+ +{% endblock %} \ No newline at end of file diff --git a/InvenTree/build/templates/build/cancel.html b/InvenTree/build/templates/build/cancel.html new file mode 100644 index 0000000000..d273a14ff5 --- /dev/null +++ b/InvenTree/build/templates/build/cancel.html @@ -0,0 +1,3 @@ +Are you sure you wish to cancel this build? + +{% include "modal_csrf.html" %} \ No newline at end of file diff --git a/InvenTree/build/templates/build/detail.html b/InvenTree/build/templates/build/detail.html index b1c3a11ce9..3188ba50ed 100644 --- a/InvenTree/build/templates/build/detail.html +++ b/InvenTree/build/templates/build/detail.html @@ -58,6 +58,10 @@
+{% if build.is_active %} + + +{% endif %}
{% include 'modals.html' %} @@ -70,6 +74,7 @@ {% endblock %} {% block js_ready %} + $("#build-list").footable(); $("#edit-build").click(function () { @@ -79,4 +84,12 @@ reload: true }); }); + + $("#cancel-build").click(function() { + launchModalForm("#modal-form", + "{% url 'build-cancel' build.id %}", + { + reload: true + }); + }); {% endblock %} diff --git a/InvenTree/build/urls.py b/InvenTree/build/urls.py index 656d111156..a8e4435e24 100644 --- a/InvenTree/build/urls.py +++ b/InvenTree/build/urls.py @@ -4,6 +4,8 @@ from . import views build_detail_urls = [ url(r'^edit/?', views.BuildUpdate.as_view(), name='build-edit'), + url(r'^allocate/?', views.BuildAllocate.as_view(), name='build-allocate'), + url(r'^cancel/?', views.BuildCancel.as_view(), name='build-cancel'), url(r'^.*$', views.BuildDetail.as_view(), name='build-detail'), ] diff --git a/InvenTree/build/views.py b/InvenTree/build/views.py index 5f61770617..97e5a2fb51 100644 --- a/InvenTree/build/views.py +++ b/InvenTree/build/views.py @@ -10,7 +10,8 @@ from .models import Build from .forms import EditBuildForm -from InvenTree.views import AjaxUpdateView, AjaxCreateView +from InvenTree.views import AjaxView, AjaxUpdateView, AjaxCreateView +from django.http import JsonResponse class BuildIndex(ListView): @@ -35,12 +36,41 @@ class BuildIndex(ListView): return context +class BuildCancel(AjaxView): + model = Build + template_name = 'build/cancel.html' + ajax_form_title = 'Cancel Build' + ajax_submit_text = 'Cancel' + context_object_name = 'build' + fields = [] + + def post(self, request, *args, **kwargs): + + build = get_object_or_404(Build, pk=self.kwargs['pk']) + + build.status = Build.CANCELLED + build.save() + + return self.renderJsonResponse(request, None) + + def get_data(self): + return { + 'info': 'Build was cancelled' + } + + class BuildDetail(DetailView): model = Build template_name = 'build/detail.html' context_object_name = 'build' +class BuildAllocate(DetailView): + model = Build + context_object_name = 'build' + template_name = 'build/allocate.html' + + class BuildCreate(AjaxCreateView): model = Build template_name = 'build/create.html' @@ -59,6 +89,11 @@ class BuildCreate(AjaxCreateView): return initials + def get_data(self): + return { + 'success': 'Created new build', + } + class BuildUpdate(AjaxUpdateView): model = Build @@ -67,3 +102,8 @@ class BuildUpdate(AjaxUpdateView): template_name = 'build/update.html' ajax_form_title = 'Edit Build Details' ajax_template_name = 'modal_form.html' + + def get_data(self): + return { + 'info': 'Edited build', + }