aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/dispatch/templates/dispatch/base.html6
-rw-r--r--app/dispatch/templates/dispatch/loads/create.html15
-rw-r--r--app/dispatch/templates/dispatch/loads/detail.html10
-rw-r--r--app/dispatch/templates/dispatch/loads/edit.html15
-rw-r--r--app/dispatch/templates/dispatch/loads/list.html43
-rw-r--r--app/dispatch/urls.py7
-rw-r--r--app/dispatch/views.py82
7 files changed, 174 insertions, 4 deletions
diff --git a/app/dispatch/templates/dispatch/base.html b/app/dispatch/templates/dispatch/base.html
index d7a85a9..37c8830 100644
--- a/app/dispatch/templates/dispatch/base.html
+++ b/app/dispatch/templates/dispatch/base.html
@@ -29,6 +29,7 @@
<ul class="right hide-on-med-and-down">
{% if user.is_authenticated %}
<li><a href="#">Drivers</a></li>
+ <li><a href="{% url 'load_list' %}">Loads</a></li>
<li><a href="{% url 'company_list' %}">Companies</a></li>
<li><a href="#">Contacts</a></li>
<li><a href="{% url 'logout' %}">Logout</a></li>
@@ -40,6 +41,7 @@
<ul id="nav-mobile" class="side-nav">
{% if user.is_authenticated %}
<li><a href="#">Drivers</a></li>
+ <li><a href="{% url 'load_list' %}">Loads</a></li>
<li><a href="#">Companies</a></li>
<li><a href="#">Contacts</a></li>
<li><a href="{% url 'logout' %}">Logout</a></li>
@@ -81,5 +83,9 @@
<!--Import jQuery before materialize.js-->
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="{% static 'materialize/js/materialize.min.js' %}"></script>
+
+ <script>
+ $('select').material_select();
+ </script>
</body>
</html>
diff --git a/app/dispatch/templates/dispatch/loads/create.html b/app/dispatch/templates/dispatch/loads/create.html
new file mode 100644
index 0000000..ae40722
--- /dev/null
+++ b/app/dispatch/templates/dispatch/loads/create.html
@@ -0,0 +1,15 @@
+{% extends 'dispatch/base.html' %}
+
+
+{% block content %}
+<div class="row">
+ <div class="col s12 m6">
+ <h1>New Load</h1>
+ </div>
+</div>
+
+<form action="" method="post">{% csrf_token %}
+ {{ form.as_p }}
+ <input type="submit" class="btn green" value="Save" />
+</form>
+{% endblock %}
diff --git a/app/dispatch/templates/dispatch/loads/detail.html b/app/dispatch/templates/dispatch/loads/detail.html
new file mode 100644
index 0000000..e939fdb
--- /dev/null
+++ b/app/dispatch/templates/dispatch/loads/detail.html
@@ -0,0 +1,10 @@
+{% extends 'dispatch/base.html' %}
+
+
+{% block content %}
+<div class="row">
+ <div class="col s12 m6">
+ <h1>{{ object.name }} details</h1>
+ </div>
+</div>
+{% endblock %}
diff --git a/app/dispatch/templates/dispatch/loads/edit.html b/app/dispatch/templates/dispatch/loads/edit.html
new file mode 100644
index 0000000..fe8460d
--- /dev/null
+++ b/app/dispatch/templates/dispatch/loads/edit.html
@@ -0,0 +1,15 @@
+{% extends 'dispatch/base.html' %}
+
+
+{% block content %}
+<div class="row">
+ <div class="col s12 m6">
+ <h1>{{object.name}}</h1>
+ </div>
+</div>
+
+<form action="" method="post">{% csrf_token %}
+ {{ form.as_p }}
+ <input type="submit" class="btn blue" value="Update" />
+</form>
+{% endblock %}
diff --git a/app/dispatch/templates/dispatch/loads/list.html b/app/dispatch/templates/dispatch/loads/list.html
new file mode 100644
index 0000000..8129907
--- /dev/null
+++ b/app/dispatch/templates/dispatch/loads/list.html
@@ -0,0 +1,43 @@
+{% extends 'dispatch/base.html' %}
+
+
+{% block content %}
+<div class="row">
+ <div class="col s12 m6">
+ <h1>Loads</h1>
+ </div>
+ <div class="col s12 m6 right-align">
+ <a href="{% url 'load_new' %}" class="btn green">Add Load</a>
+ </div>
+</div>
+<table class="striped">
+ <thead>
+ <tr>
+ {% if user.is_superuser %}
+ <td>Driver</td>
+ {% endif %}
+ <th>Date</th>
+ <th>Company</th>
+ <th>Amount</th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for load in object_list %}
+ <tr>
+ {% if user.is_superuser %}
+ <td>{{ load.user.first_name }} {{ load.user.last_name }}</td>
+ {% endif %}
+ <td>{{ load.date }}</td>
+ <td>{{ load.company.name }}</td>
+ <td>{{ load.amount }}</td>
+ <td class="right-align">
+ <a href="{% url 'load_edit' load.id %}" class="btn orange">Edit</a>
+ <a href="{% url 'load_detail' load.id %}" class="btn blue">View</a>
+ </td>
+ </tr>
+ {% empty %}
+ <tr><td colspan="4">No loads yet.</td></tr>
+ {% endfor %}
+ </tbody>
+</table>
+{% endblock %}
diff --git a/app/dispatch/urls.py b/app/dispatch/urls.py
index 688839e..3d33940 100644
--- a/app/dispatch/urls.py
+++ b/app/dispatch/urls.py
@@ -15,4 +15,11 @@ urlpatterns = [
url(r'^companies/view/(?P<pk>\d+)$', views.CompanyDetail.as_view(), name='company_detail'),
url(r'^companies/edit/(?P<pk>\d+)$', views.CompanyUpdate.as_view(), name='company_edit'),
url(r'^companies/delete/(?P<pk>\d+)$', views.CompanyDelete.as_view(), name='company_delete'),
+
+ url(r'^loads/$', views.LoadList.as_view(), name='load_list'),
+ url(r'^loads/new$', views.LoadCreate.as_view(), name='load_new'),
+ url(r'^loads/view/(?P<pk>\d+)$', views.LoadDetail.as_view(), name='load_detail'),
+ url(r'^loads/edit/(?P<pk>\d+)$', views.LoadUpdate.as_view(), name='load_edit'),
+ url(r'^loads/delete/(?P<pk>\d+)$', views.LoadDelete.as_view(), name='load_delete'),
+
]
diff --git a/app/dispatch/views.py b/app/dispatch/views.py
index 600a746..8101ac0 100644
--- a/app/dispatch/views.py
+++ b/app/dispatch/views.py
@@ -9,12 +9,33 @@ from django.views.generic import TemplateView,ListView
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.core.urlresolvers import reverse_lazy
-from dispatch.models import Company
+from dispatch.models import Company, Load
def home(request):
return render(request,"dispatch/index.html")
+class FilteredListView(ListView):
+ def get_queryset(self):
+ base_qs = super(FilteredListView, self).get_queryset()
+ if not self.request.user.is_superuser:
+ return base_qs.filter(user=self.request.user)
+ return base_qs
+
+class FilteredUpdateView(UpdateView):
+ def get_queryset(self):
+ base_qs = super(FilteredUpdateView, self).get_queryset()
+ if not self.request.user.is_superuser:
+ return base_qs.filter(user=self.request.user)
+ return base_qs
+
+class FilteredDeleteView(DeleteView):
+ def get_queryset(self):
+ base_qs = super(FilteredDeleteView, self).get_queryset()
+ if not self.request.user.is_superuser:
+ return base_qs.filter(user=self.request.user)
+ return base_qs
+
class CompanyList(ListView):
template_name = "dispatch/companies/list.html"
model = Company
@@ -34,12 +55,65 @@ class CompanyDetail(DetailView):
return context
class CompanyUpdate(UpdateView):
- template_name = "dispatch/companies/edit.html"
+ template_name = "dispatch/loads/edit.html"
model = Company
success_url = reverse_lazy('company_list')
fields = ['name', 'address', 'phone_number','email_address']
class CompanyDelete(DeleteView):
- template_name = "dispatch/companies/delete.html"
+ template_name = "dispatch/loads/delete.html"
model = Company
- success_url = reverse_lazy('company_list') \ No newline at end of file
+ success_url = reverse_lazy('company_list')
+
+# Load CRUD
+
+class LoadList(FilteredListView):
+ template_name = "dispatch/loads/list.html"
+ model = Load
+
+class LoadCreate(CreateView):
+ template_name = "dispatch/loads/create.html"
+ model = Load
+ success_url = reverse_lazy('load_list')
+ fields = ['date', 'company','description','amount']
+
+ def get(self,request):
+ if request.user.is_superuser:
+ self.fields.insert(1,'user')
+ return super(LoadCreate, self).get(request)
+
+ def form_valid(self, form):
+ if not self.request.user.is_superuser:
+ load = form.save(commit=False)
+ load.user = self.request.user
+ return super(LoadCreate, self).form_valid(form)
+
+class LoadDetail(DetailView):
+ template_name = "dispatch/loads/detail.html"
+ model = Load
+
+ def get_context_data(self, **kwargs):
+ context = super(LoadDetail, self).get_context_data(**kwargs)
+ return context
+
+class LoadUpdate(FilteredUpdateView):
+ template_name = "dispatch/loads/edit.html"
+ model = Load
+ success_url = reverse_lazy('load_list')
+ fields = ['date', 'company','description','amount']
+
+ def get(self,request,pk):
+ if request.user.is_superuser:
+ self.fields.insert(1,'user')
+ return super(LoadUpdate, self).get(request)
+
+ def form_valid(self, form):
+ if not self.request.user.is_superuser:
+ load = form.save(commit=False)
+ load.user = self.request.user
+ return super(LoadUpdate, self).form_valid(form)
+
+class LoadDelete(FilteredDeleteView):
+ template_name = "dispatch/loads/delete.html"
+ model = Load
+ success_url = reverse_lazy('load_list') \ No newline at end of file