Updates for build app

- Added 'allocate' page (empty thus far)
- Added 'cancel' button and view
This commit is contained in:
Oliver 2018-04-30 00:23:44 +10:00
parent a9c20f5d95
commit 5185173639
6 changed files with 79 additions and 5 deletions

View File

@ -19,10 +19,10 @@ class EditBuildForm(forms.ModelForm):
model = Build
fields = [
'title',
'notes',
'part',
'batch',
'quantity',
'status',
'completion_date',
'batch',
'notes',
# 'status',
# 'completion_date',
]

View File

@ -0,0 +1,16 @@
{% extends "base.html" %}
{% load static %}
{% block content %}
<h3>Allocate Parts for Build</h3>
<h4><a href="{% url 'build-detail' build.id %}">{{ build.title }}</a></h4>
<hr>
<table class='table table-striped' id='part-table'>
</table>
{% endblock %}

View File

@ -0,0 +1,3 @@
Are you sure you wish to cancel this build?
{% include "modal_csrf.html" %}

View File

@ -58,6 +58,10 @@
<div class='container-fluid'>
<button class="btn btn-info" id='edit-build'>Edit Build</button>
{% if build.is_active %}
<a href="{% url 'build-allocate' build.id %}"><button class='btn btn-primary' id='allocate-build'>Allocate Parts</button></a>
<button class='btn btn-warning' id='cancel-build'>Cancel Build</button>
{% endif %}
</div>
{% 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 %}

View File

@ -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'),
]

View File

@ -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',
}