forked from 0x2620/pandora
some work towards editing places
This commit is contained in:
parent
ab8e876609
commit
c6c1c9b15b
6 changed files with 58 additions and 15 deletions
|
@ -2,6 +2,8 @@
|
|||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
|
||||
from django.db.models import Q, Manager
|
||||
from ox.django.query import QuerySet
|
||||
|
||||
|
||||
def parseCondition(condition, user):
|
||||
k = condition.get('key', 'name')
|
||||
|
@ -60,7 +62,7 @@ def parseConditions(conditions, operator, user):
|
|||
class EventManager(Manager):
|
||||
|
||||
def get_query_set(self):
|
||||
return super(EventManager, self).get_query_set()
|
||||
return QuerySet(self.model)
|
||||
|
||||
def find(self, data, user):
|
||||
qs = self.get_query_set()
|
||||
|
|
|
@ -19,8 +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', )
|
||||
#class Meta:
|
||||
# ordering = ('name_sort', )
|
||||
|
||||
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
modified = models.DateTimeField(auto_now=True)
|
||||
|
@ -56,6 +57,11 @@ class Event(models.Model):
|
|||
def __unicode__(self):
|
||||
return self.name
|
||||
|
||||
def editable(self, user):
|
||||
if self.user == user or user.is_staff:
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_matches(self):
|
||||
q = Q(value__icontains=" " + self.name)|Q(value__startswith=self.name)
|
||||
for name in self.alternativeNames:
|
||||
|
@ -80,6 +86,7 @@ class Event(models.Model):
|
|||
if not self.name_sort:
|
||||
self.name_sort = self.name
|
||||
self.name_find = '||' + self.name + '||'.join(self.alternativeNames) + '||'
|
||||
self.durationTime = self.endTime - self.startTime
|
||||
super(Event, self).save(*args, **kwargs)
|
||||
|
||||
def get_id(self):
|
||||
|
@ -94,6 +101,8 @@ class Event(models.Model):
|
|||
for key in ('created', 'modified',
|
||||
'name', 'alternativeNames',
|
||||
'start', 'end', 'duration',
|
||||
'startTime', 'endTime', 'durationTime',
|
||||
'type', 'matches'):
|
||||
j[key] = getattr(self, key)
|
||||
j['nameSort'] = self.name_sort
|
||||
return j
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
from __future__ import division
|
||||
import unicodedata
|
||||
|
||||
import ox
|
||||
from ox.utils import json
|
||||
|
@ -34,9 +35,14 @@ def addEvent(request):
|
|||
if not exists:
|
||||
event = models.Event(name = data['name'])
|
||||
for key in ('start', 'startTime', 'end', 'endTime', 'duration', 'durationTime',
|
||||
'alternativeNames'):
|
||||
'type', 'alternativeNames'):
|
||||
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()
|
||||
tasks.update_matches.delay(event.id)
|
||||
response = json_response(status=200, text='created')
|
||||
|
@ -70,13 +76,19 @@ def editEvent(request):
|
|||
conflict = True
|
||||
conflict_names.append(name)
|
||||
if not conflict:
|
||||
for key in ('start', 'startTime', 'end', 'endTime', 'duration', 'durationTime',
|
||||
'alternativeNames'):
|
||||
for key in ('name', 'start', 'startTime', 'end', 'endTime', 'duration', 'durationTime',
|
||||
'type', 'alternativeNames'):
|
||||
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()
|
||||
tasks.update_matches.delay(event.id)
|
||||
response = json_response(status=200, text='updated')
|
||||
response['data'] = event.json()
|
||||
else:
|
||||
response = json_response(status=403, text='Event name conflict')
|
||||
response['data']['names'] = conflict_names
|
||||
|
@ -96,7 +108,7 @@ def removeEvent(request):
|
|||
|
||||
'''
|
||||
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):
|
||||
event.delete()
|
||||
response = json_response(status=200, text='removed')
|
||||
|
@ -174,7 +186,8 @@ Positions
|
|||
|
||||
data = json.loads(request.POST['data'])
|
||||
query = parse_query(data, request.user)
|
||||
qs = query['qs'].distinct()
|
||||
qs = order_query(query['qs'], query['sort'])
|
||||
qs = qs.distinct()
|
||||
if 'keys' in data:
|
||||
qs = qs[query['range'][0]:query['range'][1]]
|
||||
qs = qs.select_related()
|
||||
|
|
|
@ -36,8 +36,26 @@ pandora.ui.eventsDialog = function() {
|
|||
}, function(result) {
|
||||
that.options({
|
||||
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,
|
||||
height: height - 48,
|
||||
removeEvent: function(event, callback) {
|
||||
pandora.api.removeEvent(event, function(result) {
|
||||
Ox.Request.clearCache(); // fixme: remove
|
||||
callback(result);
|
||||
});
|
||||
},
|
||||
width: width
|
||||
})
|
||||
});
|
||||
|
|
|
@ -202,6 +202,7 @@ pandora.ui.navigationView = function(type, videoRatio) {
|
|||
})
|
||||
.bindEvent({
|
||||
resize: function(data) {
|
||||
// triggered by SplitPanel
|
||||
$element.resizeCalendar();
|
||||
},
|
||||
select: selectItem
|
||||
|
|
|
@ -23,18 +23,18 @@ pandora.ui.placesDialog = function() {
|
|||
}, data), callback);
|
||||
},
|
||||
addPlace: function(place, callback) {
|
||||
Ox.print('ADDPLACE', place);
|
||||
pandora.api.addPlace(place, function(result) {
|
||||
Ox.Request.clearCache(); // fixme: remove
|
||||
callback(result);
|
||||
});
|
||||
},
|
||||
editPlace: function(place, callback) {
|
||||
Ox.print('EDITPLACE', place);
|
||||
pandora.api.editPlace(place, callback);
|
||||
pandora.api.editPlace(place, function(result) {
|
||||
Ox.Request.clearCache(); // fixme: remove
|
||||
callback(result);
|
||||
});
|
||||
},
|
||||
removePlace: function(place, callback) {
|
||||
Ox.print('REMOVEPLACE', place);
|
||||
pandora.api.removePlace(place, function(result) {
|
||||
Ox.Request.clearCache(); // fixme: remove
|
||||
callback(result);
|
||||
|
|
Loading…
Reference in a new issue