From 8078cee13f0aaec595ce4a11297cebb8bd366178 Mon Sep 17 00:00:00 2001 From: Sanj Date: Sun, 22 Apr 2012 15:06:39 +0530 Subject: [PATCH] basic ship list page --- manifests/settings.py | 9 ++- manifests/ships/convert.py | 1 + manifests/ships/models.py | 82 ++++++++++++--------- manifests/ships/views.py | 38 ++++++++++ manifests/templates/registration/login.html | 28 +++++++ manifests/templates/shipList.html | 66 +++++++++++++++++ manifests/urls.py | 9 +++ 7 files changed, 198 insertions(+), 35 deletions(-) create mode 100644 manifests/templates/registration/login.html create mode 100644 manifests/templates/shipList.html diff --git a/manifests/settings.py b/manifests/settings.py index 287eb5f..2fab57d 100644 --- a/manifests/settings.py +++ b/manifests/settings.py @@ -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: diff --git a/manifests/ships/convert.py b/manifests/ships/convert.py index daaf4cc..4aa6c01 100755 --- a/manifests/ships/convert.py +++ b/manifests/ships/convert.py @@ -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 diff --git a/manifests/ships/models.py b/manifests/ships/models.py index 690e1c2..e4e8a5d 100644 --- a/manifests/ships/models.py +++ b/manifests/ships/models.py @@ -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) diff --git a/manifests/ships/views.py b/manifests/ships/views.py index 63bb9e6..1d4341f 100644 --- a/manifests/ships/views.py +++ b/manifests/ships/views.py @@ -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', '') diff --git a/manifests/templates/registration/login.html b/manifests/templates/registration/login.html new file mode 100644 index 0000000..7d19ab9 --- /dev/null +++ b/manifests/templates/registration/login.html @@ -0,0 +1,28 @@ +
+
+{{ form.as_ul }}
+ +
+
+ +{% comment %} +{% extends 'main_base.html' %} + +{% block title %} + Login +{% endblock %} + +{% block extra_head %} + +{% endblock %} + +{% block pageTitle %} + Login +{% endblock %} + +{% block content %} + + +{% endblock %} + +{% endcomment %} diff --git a/manifests/templates/shipList.html b/manifests/templates/shipList.html new file mode 100644 index 0000000..5a64364 --- /dev/null +++ b/manifests/templates/shipList.html @@ -0,0 +1,66 @@ + + + + + + + + +
+
+
+ Form goes here +
+
+
+ + {% for s in ships %} + + + + + + + + + + + + + + {% endfor %} +
{{ s.number }}{{ s.date|date:"d, M, Y" }}{{ s.ship_name_trans }}{{ s.captain_trans }}{{ s.owner_trans }}{{ s.port }}{{ s.country }}
+ + {% for good in s.good_set.all %} + + + + + + {% endfor %} + + + +
{{ good.description_string_trans }}{{ good.no_of_packages }}{{ good.weight }}
Total wt.: {{ s.total_weight }}
+
+
+ +
+ + + + diff --git a/manifests/urls.py b/manifests/urls.py index 7fc5954..bd5af3f 100644 --- a/manifests/urls.py +++ b/manifests/urls.py @@ -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[A-Za-z].*?)/(?P[A-Za-z].*?)/(?P\d*)/', 'ships.views.translate'), (r'^dotrans/(?P[A-Za-z].*?)/(?P[A-Za-z].*?)/', 'ships.views.dotranslate'), @@ -23,6 +26,12 @@ urlpatterns = patterns('', (r'^dotranslate/(?P[A-Za-z].*?)/(?P[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: