load events from backend

This commit is contained in:
j 2011-09-24 16:13:23 +02:00
parent 6029217e4a
commit ee4bfa0366
3 changed files with 27 additions and 27 deletions

View file

@ -11,5 +11,6 @@ class EventManager(Manager):
def find(self, q=''): def find(self, q=''):
qs = self.get_query_set() qs = self.get_query_set()
if q:
qs = qs.filter(Q(name_find__icontains=q)) qs = qs.filter(Q(name_find__icontains=q))
return qs return qs

View file

@ -19,6 +19,9 @@ class Event(models.Model):
Events are events in time that can be once or recurring, Events are events in time that can be once or recurring,
From Mondays to Spring to 1989 to Roman Empire From Mondays to Spring to 1989 to Roman Empire
''' '''
class Meta:
ordering = ('name_sort', )
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True) modified = models.DateTimeField(auto_now=True)
@ -33,9 +36,6 @@ class Event(models.Model):
objects = managers.EventManager() objects = managers.EventManager()
class Meta:
ordering = ('name_sort', )
#start yyyy-mm-dd|mm-dd|dow 00:00|00:00 #start yyyy-mm-dd|mm-dd|dow 00:00|00:00
start = models.CharField(default='', max_length=255) start = models.CharField(default='', max_length=255)
startTime = models.BigIntegerField(default=0) startTime = models.BigIntegerField(default=0)
@ -52,6 +52,9 @@ class Event(models.Model):
matches = models.IntegerField(default=0) matches = models.IntegerField(default=0)
items = models.ManyToManyField(Item, blank=True, related_name='events') items = models.ManyToManyField(Item, blank=True, related_name='events')
def __unicode__(self):
return self.name
def get_matches(self): def get_matches(self):
q = Q(value__icontains=" " + self.name)|Q(value__startswith=self.name) q = Q(value__icontains=" " + self.name)|Q(value__startswith=self.name)
for name in self.alternativeNames: for name in self.alternativeNames:
@ -80,8 +83,9 @@ class Event(models.Model):
def json(self, user=None): def json(self, user=None):
j = { j = {
'id': self.get_id(), 'id': self.get_id(),
'user': self.user.username,
} }
if self.user:
j['user'] = self.user.username
for key in ('created', 'modified', for key in ('created', 'modified',
'name', 'alternativeNames', 'name', 'alternativeNames',
'start', 'end', 'duration', 'start', 'end', 'duration',

View file

@ -485,27 +485,7 @@ pandora.ui.list = function() { // fixme: remove view argument
that = Ox.SplitPanel({ that = Ox.SplitPanel({
elements: [ elements: [
{ {
element: pandora.$ui.calendar = Ox.Calendar({ element: pandora.$ui.calendar = Ox.Element()
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: Ox.Element(), element: Ox.Element(),
@ -518,6 +498,21 @@ pandora.ui.list = function() { // fixme: remove view argument
.bindEvent('resize', function(data) { .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 { } else {
// fixme: ??? // fixme: ???
$list = Ox.Element('<div>') $list = Ox.Element('<div>')