basic ship list page
This commit is contained in:
parent
2513469028
commit
8078cee13f
|
@ -64,7 +64,7 @@ STATIC_URL = '/static/'
|
|||
# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
|
||||
# trailing slash.
|
||||
# Examples: "http://foo.com/media/", "/media/".
|
||||
ADMIN_MEDIA_PREFIX = '/admin/media/'
|
||||
ADMIN_MEDIA_PREFIX = '/static/admin/'
|
||||
|
||||
# Make this unique, creates random key first at first time.
|
||||
try:
|
||||
|
@ -115,12 +115,17 @@ INSTALLED_APPS = (
|
|||
'django.contrib.sites',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'django.contrib.databrowse',
|
||||
'ships',
|
||||
# Uncomment the next line to enable the admin:
|
||||
'django.contrib.admin',
|
||||
# Uncomment the next line to enable admin documentation:
|
||||
'django.contrib.admindocs',
|
||||
'django_extensions'
|
||||
'django_extensions',
|
||||
'django.contrib.databrowse'
|
||||
|
||||
# 'querybuilder',
|
||||
# 'dashboard'
|
||||
)
|
||||
|
||||
try:
|
||||
|
|
|
@ -203,6 +203,7 @@ def importJSON(filename):
|
|||
|
||||
def generateGoodStrings():
|
||||
for g in Good.objects.all():
|
||||
if g.description_string: continue
|
||||
s = getGoodString(g.description)
|
||||
print s
|
||||
g.description_string = s
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
from django.db import models
|
||||
from django.contrib import databrowse
|
||||
from django.db.models import Sum, Avg
|
||||
|
||||
class Manifest(models.Model):
|
||||
month = models.CharField(max_length=3)
|
||||
year = models.IntegerField(max_length=4)
|
||||
filename = models.CharField(max_length=256)
|
||||
month = models.CharField(max_length=3)
|
||||
year = models.IntegerField(max_length=4)
|
||||
filename = models.CharField(max_length=256)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.filename
|
||||
def __unicode__(self):
|
||||
return self.filename
|
||||
|
||||
TYPE_CHOICES = (
|
||||
('Import', 'Import'),
|
||||
|
@ -16,42 +18,55 @@ TYPE_CHOICES = (
|
|||
|
||||
#['type', 'number', 'date', 'ship_name', 'captain', 'flag', 'trader', 'port', 'country']
|
||||
class Ship(models.Model):
|
||||
manifest_file = models.ForeignKey(Manifest)
|
||||
bill_type = models.CharField(max_length=50, choices=TYPE_CHOICES)
|
||||
number = models.IntegerField(max_length=20)
|
||||
date = models.DateField()
|
||||
ship_name = models.CharField(max_length=255)
|
||||
ship_name_trans = models.CharField(max_length=255, blank=True, null=True)
|
||||
captain = models.CharField(max_length=255)
|
||||
captain_trans = models.CharField(max_length=255, blank=True, null=True)
|
||||
flag = models.CharField(max_length=255)
|
||||
owner = models.CharField(max_length=255)
|
||||
owner_trans = models.CharField(max_length=255, blank=True, null=True)
|
||||
port = models.CharField(max_length=255)
|
||||
country = models.CharField(max_length=255)
|
||||
manifest_file = models.ForeignKey(Manifest)
|
||||
bill_type = models.CharField(max_length=50, choices=TYPE_CHOICES)
|
||||
number = models.IntegerField(max_length=20)
|
||||
date = models.DateField()
|
||||
ship_name = models.CharField(max_length=255)
|
||||
ship_name_trans = models.CharField(max_length=255, blank=True, null=True)
|
||||
captain = models.CharField(max_length=255)
|
||||
captain_trans = models.CharField(max_length=255, blank=True, null=True)
|
||||
flag = models.CharField(max_length=255)
|
||||
owner = models.CharField(max_length=255)
|
||||
owner_trans = models.CharField(max_length=255, blank=True, null=True)
|
||||
port = models.CharField(max_length=255)
|
||||
country = models.CharField(max_length=255)
|
||||
#calculated fields:
|
||||
# total_weight = models.IntegerField(null=True, blank=True, editable=False)
|
||||
# no_of_goods = models.IntegerField(null=True, blank=True, editable=False)
|
||||
# no_of_packages = models.IntegerField(null=True, blank=True, editable=False)
|
||||
|
||||
def __unicode__(self):
|
||||
return "%d: %s" % (self.number, self.ship_name,)
|
||||
def __unicode__(self):
|
||||
return "%d: %s" % (self.number, self.ship_name,)
|
||||
|
||||
@property
|
||||
def total_weight(self):
|
||||
return self.good_set.all().aggregate(Sum('weight'))['weight__sum']
|
||||
|
||||
|
||||
# def calculate_weight(self):
|
||||
# self.total_weight = self.good_set.all().aggregate(Sum('weight'))
|
||||
# return self
|
||||
|
||||
# class Meta:
|
||||
# ordering = ['number']
|
||||
|
||||
def no_of_goods(self):
|
||||
return Good.objects.filter(ship=self).count()
|
||||
def no_of_goods(self):
|
||||
return self.good_set.count()
|
||||
|
||||
#['description', 'package_type', 'no_of_packages', 'weight', 'value']
|
||||
class Good(models.Model):
|
||||
ship = models.ForeignKey(Ship)
|
||||
description = models.TextField()
|
||||
description_string = models.TextField(blank=True, null=True)
|
||||
description_string_trans = models.TextField(blank=True, null=True)
|
||||
package_type = models.CharField(max_length=256)
|
||||
no_of_packages = models.IntegerField(max_length=20, null=True)
|
||||
weight = models.IntegerField(max_length=20, null=True)
|
||||
value = models.IntegerField(max_length=20, null=True)
|
||||
ship = models.ForeignKey(Ship)
|
||||
description = models.TextField()
|
||||
description_string = models.TextField(blank=True, null=True)
|
||||
description_string_trans = models.TextField(blank=True, null=True)
|
||||
package_type = models.CharField(max_length=256)
|
||||
no_of_packages = models.IntegerField(max_length=20, null=True)
|
||||
weight = models.IntegerField(max_length=20, null=True)
|
||||
value = models.IntegerField(max_length=20, null=True)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.description
|
||||
def __unicode__(self):
|
||||
return self.description
|
||||
|
||||
|
||||
class Translation(models.Model):
|
||||
|
@ -65,4 +80,5 @@ class Translation(models.Model):
|
|||
|
||||
class Meta:
|
||||
ordering = ('id',)
|
||||
# Create your models here.
|
||||
|
||||
databrowse.site.register(Ship, Good, Manifest)
|
||||
|
|
|
@ -163,6 +163,44 @@ def stringtranslate(request):
|
|||
return render_to_json_response({'ok': savedObjects})
|
||||
|
||||
|
||||
|
||||
|
||||
@login_required
|
||||
def shipList(request):
|
||||
page = request.GET.get('page', 1)
|
||||
page_size = request.GET.get('page_size', 50)
|
||||
startDate = request.GET.get('start_date', None)
|
||||
endDate = request.GET.get('end_date', None)
|
||||
billType = request.GET.get('bill_type', None)
|
||||
shipName = request.GET.get('ship_name', None)
|
||||
captain = request.GET.get('captain', None)
|
||||
flag = request.GET.get('flag', None)
|
||||
owner = request.GET.get('owner', None)
|
||||
port = request.GET.get('port', None)
|
||||
# country = request.GET.get('country', None)
|
||||
qset = Ship.objects.all()
|
||||
#add dates stuff
|
||||
if billType:
|
||||
qset = qset.filter(billType__iexact=billType)
|
||||
if shipName:
|
||||
qset = qset.filter(ship_name_trans__icontains=shipName)
|
||||
if captain:
|
||||
qset = qset.filter(captain_trans__icontains=captain)
|
||||
if flag:
|
||||
qset = qset.filter(flag__iexact=flag)
|
||||
if owner:
|
||||
qset = qset.filter(owner_trans__icontains=owner)
|
||||
if port:
|
||||
qset = qset.filter(port__icontains=port)
|
||||
# if country:
|
||||
# qset = qset.filter(country__icontains=country)
|
||||
paginator = Paginator(qset, page_size)
|
||||
results = paginator.page(page)
|
||||
|
||||
return render_to_response("shipList.html", {'ships': results.object_list})
|
||||
|
||||
|
||||
|
||||
'''
|
||||
def dotrans(request, model, field):
|
||||
oldVal = request.POST.get('oldVal', '')
|
||||
|
|
28
manifests/templates/registration/login.html
Normal file
28
manifests/templates/registration/login.html
Normal file
|
@ -0,0 +1,28 @@
|
|||
<div id="loginWrapper">
|
||||
<form action="" method="POST">
|
||||
{{ form.as_ul }}<br />
|
||||
<input type="submit" value="Submit" />
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{% comment %}
|
||||
{% extends 'main_base.html' %}
|
||||
|
||||
{% block title %}
|
||||
Login
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_head %}
|
||||
<link rel="stylesheet" href="/static/css/files/login.css" />
|
||||
{% endblock %}
|
||||
|
||||
{% block pageTitle %}
|
||||
Login
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% endcomment %}
|
66
manifests/templates/shipList.html
Normal file
66
manifests/templates/shipList.html
Normal file
|
@ -0,0 +1,66 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<script type="text/javascript" src="/media/js/jquery.js"></script>
|
||||
<style type="text/css">
|
||||
.goodRow {
|
||||
display: none;
|
||||
}
|
||||
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
$('.shipRow').click(function() {
|
||||
var $goodRow = $(this).next();
|
||||
$goodRow.slideToggle();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="wrapper">
|
||||
<div id="leftCol">
|
||||
<form id="shipFilterForm" action="" method="GET">
|
||||
Form goes here
|
||||
</form>
|
||||
</div>
|
||||
<div id="rightCol">
|
||||
<table>
|
||||
{% for s in ships %}
|
||||
<tr class="shipRow">
|
||||
<td>{{ s.number }}</td>
|
||||
<td>{{ s.date|date:"d, M, Y" }}</td>
|
||||
<td>{{ s.ship_name_trans }}</td>
|
||||
<td>{{ s.captain_trans }}</td>
|
||||
<td>{{ s.owner_trans }}</td>
|
||||
<td>{{ s.port }}</td>
|
||||
<td>{{ s.country }}</td>
|
||||
</tr>
|
||||
<tr class="goodRow">
|
||||
<td></td>
|
||||
<td colspan="6">
|
||||
<table class="goodTable">
|
||||
{% for good in s.good_set.all %}
|
||||
<tr>
|
||||
<td>{{ good.description_string_trans }}</td>
|
||||
<td>{{ good.no_of_packages }}</td>
|
||||
<td>{{ good.weight }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
<tr>
|
||||
<td>Total wt.: {{ s.total_weight }}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -4,6 +4,7 @@ from os.path import join
|
|||
# Uncomment the next two lines to enable the admin:
|
||||
from django.contrib import admin
|
||||
admin.autodiscover()
|
||||
from django.contrib import databrowse
|
||||
|
||||
urlpatterns = patterns('',
|
||||
# Example:
|
||||
|
@ -14,6 +15,8 @@ urlpatterns = patterns('',
|
|||
|
||||
# Uncomment the next line to enable the admin:
|
||||
|
||||
|
||||
(r'^$', 'ships.views.shipList'),
|
||||
# for human translators
|
||||
(r'^trans/(?P<model>[A-Za-z].*?)/(?P<field>[A-Za-z].*?)/(?P<page_no>\d*)/', 'ships.views.translate'),
|
||||
(r'^dotrans/(?P<model>[A-Za-z].*?)/(?P<field>[A-Za-z].*?)/', 'ships.views.dotranslate'),
|
||||
|
@ -23,6 +26,12 @@ urlpatterns = patterns('',
|
|||
(r'^dotranslate/(?P<model>[A-Za-z].*?)/(?P<field>[A-Za-z].*?)/', 'ships.views.dotranslate'),
|
||||
(r'^stringtranslate/$', 'ships.views.stringtranslate'),
|
||||
(r'^admin/', include(admin.site.urls)),
|
||||
(r'^databrowse/(.*)', databrowse.site.root),
|
||||
#(r'^querybuilder/', include('querybuilder.urls')),
|
||||
#(r'^dashboard/', include('dashboard.urls')),
|
||||
(r'^accounts/login/$', 'django.contrib.auth.views.login'),
|
||||
(r'^accounts/logout/$', 'django.contrib.auth.views.logout_then_login'),
|
||||
(r'^accounts/profile/$', 'django.views.generic.simple.redirect_to', {'url': '/'}),
|
||||
)
|
||||
|
||||
if settings.LOCAL_DEVELOPMENT:
|
||||
|
|
Loading…
Reference in New Issue
Block a user