basic ship list page

This commit is contained in:
Sanj 2012-04-22 15:06:39 +05:30
parent 2513469028
commit 8078cee13f
7 changed files with 198 additions and 35 deletions

View File

@ -64,7 +64,7 @@ STATIC_URL = '/static/'
# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a # URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash. # trailing slash.
# Examples: "http://foo.com/media/", "/media/". # 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. # Make this unique, creates random key first at first time.
try: try:
@ -115,12 +115,17 @@ INSTALLED_APPS = (
'django.contrib.sites', 'django.contrib.sites',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'django.contrib.databrowse',
'ships', 'ships',
# Uncomment the next line to enable the admin: # Uncomment the next line to enable the admin:
'django.contrib.admin', 'django.contrib.admin',
# Uncomment the next line to enable admin documentation: # Uncomment the next line to enable admin documentation:
'django.contrib.admindocs', 'django.contrib.admindocs',
'django_extensions' 'django_extensions',
'django.contrib.databrowse'
# 'querybuilder',
# 'dashboard'
) )
try: try:

View File

@ -203,6 +203,7 @@ def importJSON(filename):
def generateGoodStrings(): def generateGoodStrings():
for g in Good.objects.all(): for g in Good.objects.all():
if g.description_string: continue
s = getGoodString(g.description) s = getGoodString(g.description)
print s print s
g.description_string = s g.description_string = s

View File

@ -1,4 +1,6 @@
from django.db import models from django.db import models
from django.contrib import databrowse
from django.db.models import Sum, Avg
class Manifest(models.Model): class Manifest(models.Model):
month = models.CharField(max_length=3) month = models.CharField(max_length=3)
@ -29,15 +31,28 @@ class Ship(models.Model):
owner_trans = models.CharField(max_length=255, blank=True, null=True) owner_trans = models.CharField(max_length=255, blank=True, null=True)
port = models.CharField(max_length=255) port = models.CharField(max_length=255)
country = 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): def __unicode__(self):
return "%d: %s" % (self.number, self.ship_name,) 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: # class Meta:
# ordering = ['number'] # ordering = ['number']
def no_of_goods(self): def no_of_goods(self):
return Good.objects.filter(ship=self).count() return self.good_set.count()
#['description', 'package_type', 'no_of_packages', 'weight', 'value'] #['description', 'package_type', 'no_of_packages', 'weight', 'value']
class Good(models.Model): class Good(models.Model):
@ -65,4 +80,5 @@ class Translation(models.Model):
class Meta: class Meta:
ordering = ('id',) ordering = ('id',)
# Create your models here.
databrowse.site.register(Ship, Good, Manifest)

View File

@ -163,6 +163,44 @@ def stringtranslate(request):
return render_to_json_response({'ok': savedObjects}) 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): def dotrans(request, model, field):
oldVal = request.POST.get('oldVal', '') oldVal = request.POST.get('oldVal', '')

View 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 %}

View 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>

View File

@ -4,6 +4,7 @@ from os.path import join
# Uncomment the next two lines to enable the admin: # Uncomment the next two lines to enable the admin:
from django.contrib import admin from django.contrib import admin
admin.autodiscover() admin.autodiscover()
from django.contrib import databrowse
urlpatterns = patterns('', urlpatterns = patterns('',
# Example: # Example:
@ -14,6 +15,8 @@ urlpatterns = patterns('',
# Uncomment the next line to enable the admin: # Uncomment the next line to enable the admin:
(r'^$', 'ships.views.shipList'),
# for human translators # for human translators
(r'^trans/(?P<model>[A-Za-z].*?)/(?P<field>[A-Za-z].*?)/(?P<page_no>\d*)/', 'ships.views.translate'), (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'), (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'^dotranslate/(?P<model>[A-Za-z].*?)/(?P<field>[A-Za-z].*?)/', 'ships.views.dotranslate'),
(r'^stringtranslate/$', 'ships.views.stringtranslate'), (r'^stringtranslate/$', 'ships.views.stringtranslate'),
(r'^admin/', include(admin.site.urls)), (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: if settings.LOCAL_DEVELOPMENT: