events
This commit is contained in:
parent
4b9ea3731a
commit
093e1b86f3
8 changed files with 81 additions and 67 deletions
|
@ -1,42 +0,0 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
|
||||||
from __future__ import division, with_statement
|
|
||||||
|
|
||||||
from django.db import models
|
|
||||||
|
|
||||||
from ox.django import fields
|
|
||||||
|
|
||||||
import managers
|
|
||||||
|
|
||||||
|
|
||||||
class Date(models.Model):
|
|
||||||
'''
|
|
||||||
Dates are dates in time that can be once or recurring,
|
|
||||||
From Mondays to Spring to 1989 to Roman Empire
|
|
||||||
'''
|
|
||||||
name = models.CharField(null=True, max_length=255, unique=True)
|
|
||||||
name_sort = models.CharField(null=True, max_length=255, unique=True)
|
|
||||||
name_find = models.TextField(default='', editable=True)
|
|
||||||
wikipediaId = models.CharField(max_length=1000, blank=True)
|
|
||||||
|
|
||||||
objects = managers.DateManager()
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
ordering = ('name_sort', )
|
|
||||||
|
|
||||||
#FIXME: how to deal with aliases
|
|
||||||
aliases = fields.TupleField(default=[])
|
|
||||||
|
|
||||||
#once|year|week|day
|
|
||||||
recurring = models.IntegerField(default=0)
|
|
||||||
|
|
||||||
#start yyyy-mm-dd|mm-dd|dow 00:00|00:00
|
|
||||||
#end yyyy-mm-dd|mm-dd|dow 00:00|00:01
|
|
||||||
start = models.CharField(null=True, max_length=255)
|
|
||||||
end = models.CharField(null=True, max_length=255)
|
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
|
||||||
if not self.name_sort:
|
|
||||||
self.name_sort = self.name
|
|
||||||
self.name_find = self.name + '||'.join(self.aliases)
|
|
||||||
super(Date, self).save(*args, **kwargs)
|
|
|
@ -6,6 +6,6 @@ from django.contrib import admin
|
||||||
import models
|
import models
|
||||||
|
|
||||||
|
|
||||||
class DateAdmin(admin.ModelAdmin):
|
class EventAdmin(admin.ModelAdmin):
|
||||||
search_fields = ['name']
|
search_fields = ['name']
|
||||||
admin.site.register(models.Date, DateAdmin)
|
admin.site.register(models.Event, EventAdmin)
|
|
@ -4,10 +4,10 @@
|
||||||
from django.db.models import Q, Manager
|
from django.db.models import Q, Manager
|
||||||
|
|
||||||
|
|
||||||
class DateManager(Manager):
|
class EventManager(Manager):
|
||||||
|
|
||||||
def get_query_set(self):
|
def get_query_set(self):
|
||||||
return super(DateManager, self).get_query_set()
|
return super(EventManager, self).get_query_set()
|
||||||
|
|
||||||
def find(self, q=''):
|
def find(self, q=''):
|
||||||
qs = self.get_query_set()
|
qs = self.get_query_set()
|
56
pandora/event/models.py
Normal file
56
pandora/event/models.py
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
from __future__ import division, with_statement
|
||||||
|
|
||||||
|
from django.db import models
|
||||||
|
from django.contrib.auth.models import User, Group
|
||||||
|
|
||||||
|
from ox.django import fields
|
||||||
|
|
||||||
|
import managers
|
||||||
|
|
||||||
|
|
||||||
|
class Event(models.Model):
|
||||||
|
'''
|
||||||
|
Events are events in time that can be once or recurring,
|
||||||
|
From Mondays to Spring to 1989 to Roman Empire
|
||||||
|
'''
|
||||||
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
|
modified = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
|
user = models.ForeignKey(User, null=True, related_name='events')
|
||||||
|
|
||||||
|
name = models.CharField(null=True, max_length=255, unique=True)
|
||||||
|
name_sort = models.CharField(null=True, max_length=255, unique=True)
|
||||||
|
name_find = models.TextField(default='', editable=True)
|
||||||
|
wikipediaId = models.CharField(max_length=1000, blank=True)
|
||||||
|
|
||||||
|
alternativeNames = fields.TupleField(default=[])
|
||||||
|
|
||||||
|
objects = managers.EventManager()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
ordering = ('name_sort', )
|
||||||
|
|
||||||
|
#start yyyy-mm-dd|mm-dd|dow 00:00|00:00
|
||||||
|
#end yyyy-mm-dd|mm-dd|dow 00:00|00:01
|
||||||
|
start = models.CharField(default='', max_length=255)
|
||||||
|
end = models.CharField(default='', max_length=255)
|
||||||
|
startTime = models.BigIntegerField(default=0)
|
||||||
|
endTime = models.BigIntegerField(default=0)
|
||||||
|
type = models.CharField(default='', max_length=255)
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
if not self.name_sort:
|
||||||
|
self.name_sort = self.name
|
||||||
|
self.name_find = self.name + '||'.join(self.alternativeNames)
|
||||||
|
super(Event, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
def json(self):
|
||||||
|
return {
|
||||||
|
'name': self.name,
|
||||||
|
'alternativeNames': self.alternativeNames,
|
||||||
|
'start': self.start,
|
||||||
|
'end': self.end,
|
||||||
|
'type': self.type
|
||||||
|
}
|
|
@ -11,20 +11,20 @@ from api.actions import actions
|
||||||
|
|
||||||
|
|
||||||
@login_required_json
|
@login_required_json
|
||||||
def addDate(request):
|
def addEvent(request):
|
||||||
data = json.loads(request.POST['data'])
|
data = json.loads(request.POST['data'])
|
||||||
if models.Date.filter(name=data['name']).count() == 0:
|
if models.Event.filter(name=data['name']).count() == 0:
|
||||||
place = models.Date(name = data['name'])
|
place = models.Event(name = data['name'])
|
||||||
place.save()
|
place.save()
|
||||||
response = json_response(status=200, text='created')
|
response = json_response(status=200, text='created')
|
||||||
else:
|
else:
|
||||||
response = json_response(status=403, text='place name exists')
|
response = json_response(status=403, text='place name exists')
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
actions.register(addDate, cache=False)
|
actions.register(addEvent, cache=False)
|
||||||
|
|
||||||
|
|
||||||
@login_required_json
|
@login_required_json
|
||||||
def editDate(request):
|
def editEvent(request):
|
||||||
'''
|
'''
|
||||||
param data
|
param data
|
||||||
{
|
{
|
||||||
|
@ -34,34 +34,34 @@ def editDate(request):
|
||||||
date contains key/value pairs with place propterties
|
date contains key/value pairs with place propterties
|
||||||
'''
|
'''
|
||||||
data = json.loads(request.POST['data'])
|
data = json.loads(request.POST['data'])
|
||||||
Date = get_object_or_404_json(models.Date, pk=data['id'])
|
Event = get_object_or_404_json(models.Event, pk=data['id'])
|
||||||
if Date.editable(request.user):
|
if Event.editable(request.user):
|
||||||
conflict = False
|
conflict = False
|
||||||
names = [data['date']['name']] + data['date']['aliases']
|
names = [data['date']['name']] + data['date']['aliases']
|
||||||
for name in names: #FIXME: also check aliases!
|
for name in names: #FIXME: also check aliases!
|
||||||
if models.Date.filter(name=data['name']).exclude(id=Date.id).count() != 0:
|
if models.Event.filter(name=data['name']).exclude(id=Event.id).count() != 0:
|
||||||
conflict = True
|
conflict = True
|
||||||
if not conflict:
|
if not conflict:
|
||||||
for key in data['date']:
|
for key in data['date']:
|
||||||
setattr(Date, key, data['date'][key])
|
setattr(Event, key, data['date'][key])
|
||||||
Date.save()
|
Event.save()
|
||||||
response = json_response(status=200, text='updated')
|
response = json_response(status=200, text='updated')
|
||||||
else:
|
else:
|
||||||
response = json_response(status=403, text='Date name/alias conflict')
|
response = json_response(status=403, text='Event name/alias conflict')
|
||||||
else:
|
else:
|
||||||
response = json_response(status=403, text='permission denied')
|
response = json_response(status=403, text='permission denied')
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
actions.register(editDate, cache=False)
|
actions.register(editEvent, cache=False)
|
||||||
|
|
||||||
|
|
||||||
@login_required_json
|
@login_required_json
|
||||||
def removeDate(request):
|
def removeEvent(request):
|
||||||
response = json_response(status=501, text='not implemented')
|
response = json_response(status=501, text='not implemented')
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
actions.register(removeDate, cache=False)
|
actions.register(removeEvent, cache=False)
|
||||||
|
|
||||||
|
|
||||||
def findDate(request):
|
def findEvent(request):
|
||||||
'''
|
'''
|
||||||
param data
|
param data
|
||||||
{'query': query, 'sort': array, 'range': array}
|
{'query': query, 'sort': array, 'range': array}
|
||||||
|
@ -91,13 +91,13 @@ Positions
|
||||||
|
|
||||||
query: query object, more on query syntax at
|
query: query object, more on query syntax at
|
||||||
https://wiki.0x2620.org/wiki/pandora/QuerySyntax
|
https://wiki.0x2620.org/wiki/pandora/QuerySyntax
|
||||||
ids: ids of dates for which positions are required
|
ids: ids of events for which positions are required
|
||||||
'''
|
'''
|
||||||
data = json.loads(request.POST['data'])
|
data = json.loads(request.POST['data'])
|
||||||
response = json_response(status=200, text='ok')
|
response = json_response(status=200, text='ok')
|
||||||
response['data']['places'] = []
|
response['data']['events'] = []
|
||||||
#FIXME: add coordinates to limit search
|
#FIXME: add coordinates to limit search
|
||||||
for p in models.Date.objects.find(data['query']):
|
for p in models.Event.objects.find(data['query']):
|
||||||
response['data']['dates'].append(p.json())
|
response['data']['events'].append(p.json())
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
actions.register(findDate)
|
actions.register(findEvent)
|
|
@ -124,7 +124,7 @@ INSTALLED_APPS = (
|
||||||
'annotation',
|
'annotation',
|
||||||
'app',
|
'app',
|
||||||
'archive',
|
'archive',
|
||||||
'date',
|
'event',
|
||||||
'item',
|
'item',
|
||||||
'itemlist',
|
'itemlist',
|
||||||
'person',
|
'person',
|
||||||
|
|
Loading…
Reference in a new issue