From ee4bfa0366980c12cd4d22261fbd7898e89f77f4 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sat, 24 Sep 2011 16:13:23 +0200 Subject: [PATCH] load events from backend --- pandora/event/managers.py | 3 ++- pandora/event/models.py | 14 +++++++++----- static/js/pandora/ui/list.js | 37 ++++++++++++++++-------------------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/pandora/event/managers.py b/pandora/event/managers.py index 1d28a300f..fcd9cf000 100644 --- a/pandora/event/managers.py +++ b/pandora/event/managers.py @@ -11,5 +11,6 @@ class EventManager(Manager): def find(self, q=''): qs = self.get_query_set() - qs = qs.filter(Q(name_find__icontains=q)) + if q: + qs = qs.filter(Q(name_find__icontains=q)) return qs diff --git a/pandora/event/models.py b/pandora/event/models.py index 32f0fe8fa..954a31aff 100644 --- a/pandora/event/models.py +++ b/pandora/event/models.py @@ -19,6 +19,9 @@ class Event(models.Model): Events are events in time that can be once or recurring, From Mondays to Spring to 1989 to Roman Empire ''' + class Meta: + ordering = ('name_sort', ) + created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) @@ -33,9 +36,6 @@ class Event(models.Model): objects = managers.EventManager() - class Meta: - ordering = ('name_sort', ) - #start yyyy-mm-dd|mm-dd|dow 00:00|00:00 start = models.CharField(default='', max_length=255) startTime = models.BigIntegerField(default=0) @@ -51,7 +51,10 @@ class Event(models.Model): matches = models.IntegerField(default=0) items = models.ManyToManyField(Item, blank=True, related_name='events') - + + def __unicode__(self): + return self.name + def get_matches(self): q = Q(value__icontains=" " + self.name)|Q(value__startswith=self.name) for name in self.alternativeNames: @@ -80,8 +83,9 @@ class Event(models.Model): def json(self, user=None): j = { 'id': self.get_id(), - 'user': self.user.username, } + if self.user: + j['user'] = self.user.username for key in ('created', 'modified', 'name', 'alternativeNames', 'start', 'end', 'duration', diff --git a/static/js/pandora/ui/list.js b/static/js/pandora/ui/list.js index 500935e16..508967904 100644 --- a/static/js/pandora/ui/list.js +++ b/static/js/pandora/ui/list.js @@ -485,27 +485,7 @@ pandora.ui.list = function() { // fixme: remove view argument that = Ox.SplitPanel({ elements: [ { - element: pandora.$ui.calendar = Ox.Calendar({ - date: new Date(0), - events: [ - {name: 'Thirty Years\' War', start: '1618', end: '1648', type: 'other'}, - {name: 'American Civil War', start: '1861-04-12', end: '1865-04-09', type: 'other'}, - {name: 'Franco-Prussian War', start: '1870-07-19', end: '1871-05-10', type: 'other'}, - {name: 'World War One', start: '1914-07-28', end: '1918-11-11', type: 'other'}, - {name: 'World War Two', start: '1939-09-01', end: '1945-09-02', type: 'other'}, - {name: 'Cold War', start: '1947', end: '1991', type: 'other'}, - {name: 'Korean War', start: '1950-06-25', end: '1953-07-27', type: 'other'}, - {name: 'Algerian War', start: '1954-11-01', end: '1962-03-19', type: 'other'}, - {name: 'Vietnam War', start: '1955-11-01', end: '1975-04-30', type: 'other'}, - {name: 'Six-Day War', start: '1967-06-05', end: '1967-06-11', type: 'other'}, - {name: 'Iran-Iraq War', start: '1980-09-22', end: '1988-08-20', type: 'other'}, - {name: 'Gulf War', start: '1990-08-02', end: '1991-02-28', type: 'other'} - ], - height: window.innerHeight - pandora.user.ui.showGroups * pandora.user.ui.groupsSize - 61, - range: [-5000, 5000], - width: window.innerWidth - pandora.user.ui.showSidebar * pandora.user.ui.sidebarSize - 2 - 144 - Ox.UI.SCROLLBAR_SIZE, - zoom: 4 - }) + element: pandora.$ui.calendar = Ox.Element() }, { element: Ox.Element(), @@ -518,6 +498,21 @@ pandora.ui.list = function() { // fixme: remove view argument .bindEvent('resize', function(data) { }); + pandora.api.findEvents({ + query: '', + itemQuery: pandora.user.ui.query + }, function(result) { + Ox.print(">>>>>>>", result); + that.replaceElement(0, + pandora.$ui.calendar = Ox.Calendar({ + date: new Date(0), + events: result.data.events, + height: window.innerHeight - pandora.user.ui.showGroups * pandora.user.ui.groupsSize - 61, + range: [-5000, 5000], + width: window.innerWidth - pandora.user.ui.showSidebar * pandora.user.ui.sidebarSize - 2 - 144 - Ox.UI.SCROLLBAR_SIZE, + zoom: 4 + })); + }); } else { // fixme: ??? $list = Ox.Element('
')