do not dump undefined locations, make sure out point is > inpoint

This commit is contained in:
j 2012-01-21 01:08:21 +05:30
parent 2b8e2e8219
commit 764a22aafb
2 changed files with 30 additions and 23 deletions

View file

@ -160,6 +160,8 @@ def import_layers(item, layers):
annotation = Annotation(item=item, layer=layer_name)
annotation.start = float(layer['time_in'])/1000
annotation.end = float(layer['time_out'])/1000
if annotation.end < annotation.start:
annotation.end = annotation.start + 3
username = layer['creator'].strip()
annotation.user = User.objects.get(username=username)
annotation.value = html_parser(layer['value'])
@ -183,6 +185,9 @@ for oldId in sorted(padma, key=lambda x: padma[x]['created']):
item.user = User.objects.get(username=username)
for key in _data:
item.data[key] = _data[key]
if 'collection' in data and data['collection']:
group, created = Group.objects.get_or_create(name=data['collection'])
item.groups.add(group)
if 'poster_frame' in item.data:
item.poster_frame = float(item.data.pop('poster_frame')) / 1000
if 'published' in item.data:
@ -260,6 +265,7 @@ for l in locations:
l['user'] = User.objects.get(username=l['user'].strip())
else:
l['user'] = User.objects.all().order_by('id')[0]
l['name'] = ox.decodeHtml(l['name'])
l['created'] = datetime.fromtimestamp(int(l['created']))
l['modified'] = datetime.fromtimestamp(int(l['modified']))
l['alternativeNames'] = tuple(l['alternativeNames'])

View file

@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vi:si:et:sw=2:sts=2:ts=2
# vi:si:et:sw=4:sts=4:ts=4
# GPL written 2008 by j@pad.ma
import pkg_resources
@ -93,28 +93,29 @@ with open(os.path.join(prefix, 'lists.json'), 'w') as f:
locations = []
for l in Location.select().orderBy('id'):
data = {}
data['id'] = l.hid
data['name'] = l.name
data['south'] = l.lat_sw
data['west'] = l.lng_sw
data['north'] = l.lat_ne
data['east'] = l.lng_ne
data['lat'] = l.lat_center
data['lng'] = l.lng_center
data['area'] = l.area
data['created'] = int(l.created.strftime('%s'))
data['modified'] = int(l.modified.strftime('%s'))
data['alternativeNames'] = [l.name for l in l.alt_names]
try:
if l.creator:
data['user'] = l.creator.user_name
except SQLObjectNotFound:
pass
data['annotations'] = []
for a in l.layers:
data['annotations'].append(a.hid)
locations.append(data)
if l.lat_center != 0 and l.lng_center != 0 and l.area != 0:
data = {}
data['id'] = l.hid
data['name'] = l.name
data['south'] = l.lat_sw
data['west'] = l.lng_sw
data['north'] = l.lat_ne
data['east'] = l.lng_ne
data['lat'] = l.lat_center
data['lng'] = l.lng_center
data['area'] = l.area
data['created'] = int(l.created.strftime('%s'))
data['modified'] = int(l.modified.strftime('%s'))
data['alternativeNames'] = [l.name for l in l.alt_names]
try:
if l.creator:
data['user'] = l.creator.user_name
except SQLObjectNotFound:
pass
data['annotations'] = []
for a in l.layers:
data['annotations'].append(a.hid)
locations.append(data)
with open(os.path.join(prefix, 'locations.json'), 'w') as f:
json.dump(locations, f, indent=2)