From 6886c76255a4e3070e0d75901e3897efcdfc0881 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sat, 28 May 2011 13:35:57 +0200 Subject: [PATCH] events --- pandora/date/models.py | 42 ---------------------- pandora/{date => event}/__init__.py | 0 pandora/{date => event}/admin.py | 4 +-- pandora/{date => event}/managers.py | 4 +-- pandora/event/models.py | 56 +++++++++++++++++++++++++++++ pandora/{date => event}/tests.py | 0 pandora/{date => event}/views.py | 40 ++++++++++----------- pandora/settings.py | 2 +- 8 files changed, 81 insertions(+), 67 deletions(-) delete mode 100644 pandora/date/models.py rename pandora/{date => event}/__init__.py (100%) rename pandora/{date => event}/admin.py (61%) rename pandora/{date => event}/managers.py (74%) create mode 100644 pandora/event/models.py rename pandora/{date => event}/tests.py (100%) rename pandora/{date => event}/views.py (73%) diff --git a/pandora/date/models.py b/pandora/date/models.py deleted file mode 100644 index fc4057d8..00000000 --- a/pandora/date/models.py +++ /dev/null @@ -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) diff --git a/pandora/date/__init__.py b/pandora/event/__init__.py similarity index 100% rename from pandora/date/__init__.py rename to pandora/event/__init__.py diff --git a/pandora/date/admin.py b/pandora/event/admin.py similarity index 61% rename from pandora/date/admin.py rename to pandora/event/admin.py index a02f4185..b1725b96 100644 --- a/pandora/date/admin.py +++ b/pandora/event/admin.py @@ -6,6 +6,6 @@ from django.contrib import admin import models -class DateAdmin(admin.ModelAdmin): +class EventAdmin(admin.ModelAdmin): search_fields = ['name'] -admin.site.register(models.Date, DateAdmin) +admin.site.register(models.Event, EventAdmin) diff --git a/pandora/date/managers.py b/pandora/event/managers.py similarity index 74% rename from pandora/date/managers.py rename to pandora/event/managers.py index 78333b5c..1d28a300 100644 --- a/pandora/date/managers.py +++ b/pandora/event/managers.py @@ -4,10 +4,10 @@ from django.db.models import Q, Manager -class DateManager(Manager): +class EventManager(Manager): def get_query_set(self): - return super(DateManager, self).get_query_set() + return super(EventManager, self).get_query_set() def find(self, q=''): qs = self.get_query_set() diff --git a/pandora/event/models.py b/pandora/event/models.py new file mode 100644 index 00000000..26f65a51 --- /dev/null +++ b/pandora/event/models.py @@ -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 + } diff --git a/pandora/date/tests.py b/pandora/event/tests.py similarity index 100% rename from pandora/date/tests.py rename to pandora/event/tests.py diff --git a/pandora/date/views.py b/pandora/event/views.py similarity index 73% rename from pandora/date/views.py rename to pandora/event/views.py index b95bc199..91ccca8c 100644 --- a/pandora/date/views.py +++ b/pandora/event/views.py @@ -11,20 +11,20 @@ from api.actions import actions @login_required_json -def addDate(request): +def addEvent(request): data = json.loads(request.POST['data']) - if models.Date.filter(name=data['name']).count() == 0: - place = models.Date(name = data['name']) + if models.Event.filter(name=data['name']).count() == 0: + place = models.Event(name = data['name']) place.save() response = json_response(status=200, text='created') else: response = json_response(status=403, text='place name exists') return render_to_json_response(response) -actions.register(addDate, cache=False) +actions.register(addEvent, cache=False) @login_required_json -def editDate(request): +def editEvent(request): ''' param data { @@ -34,34 +34,34 @@ def editDate(request): date contains key/value pairs with place propterties ''' data = json.loads(request.POST['data']) - Date = get_object_or_404_json(models.Date, pk=data['id']) - if Date.editable(request.user): + Event = get_object_or_404_json(models.Event, pk=data['id']) + if Event.editable(request.user): conflict = False names = [data['date']['name']] + data['date']['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 if not conflict: for key in data['date']: - setattr(Date, key, data['date'][key]) - Date.save() + setattr(Event, key, data['date'][key]) + Event.save() response = json_response(status=200, text='updated') else: - response = json_response(status=403, text='Date name/alias conflict') + response = json_response(status=403, text='Event name/alias conflict') else: response = json_response(status=403, text='permission denied') return render_to_json_response(response) -actions.register(editDate, cache=False) +actions.register(editEvent, cache=False) @login_required_json -def removeDate(request): +def removeEvent(request): response = json_response(status=501, text='not implemented') return render_to_json_response(response) -actions.register(removeDate, cache=False) +actions.register(removeEvent, cache=False) -def findDate(request): +def findEvent(request): ''' param data {'query': query, 'sort': array, 'range': array} @@ -91,13 +91,13 @@ Positions query: query object, more on query syntax at 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']) response = json_response(status=200, text='ok') - response['data']['places'] = [] + response['data']['events'] = [] #FIXME: add coordinates to limit search - for p in models.Date.objects.find(data['query']): - response['data']['dates'].append(p.json()) + for p in models.Event.objects.find(data['query']): + response['data']['events'].append(p.json()) return render_to_json_response(response) -actions.register(findDate) +actions.register(findEvent) diff --git a/pandora/settings.py b/pandora/settings.py index 60d9d008..20a68706 100644 --- a/pandora/settings.py +++ b/pandora/settings.py @@ -124,7 +124,7 @@ INSTALLED_APPS = ( 'annotation', 'app', 'archive', - 'date', + 'event', 'item', 'itemlist', 'person',