From 40ee2a08601e54b07d6f0abbb3c8e5c03e7538e3 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sat, 18 Feb 2012 09:59:56 +0000 Subject: [PATCH] place/event annotations always need a place/event object. set formated date on annotations --- pandora/annotation/models.py | 4 ++++ pandora/annotation/tasks.py | 14 ++++++++------ static/js/pandora/item.js | 2 ++ static/js/pandora/utils.js | 1 + 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/pandora/annotation/models.py b/pandora/annotation/models.py index 603be1d8..b2962597 100644 --- a/pandora/annotation/models.py +++ b/pandora/annotation/models.py @@ -197,10 +197,14 @@ class Annotation(models.Model): qs = self.places.all() if qs.count() > 0: j['place'] = qs[0].json(user=user) + else: + j['place'] = {} elif l['type'] == 'event': qs = self.events.all() if qs.count() > 0: j['event'] = qs[0].json(user=user) + else: + j['event'] = {} if layer or (keys and 'layer' in keys): j['layer'] = self.layer diff --git a/pandora/annotation/tasks.py b/pandora/annotation/tasks.py index 319c7fb0..b7246ba8 100644 --- a/pandora/annotation/tasks.py +++ b/pandora/annotation/tasks.py @@ -13,11 +13,12 @@ def update_matching_events(id): for e in a.events.filter(defined=False).exclude(name=a.value): if e.annotations.exclude(id=id).count() == 0: e.delete() - if a.get_layer().get('type') == 'event' \ - and a.events.count() == 0: - a.events.add(Event.get_or_create(a.value)) for e in a.events.all(): e.update_matches() + if a.get_layer().get('type') == 'event' and a.events.count() == 0: + a.events.add(Event.get_or_create(a.value)) + for e in a.events.all(): + e.update_matches() ids = [e['id'] for e in Event.objects.all().values('id')] for i in ids: e = Event.objects.get(pk=i) @@ -33,11 +34,12 @@ def update_matching_places(id): for p in a.places.filter(defined=False).exclude(name=a.value): if p.annotations.exclude(id=id).count() == 0: p.delete() - if a.get_layer().get('type') == 'place' \ - and a.places.count() == 0: - a.places.add(Place.get_or_create(a.value)) for p in a.places.all(): p.update_matches() + if a.get_layer().get('type') == 'place' and a.places.count() == 0: + a.places.add(Place.get_or_create(a.value)) + for p in a.places.all(): + p.update_matches() ids = [e['id'] for e in Place.objects.all().values('id')] for i in ids: e = Place.objects.get(pk=i) diff --git a/static/js/pandora/item.js b/static/js/pandora/item.js index 414c2f41..f18cf6e6 100644 --- a/static/js/pandora/item.js +++ b/static/js/pandora/item.js @@ -350,6 +350,8 @@ pandora.ui.item = function() { Ox.Log('', 'editAnnotation', data); function callback(result) { Ox.Log('', 'editAnnotation result', result); + result.data.date = Ox.formatDate(result.data.modified.substr(0, 10), + '%B %e, %Y'); pandora.$ui.editor.updateAnnotation(data.id, result.data); }; if (data.id[0] == '_') { diff --git a/static/js/pandora/utils.js b/static/js/pandora/utils.js index 2114c670..e974f553 100644 --- a/static/js/pandora/utils.js +++ b/static/js/pandora/utils.js @@ -831,6 +831,7 @@ pandora.getVideoOptions = function(data) { pandora.site.layers.forEach(function(layer, i) { options.layers[i] = Ox.extend({}, layer, { items: data.layers[layer.id].map(function(annotation) { + annotation.date = Ox.formatDate(annotation.modified.substr(0, 10), '%B %e, %Y'); annotation.duration = Math.abs(annotation.out - annotation['in']); annotation.editable = annotation.editable || annotation.user == pandora.user.username