some work towards editing places

This commit is contained in:
rolux 2011-10-09 21:12:50 +00:00
parent ab8e876609
commit c6c1c9b15b
6 changed files with 58 additions and 15 deletions

View file

@ -2,6 +2,8 @@
# vi:si:et:sw=4:sts=4:ts=4 # vi:si:et:sw=4:sts=4:ts=4
from django.db.models import Q, Manager from django.db.models import Q, Manager
from ox.django.query import QuerySet
def parseCondition(condition, user): def parseCondition(condition, user):
k = condition.get('key', 'name') k = condition.get('key', 'name')
@ -60,7 +62,7 @@ def parseConditions(conditions, operator, user):
class EventManager(Manager): class EventManager(Manager):
def get_query_set(self): def get_query_set(self):
return super(EventManager, self).get_query_set() return QuerySet(self.model)
def find(self, data, user): def find(self, data, user):
qs = self.get_query_set() qs = self.get_query_set()

View file

@ -19,8 +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: #class Meta:
ordering = ('name_sort', ) # 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)
@ -56,6 +57,11 @@ class Event(models.Model):
def __unicode__(self): def __unicode__(self):
return self.name return self.name
def editable(self, user):
if self.user == user or user.is_staff:
return True
return False
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,6 +86,7 @@ class Event(models.Model):
if not self.name_sort: if not self.name_sort:
self.name_sort = self.name self.name_sort = self.name
self.name_find = '||' + self.name + '||'.join(self.alternativeNames) + '||' self.name_find = '||' + self.name + '||'.join(self.alternativeNames) + '||'
self.durationTime = self.endTime - self.startTime
super(Event, self).save(*args, **kwargs) super(Event, self).save(*args, **kwargs)
def get_id(self): def get_id(self):
@ -94,6 +101,8 @@ class Event(models.Model):
for key in ('created', 'modified', for key in ('created', 'modified',
'name', 'alternativeNames', 'name', 'alternativeNames',
'start', 'end', 'duration', 'start', 'end', 'duration',
'startTime', 'endTime', 'durationTime',
'type', 'matches'): 'type', 'matches'):
j[key] = getattr(self, key) j[key] = getattr(self, key)
j['nameSort'] = self.name_sort
return j return j

View file

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4 # vi:si:et:sw=4:sts=4:ts=4
from __future__ import division from __future__ import division
import unicodedata
import ox import ox
from ox.utils import json from ox.utils import json
@ -34,9 +35,14 @@ def addEvent(request):
if not exists: if not exists:
event = models.Event(name = data['name']) event = models.Event(name = data['name'])
for key in ('start', 'startTime', 'end', 'endTime', 'duration', 'durationTime', for key in ('start', 'startTime', 'end', 'endTime', 'duration', 'durationTime',
'alternativeNames'): 'type', 'alternativeNames'):
if key in data and data[key]: if key in data and data[key]:
setattr(event, key, data[key]) value = data[key]
if key == 'alternativeNames':
value = tuple(value)
setattr(event, key, value)
if 'nameSort' in data:
event.name_sort = unicodedata.normalize('NFKD', data['nameSort'])
event.save() event.save()
tasks.update_matches.delay(event.id) tasks.update_matches.delay(event.id)
response = json_response(status=200, text='created') response = json_response(status=200, text='created')
@ -70,13 +76,19 @@ def editEvent(request):
conflict = True conflict = True
conflict_names.append(name) conflict_names.append(name)
if not conflict: if not conflict:
for key in ('start', 'startTime', 'end', 'endTime', 'duration', 'durationTime', for key in ('name', 'start', 'startTime', 'end', 'endTime', 'duration', 'durationTime',
'alternativeNames'): 'type', 'alternativeNames'):
if key in data: if key in data:
setattr(event, key, data[key]) value = data[key]
if key == 'alternativeNames':
value = tuple(value)
setattr(event, key, value)
if 'nameSort' in data:
event.name_sort = unicodedata.normalize('NFKD', data['nameSort'])
event.save() event.save()
tasks.update_matches.delay(event.id) tasks.update_matches.delay(event.id)
response = json_response(status=200, text='updated') response = json_response(status=200, text='updated')
response['data'] = event.json()
else: else:
response = json_response(status=403, text='Event name conflict') response = json_response(status=403, text='Event name conflict')
response['data']['names'] = conflict_names response['data']['names'] = conflict_names
@ -96,7 +108,7 @@ def removeEvent(request):
''' '''
data = json.loads(request.POST['data']) data = json.loads(request.POST['data'])
event = get_object_or_404_json(models.Event, pk=data['id']) event = get_object_or_404_json(models.Event, pk=ox.from26(data['id']))
if event.editable(request.user): if event.editable(request.user):
event.delete() event.delete()
response = json_response(status=200, text='removed') response = json_response(status=200, text='removed')
@ -174,7 +186,8 @@ Positions
data = json.loads(request.POST['data']) data = json.loads(request.POST['data'])
query = parse_query(data, request.user) query = parse_query(data, request.user)
qs = query['qs'].distinct() qs = order_query(query['qs'], query['sort'])
qs = qs.distinct()
if 'keys' in data: if 'keys' in data:
qs = qs[query['range'][0]:query['range'][1]] qs = qs[query['range'][0]:query['range'][1]]
qs = qs.select_related() qs = qs.select_related()

View file

@ -36,8 +36,26 @@ pandora.ui.eventsDialog = function() {
}, function(result) { }, function(result) {
that.options({ that.options({
content: Ox.ListCalendar({ content: Ox.ListCalendar({
height: height - 48, addEvent: function(event, callback) {
pandora.api.addEvent(event, function(result) {
Ox.Request.clearCache(); // fixme: remove
callback(result);
});
},
editEvent: function(event, callback) {
pandora.api.editEvent(event, function(result) {
Ox.Request.clearCache(); // fixme: remove
callback(result);
});
},
events: result.data.items, events: result.data.items,
height: height - 48,
removeEvent: function(event, callback) {
pandora.api.removeEvent(event, function(result) {
Ox.Request.clearCache(); // fixme: remove
callback(result);
});
},
width: width width: width
}) })
}); });

View file

@ -202,6 +202,7 @@ pandora.ui.navigationView = function(type, videoRatio) {
}) })
.bindEvent({ .bindEvent({
resize: function(data) { resize: function(data) {
// triggered by SplitPanel
$element.resizeCalendar(); $element.resizeCalendar();
}, },
select: selectItem select: selectItem

View file

@ -23,18 +23,18 @@ pandora.ui.placesDialog = function() {
}, data), callback); }, data), callback);
}, },
addPlace: function(place, callback) { addPlace: function(place, callback) {
Ox.print('ADDPLACE', place);
pandora.api.addPlace(place, function(result) { pandora.api.addPlace(place, function(result) {
Ox.Request.clearCache(); // fixme: remove Ox.Request.clearCache(); // fixme: remove
callback(result); callback(result);
}); });
}, },
editPlace: function(place, callback) { editPlace: function(place, callback) {
Ox.print('EDITPLACE', place); pandora.api.editPlace(place, function(result) {
pandora.api.editPlace(place, callback); Ox.Request.clearCache(); // fixme: remove
callback(result);
});
}, },
removePlace: function(place, callback) { removePlace: function(place, callback) {
Ox.print('REMOVEPLACE', place);
pandora.api.removePlace(place, function(result) { pandora.api.removePlace(place, function(result) {
Ox.Request.clearCache(); // fixme: remove Ox.Request.clearCache(); // fixme: remove
callback(result); callback(result);