add/editEvents

This commit is contained in:
j 2011-10-09 17:53:18 +02:00
parent 6e3dc69e6c
commit f8523b7ca2
2 changed files with 7 additions and 3 deletions

View file

@ -79,7 +79,7 @@ class Event(models.Model):
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
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) + '||'
super(Event, self).save(*args, **kwargs) super(Event, self).save(*args, **kwargs)
def get_id(self): def get_id(self):

View file

@ -2,6 +2,7 @@
# 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 ox
from ox.utils import json from ox.utils import json
from ox.django.decorators import login_required_json from ox.django.decorators import login_required_json
from ox.django.shortcuts import render_to_json_response, get_object_or_404_json, json_response from ox.django.shortcuts import render_to_json_response, get_object_or_404_json, json_response
@ -10,7 +11,7 @@ from api.actions import actions
from item import utils from item import utils
import models import models
import tasks
@login_required_json @login_required_json
def addEvent(request): def addEvent(request):
@ -37,7 +38,9 @@ def addEvent(request):
if key in data and data[key]: if key in data and data[key]:
setattr(event, key, data[key]) setattr(event, key, data[key])
event.save() event.save()
tasks.update_matches.delay(event.id)
response = json_response(status=200, text='created') response = json_response(status=200, text='created')
response['data'] = event.json()
else: else:
response = json_response(status=403, text='name exists') response = json_response(status=403, text='name exists')
response['data']['names'] = existing_names response['data']['names'] = existing_names
@ -57,7 +60,7 @@ def editEvent(request):
update provides keys of event with id update provides keys of event with id
''' '''
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):
conflict = False conflict = False
conflict_names = [] conflict_names = []
@ -72,6 +75,7 @@ def editEvent(request):
if key in data: if key in data:
setattr(event, key, data[key]) setattr(event, key, data[key])
event.save() event.save()
tasks.update_matches.delay(event.id)
response = json_response(status=200, text='updated') response = json_response(status=200, text='updated')
else: else:
response = json_response(status=403, text='Event name conflict') response = json_response(status=403, text='Event name conflict')