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