add is_empty option
This commit is contained in:
parent
fb51dca89c
commit
17cdf2942c
|
@ -2,7 +2,7 @@
|
|||
import os
|
||||
from os.path import join
|
||||
|
||||
DEBUG = True
|
||||
DEBUG = False
|
||||
TEMPLATE_DEBUG = DEBUG
|
||||
JSON_DEBUG = DEBUG
|
||||
LOCAL_DEVELOPMENT = True
|
||||
|
|
|
@ -120,6 +120,13 @@ def addType(inFile, outFile):
|
|||
outFile.write(outJSON)
|
||||
outFile.close()
|
||||
|
||||
def cleanDates(filename):
|
||||
data = json.load(open(filename))
|
||||
for d in data:
|
||||
d['filename'] = d['filename'].replace("csv/02042012/Outgoing/", "")
|
||||
#date = d['filename'].replace("creekmanifest", "")
|
||||
|
||||
|
||||
#prefix is a silly quick-fix for date like creekmanifest1201
|
||||
def importJSON(filename, prefix=""):
|
||||
data = json.loads(open(filename).read())
|
||||
|
@ -131,34 +138,46 @@ def importJSON(filename, prefix=""):
|
|||
m.filename = manifest['filename']
|
||||
if prefix != '':
|
||||
manifest['date'] = manifest['date'].replace(prefix, "")
|
||||
month = manifest['date'][0:3]
|
||||
yr = manifest['date'][3:5]
|
||||
m.month = month
|
||||
dateStr = manifest['date'].replace(".csv", "")
|
||||
yr = dateStr[-2:]
|
||||
month = dateStr.replace(yr, "")
|
||||
print yr
|
||||
print month
|
||||
# month = manifest['date'][0:3]
|
||||
# yr = manifest['date'][3:5]
|
||||
m.month = month[0:3].lower()
|
||||
#print yr
|
||||
m.year = int("20" + yr)
|
||||
matchedManifests = Manifest.objects.filter(month=month).filter(year=m.year)
|
||||
if matchedManifests.count() > 0:
|
||||
print "Manifest file exists with id %d" % matchedManifests[0].id
|
||||
for match in matchedManifests:
|
||||
match.delete()
|
||||
# datestring = "20%s-%s" % (yr, month,)
|
||||
# m.date = datestring
|
||||
try:
|
||||
m.save()
|
||||
except:
|
||||
manifests_errors.append(manifest['filename'])
|
||||
exit()
|
||||
for ship in manifest['ships']:
|
||||
s = Ship()
|
||||
row = ship['row']
|
||||
s.manifest_file = m
|
||||
s.bill_type = row[0]
|
||||
s.number = row[1]
|
||||
shipDate = row[2]
|
||||
s.bill_type = 'Export'
|
||||
s.number = row[0]
|
||||
shipDate = row[1]
|
||||
s.date = "%s-%s-%s" % (shipDate[6:], shipDate[3:5], shipDate[0:2])
|
||||
s.ship_name = row[3]
|
||||
s.captain = row[4]
|
||||
s.flag = row[5]
|
||||
s.owner = row[6]
|
||||
s.ship_name = row[2]
|
||||
s.captain = row[3]
|
||||
s.flag = row[4]
|
||||
s.owner = row[5]
|
||||
try:
|
||||
s.port = row[7]
|
||||
s.port = row[6]
|
||||
except:
|
||||
s.port = ''
|
||||
try:
|
||||
s.country = row[8]
|
||||
s.country = row[7]
|
||||
except:
|
||||
s.country = ''
|
||||
try:
|
||||
|
|
|
@ -110,4 +110,8 @@ class Translation(models.Model):
|
|||
class Meta:
|
||||
ordering = ('id',)
|
||||
|
||||
'''
|
||||
class NewTranslation(Translation):
|
||||
pass
|
||||
'''
|
||||
databrowse.site.register(Ship, Good, Manifest)
|
||||
|
|
|
@ -4,7 +4,7 @@ from django.http import HttpResponse
|
|||
from ships import models
|
||||
import json
|
||||
from django.shortcuts import render_to_response
|
||||
from django.db.models import Q
|
||||
from django.db.models import Q, Count
|
||||
from django.template import RequestContext
|
||||
from ox.django.shortcuts import render_to_json_response
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
@ -180,6 +180,7 @@ def shipList(request):
|
|||
port = request.GET.get('port', '')
|
||||
goods = request.GET.get('goods', '')
|
||||
sort = request.GET.get('sort', 'date')
|
||||
is_empty = request.GET.get('is_empty', False)
|
||||
# country = request.GET.get('country', None)
|
||||
qset = Ship.objects.all()
|
||||
if page == '':
|
||||
|
@ -207,6 +208,9 @@ def shipList(request):
|
|||
qset = qset.filter(port__icontains=port)
|
||||
if goods != '':
|
||||
qset = qset.filter(good__description_string_trans__icontains=goods).distinct()
|
||||
if is_empty != False:
|
||||
qset = qset.annotate(num_goods=Count('good')).filter(num_goods=0)
|
||||
|
||||
# if country:
|
||||
# qset = qset.filter(country__icontains=country)
|
||||
qset = qset.order_by(sort)
|
||||
|
|
|
@ -90,6 +90,11 @@ No of results: {{ no_of_results }} Displaying page {{ page }} of {{ no_of
|
|||
|
||||
<label for="id_goods">Goods:</label>
|
||||
<input type="text" name="goods" id="id_goods" value="{{ params.goods }}" />
|
||||
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<label for="id_is_empty">Is Empty:</label>
|
||||
<input type="checkbox" name="is_empty" id="id_is_empty" />
|
||||
</fieldset>
|
||||
<input type="submit" value="Submit" />
|
||||
</form>
|
||||
|
|
Loading…
Reference in New Issue
Block a user