summaryrefslogtreecommitdiffstats
path: root/agenda/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'agenda/views.py')
-rwxr-xr-xagenda/views.py348
1 files changed, 170 insertions, 178 deletions
diff --git a/agenda/views.py b/agenda/views.py
index 3a4b3ba..524558c 100755
--- a/agenda/views.py
+++ b/agenda/views.py
@@ -1,203 +1,153 @@
# Create your views here.
-from __future__ import with_statement
+#from __future__ import with_statement
from django.shortcuts import render_to_response, get_object_or_404, get_list_or_404
+from django.db.models import Q
from infopoint.agenda.models import *
from datetime import date
+from django.utils.translation import ugettext as _
from django.http import HttpResponse, HttpResponseRedirect
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth import authenticate, login
from django.contrib.auth.models import Group,User
from django.contrib.comments.models import Comment
from infopoint.agenda.templatetags import *
-from infopoint.agenda.models import Event, Attendance,Todo,PendingTodoManager
-from infopoint.agenda.forms import TodoCreateForm, TodoForm,TodoRelatedCreateForm,GroupAddEventForm,EventForm, RedesForm,TodoCompletedForm
+from infopoint.agenda.models import *
+from infopoint.agenda.forms import EventForm, NewEventForm, NewEventRestrictedForm, RedesForm, GroupAddEventForm, TodoForm, TodoCompletedForm, TodoCreateForm, TodoRelatedCreateForm, DateForm, AttendanceForm, ConfirmForm
from django.contrib.formtools.preview import FormPreview
from django.views.generic import create_update
from django.template import RequestContext
from django.forms import ModelForm
-import vobject
+from django.shortcuts import render_to_response
+from django.utils.safestring import mark_safe
+import calendar as therealcalendar
+import copy
-address = 'Gaona 3'
-city = 'Malaga'
-today = date.today()
+fuckthiscalendar = therealcalendar.Calendar()
-def get_map(type,object_id):
- map = open( '/var/www/media/maps/'+str(type)+'_'+str(object_id)+'.map' )
- info = str(map.read())
- return info
+today = date.today()
+def find_recurrences(event,year,month):
+ recurrences = []
+ alldays = list(fuckthiscalendar.itermonthdays2(int(year), int(month)))
+ if event.recurrence == '2':
+ weekday = event.start_date.isoweekday()-1
+ days_list = filter(lambda day:day[1]==weekday,alldays)
+ for day,weekday in days_list:
+ fakeevent = copy.copy(event)
+ fakeevent.start_date = fakeevent.start_date.replace(day=day+1)
+ if (fakeevent.start_date>fakeevent.end_period):
+ recurrences.append(fakeevent)
+ return recurrences
+
+def calendarshape(request, year, month):
+ """
+ taken from http://journal.redflavor.com/creating-a-flexible-monthly-calendar-in-django
+ """
+ next_events = Event.events.all().order_by('start_date').filter(start_date__year=year, start_date__month=month,public=True,recurrence='0')
+ year = int(year)
+ month = int(month)
+ nothing, last_day = therealcalendar.monthrange(year,month)
+ recurrent_events = Event.events.all().order_by('start_date').filter(start_period__lte=(date(int(year),int(month),last_day)),end_period__gte=(date(int(year),int(month),1)),recurrence__in=['1','2','3'])
+ all_events = list(next_events)
+ for recurrent_event in recurrent_events:
+ all_events += find_recurrences(recurrent_event,year,month)
+ all_days = map(lambda ev:ev.start_date.day, all_events)
+
+ cal = EventShapeCalendar(all_events).formatmonth(year, month)
+ previous, next = month-1,month+1
+ prevyear, postyear = year, year
+ if int(month) == 1:
+ previous = 12
+ prevyear = year-1
+
+ if int(month) == 12:
+ next = 1
+ postyear = year+1
-def ical_one_event(request,object_id):
- cal = vobject.iCalendar()
- cal.add('method').value = 'PUBLISH' # IE/Outlook needs this
- cal.add('calscale').value = 'GREGORIAN'
- for one_event in Event.calendar.filter(pk=object_id):
- cal.add('caldesc').value = 'Infopoint event - '+one_event.title
- cal.add('x-wr-calname').value = one_event.title+' calendar'
- vevent = cal.add('vevent')
- vevent.add('summary').value = one_event.title
- vevent.add('dtstart').value = one_event.start_date
- vevent.add('dtend').value = one_event.end_date
- vevent.add('dtstamp').value = one_event.start_date
- vevent.add('status').value = 'CONFIRMED'
- vevent.add('description').value = one_event.description
- vevent.add('location').value = one_event.location.title
- for user in one_event.atendees.all():
- att = vevent.add('attendee')
- att.value=user.email
- att.rsvp_param='True'
- att.cn_param=user.username
- att.role_param='REQ-PARTICIPANT'
- if user.attendance == 1:
- att.partstat_param='ACCEPTED'
- att.dir_param="http://infopoint/agenda/user/"+str(user.id)+"/busy/"
-
- for group in one_event.group.all():
- one_group = vevent.add('categorie')
- one_group.value=group.group
- one_group.dir_param="http://infopoint/agenda/group/"+str(group.group.id)+"/cal/"
- for pixie in one_event.pixie.all()[:1]:
- vevent.add('organizer').value = pixie.email
- icalstream = cal.serialize()
- response = HttpResponse(icalstream, mimetype='text/calendar')
- response['Filename'] = 'filename.ics' # IE needs this
- response['Content-Disposition'] = 'attachment; filename=filename.ics'
- return response
-
-def ical_user_busytime(request,object_id):
- cal = vobject.iCalendar()
- user = User.objects.get(pk=object_id)
- cal.add('x-wr-calname').value = 'infopoint free/busy time for '+user.username
- cal.add('calscale').value = 'GREGORIAN'
- cal.add('URL').value = 'http://infopoint/agenda/user/'+object_id+'/busy'
- for one_event in user.events.all().exclude(title__in=user.event_set.all()):
- freebusystart = one_event.start_date
- freebusyend = one_event.end_date
- vevent = cal.add('VFREEBUSY')
- vevent.add('summary').value = 'BUSY'
- vevent.add('dtstart').value = one_event.start_date
- vevent.add('dtend').value = one_event.end_date
- vevent.add('transp').value = 'OPAQUE'
- vevent.add('freebusy').value = [(vevent.dtstart.value,vevent.dtend.value)]
- for one_event in user.event_set.all():
- freebusystart = one_event.start_date
- freebusyend = one_event.end_date
- vevent = cal.add('VFREEBUSY')
- vevent.add('summary').value = 'BUSY'
- vevent.add('dtstart').value = one_event.start_date
- vevent.add('dtend').value = one_event.end_date
- vevent.add('transp').value = 'OPAQUE'
- vevent.add('freebusy').value = [(vevent.dtstart.value,vevent.dtend.value)]
- icalstream = cal.serialize()
- response = HttpResponse(icalstream, mimetype='text/calendar')
- response['Filename'] = 'filename.ics' # IE needs this
- response['Content-Disposition'] = 'attachment; filename=filename.ics'
- return response
-
-def ical_user_events(request,object_id):
- cal = vobject.iCalendar()
- user = User.objects.get(pk=object_id)
- cal.add('method').value = 'PUBLISH' # IE/Outlook needs this
- cal.add('calscale').value = 'GREGORIAN'
- cal.add('x-wr-calname').value = 'infopoint calendar for '+user.username
- for one_event in user.event_set.all():
- vevent = cal.add('vevent')
- vevent.add('summary').value = one_event.title
- vevent.add('dtstart').value = one_event.start_date
- vevent.add('status').value = 'CONFIRMED'
- vevent.add('TRANSP').value = 'OPAQUE'
- vevent.add('dtend').value = one_event.end_date
- vevent.add('description').value = one_event.description
- vevent.add('location').value = one_event.location.title
- for user in one_event.atendees.all():
- att = vevent.add('attendee')
- att.value=user.email
- att.rsvp_param='True'
- att.cn_param=user.username
- att.role_param='REQ-PARTICIPANT'
- att.partstat_param='ACCEPTED'
- att.dir_param="http://infopoint/agenda/user/"+str(user.id)+"/busy/"
- for pixie in one_event.pixie.all()[:1]:
- vevent.add('organizer').value = pixie.email
- icalstream = cal.serialize()
- response = HttpResponse(icalstream, mimetype='text/calendar')
- response['Filename'] = 'filename.ics' # IE needs this
- response['Content-Disposition'] = 'attachment; filename=filename.ics'
- return response
-
-def ical_next_events(request):
- cal = vobject.iCalendar()
- cal.add('method').value = 'PUBLISH' # IE/Outlook needs this
- cal.add('calscale').value = 'GREGORIAN'
- cal.add('x-wr-calname').value = 'infopoint calendar'
- for one_event in Event.events.next_events():
- vevent = cal.add('vevent')
- vevent.add('summary').value = one_event.title
- vevent.add('dtstart').value = one_event.start_date
- vevent.add('dtend').value = one_event.end_date
- vevent.add('dtstamp').value = one_event.start_date
- vevent.add('description').value = one_event.description
- vevent.add('location').value = one_event.location.title
- for user in one_event.atendees.all():
- att = vevent.add('attendee')
- att.value=user.email
- att.rsvp_param='True'
- att.cn_param=user.username
- att.role_param='REQ-PARTICIPANT'
- att.partstat_param='ACCEPTED'
- att.dir_param="http://infopoint/agenda/user/"+str(user.id)+"/busy/"
- for pixie in one_event.pixie.all()[:1]:
- vevent.add('organizer').value = pixie.email
- icalstream = cal.serialize()
- response = HttpResponse(icalstream, mimetype='text/calendar')
- response['Filename'] = 'filename.ics' # IE needs this
- response['Content-Disposition'] = 'attachment; filename=filename.ics'
- return response
+ return render_to_response('agenda/calendarshape.html', {'prevyear':prevyear, 'postyear':postyear, 'month':month,'previous':previous,'next':next, 'calendar': mark_safe(cal),'today': today })
def justonegroup(request,object_id):
- group = Group.objects.get(pk=object_id)
+ group = Group.objects.select_related().get(pk=object_id)
+ todolist = Todo.todos.all().filter(network=group,done=False).order_by('due_date')
+ wishlist = Wish.objects.all().filter(network=group,done=False).order_by('due_date')
+ group_events = Event.events.next_events().filter(redes=object_id).distinct()
newtodo = TodoRelatedCreateForm()
todos = Todo.todos.pending_todos().filter(network=object_id).filter(public=True)
- map_coordinates = str(get_map('group',object_id)).encode()
- return render_to_response('agenda/one_group.html', {'group': group, 'todos': todos, 'newtodo': newtodo, 'map_coordinates':map_coordinates },context_instance=RequestContext(request))
+ return render_to_response('agenda/one_group.html', {'wishlist':wishlist, 'todolist':todolist,'group': group, 'group_events': group_events,'todos': todos, 'newtodo': newtodo },context_instance=RequestContext(request))
def mismensajes(request):
- group_todos = Todo.todos.pending_todos().filter(network__user=request.user).order_by('due_date')
- missing_pixies = Event.events.missing_pixies().filter(redes__user=1).distinct()
user = request.user
- logentries = user.logentry_set.all()[:5]
+ todolist = Todo.todos.all().filter(done=False).order_by('due_date')
+ wishlist = Wish.objects.all().filter(done=False).order_by('due_date')
newtodo = TodoCreateForm()
if request.user.is_authenticated():
- return render_to_response('agenda/user_page.html', {'logentries': logentries,'group_todos': group_todos, 'newtodo': newtodo, 'missing_pixies': missing_pixies },context_instance=RequestContext(request))
+ missing_pixies = Event.events.missing_pixies().filter(redes__user=user.id).distinct()
+ group_todos = Todo.todos.pending_todos().filter(network__user=request.user).order_by('due_date')
+ my_mentored_events = Event.events.next_events().filter(pixie=user).select_related()
+ return render_to_response('agenda/user_page.html', {'wishlist':wishlist, 'todolist':todolist,'group_todos': group_todos, 'my_mentored_events': my_mentored_events,'newtodo': newtodo, 'missing_pixies': missing_pixies },context_instance=RequestContext(request))
else:
event = Event.calendar.filter(public=True)
- return render_to_response('agenda/event_list.html', {'log': log })
+ return render_to_response('agenda/event_list.html', {'event':event })
def render (request):
- event = Event.events.today_events.filter(public=True)
+ event = Event.events.today_events().filter(public=True)
if request.user.is_authenticated():
+ event = Event.events.today_events()
return render_to_response('agenda/event_list.html', {'event': event},context_instance=RequestContext(request))
else:
- #event = Event.calendar.filter(public=True)
return render_to_response('agenda/event_list.html', {'event': event })
+
+def orphan_events (request):
+ event = missing_pixies = Event.events.missing_pixies().distinct()
+ wishlist = Wish.objects.all().filter(done=False).order_by('due_date')
+ if request.user.is_authenticated():
+ todolist = Todo.todos.all().filter(done=False).order_by('due_date')
+ return render_to_response('agenda/event_list.html', {'todolist':todolist,'wishlist': wishlist,'event': event},context_instance=RequestContext(request))
+ else:
+ event = Event.events.next_events().filter(public=True)
+ return render_to_response('agenda/event_list.html', {'event': event })
+
+def calendar_shape(request):
+ event = Event.events.all().order_by('start_date')
+ wishlist = Wish.objects.all().filter(done=False).order_by('due_date')
+ todolist = Todo.todos.all().filter(done=False).order_by('due_date')
+ return render_to_response('agenda/event_list.html', {'todolist':todolist,'wishlist': wishlist,'event': event},context_instance=RequestContext(request))
+
def calendar (request):
- event = Event.events.next_events()
+ event = Event.events.next_events().order_by('start_date')
+ wishlist = Wish.objects.all().filter(done=False).order_by('due_date')
if request.user.is_authenticated():
- return render_to_response('agenda/event_list.html', {'event': event},context_instance=RequestContext(request))
+ todolist = Todo.todos.all().filter(done=False).order_by('due_date')
+ return render_to_response('agenda/event_list.html', {'todolist':todolist,'wishlist': wishlist,'event': event},context_instance=RequestContext(request))
else:
- #event = Event.calendar.filter(public=True)
+ event = Event.events.next_events().filter(public=True)
return render_to_response('agenda/event_list.html', {'event': event })
+def wishlist (request):
+ wishlist = Wish.objects.all().filter(done=False).order_by('due_date')
+ return render_to_response('agenda/wishlist.html', {'wishlist': wishlist}, context_instance=RequestContext(request))
+
+def logout_view(request):
+ logout(request)
+ return HttpResponseRedirect('/agenda/')
+
def random(request):
- event = Event.events.next_events.order_by('?')[:1]
+ event = Event.events.next_events().order_by('?')[:1]
return render_to_response('agenda/random.html', {'event': event },context_instance=RequestContext(request))
+def get_map(object_id):
+ try:
+ map = open( '/var/www/media/maps/event_'+str(object_id)+'.map' )
+ except:
+ return HttpResponseRedirect('/agenda/map/'+object_id)
+ info = str(map.read())
+ return info
def event(request,object_id):
event = get_object_or_404(Event, pk=object_id)
@@ -210,36 +160,76 @@ def event(request,object_id):
attendance = 'none'
newtodo = TodoRelatedCreateForm()
completed_todo = TodoCompletedForm()
- map_coordinates = str(get_map('event',object_id)).encode()
+ try:
+ map_coordinates = str(get_map(object_id)).encode()
+ except:
+ return HttpResponseRedirect('/agenda/map/'+object_id)
addtogroup = GroupAddEventForm()
pending_todos = Todo.todos.pending_todos().filter(event=object_id)
- return render_to_response('agenda/one_event.html', {'event': event, 'invite': invite, 'attendance': attendance, 'newtodo': newtodo, 'addtogroup': addtogroup, 'pending_todos': pending_todos, 'completed_todo': completed_todo, 'map_coordinates': map_coordinates, 'address': address, 'city': city },context_instance=RequestContext(request))
+ return render_to_response('agenda/one_event.html', {'event': event,'today': today , 'invite': invite, 'attendance': attendance, 'newtodo': newtodo, 'addtogroup': addtogroup, 'pending_todos': pending_todos, 'completed_todo': completed_todo, 'map_coordinates': map_coordinates },context_instance=RequestContext(request))
+
+def add_new_event(request):
+ form = NewEventRestrictedForm()
+ general_form = EventForm()
+ mydate = DateForm()
+ return render_to_response('agenda/add_new_event.html', {'general_form':general_form,'form': form, 'mydate': mydate },context_instance=RequestContext(request))
+
+def submit_new_event(request):
+ if request.method == 'POST':
+
+ request.POST['start_date'] = str(request.POST['start_date_0']+" "+request.POST['start_date_1'])
+
+
+ form = NewEventRestrictedForm(request.POST)
+
+ #form.start_date = str(request.POST['start_date_0']+" "+request.POST['start_date_1'])
+ #request.POST['start_date_0']+" "+request.POST['start_date_1'] = form.start_date
+ #form.end_date = str(request.POST['end_date_0']+" "+request.POST['end_date_1'])
+ if form.is_valid():
+ new_event = form.save(commit=False)
+ #form.save_m2m()
+ form.save()
+
+ return HttpResponseRedirect('/agenda/'+new_event.id)
+ return render_to_response('agenda/add_new_event.html', {'form': form },context_instance=RequestContext(request))
+ return render_to_response('agenda/add_new_event.html', {'form': form, 'mydate': mydate },context_instance=RequestContext(request))
def adoptevent(request,object_id):
- event = get_object_or_404(Event, pk=object_id)
- event.pixie.add(request.user)
- return HttpResponseRedirect('/agenda/'+object_id)
+ if request.method == 'POST':
+ event = get_object_or_404(Event, pk=object_id)
+ event.pixie.add(request.user)
+ return HttpResponseRedirect('/agenda/'+object_id)
def submittodo(request):
- f = TodoForm(request.POST)
- f.save()
- user = request.user
- user.message_set.create(message=f.title+' has been saved')
- return render_to_response('agenda/user_events.html', {'f': f},context_instance=RequestContext(request))
+ if request.method == 'POST':
+ f = TodoForm(request.POST)
+ f.save()
+ user = request.user
+ user.message_set.create(message=str(f.title+' has been saved'))
+ return render_to_response('agenda/user_events.html', {'f': f},context_instance=RequestContext(request))
-def closetodo(request,todo_id,event_id):
+def closealltodo(request,todo_id):
todo = get_object_or_404(Todo, pk=todo_id)
todo.done = True
todo.save()
- request.user.message_set.create(message=todo.title+' has been closed as completed')
- return HttpResponseRedirect('/agenda/'+event_id)
+ request.user.message_set.create(message=todo.title+_(' has been closed as completed'))
+ return HttpResponseRedirect('/agenda/me/')
+
+def closetodo(request,todo_id,event_id):
+ if request.method == 'POST':
+ todo = get_object_or_404(Todo, pk=todo_id)
+ todo.done = True
+ todo.save()
+ request.user.message_set.create(message=todo.title+' has been closed as completed')
+ return HttpResponseRedirect('/agenda/map/'+event_id)
def closegrouptodo(request,todo_id,object_id):
- todo = get_object_or_404(Todo, pk=todo_id)
- todo.done = True
- todo.save()
- return HttpResponseRedirect('/group/'+object_id)
+ if request.method == 'POST':
+ todo = get_object_or_404(Todo, pk=todo_id)
+ todo.done = True
+ todo.save()
+ return HttpResponseRedirect('/group/'+object_id)
def addtodo(request):
@@ -258,7 +248,7 @@ def addeventtogroupsave(request,event_id):
f.save()
except:
pass
- return HttpResponseRedirect('/agenda/'+event_id)
+ return HttpResponseRedirect('/agenda/map/'+event_id)
#return render_to_response('agenda/one_event.html', {'f': f, 'event': event},context_instance=RequestContext(request))
def addtodotoevent(request,event_id):
@@ -270,7 +260,7 @@ def saveeventtodo(request,event_id):
event = get_object_or_404(Event, pk=event_id)
f = TodoForm(request.POST)
f.save()
- return HttpResponseRedirect('/agenda/'+event_id)
+ return HttpResponseRedirect('/agenda/map/'+event_id)
#return render_to_response('agenda/one_event.html', {'f': f, 'event': event},context_instance=RequestContext(request))
def savegrouptodo(request,object_id):
@@ -286,14 +276,18 @@ def location(request, object_id):
want
"""
location = get_object_or_404(Location, pk=object_id)
- map_coordinates = str(get_map('location',object_id)).encode()
- if request.user.is_authenticated():
- return render_to_response('agenda/location_events.html', {'location': location, 'map_coordinates': map_coordinates},context_instance=RequestContext(request))
+ wishlist = Wish.objects.all().filter(location=location,done=False).order_by('due_date')
+
+ if request.user.is_authenticated():
+ todolist = Todo.todos.all().filter(location=location,done=False).order_by('due_date')
+ location_events = Event.events.next_events().filter(location=location.id).distinct()
+ return render_to_response('agenda/location_events.html', {'wishlist':wishlist,'todolist':todolist,'location_events':location_events,'location': location},context_instance=RequestContext(request))
else:
- return render_to_response('agenda/location_events.html', {'location': location })
+ location_events = Event.events.next_events().filter(public=True,redes=location.redes.id).distinct()
+ return render_to_response('agenda/location_events.html', {'location': location,'wishlist':wishlist,'location_events':location_events })
def attendance(request, object_id):
- if request.user.is_authenticated():
+ if request.user.is_authenticated():
event = get_object_or_404(Event, pk=object_id)
person = request.user.id()
@@ -318,7 +312,7 @@ def attendance(request, object_id):
def confirmation_pending(request):
object_id=request.user.id
- if request.user.is_authenticated():
+ if request.user.is_authenticated():
user = get_object_or_404(User, pk=object_id)
attendance = user.attendance_set.all()
confirmed = user.attendance.filter(attendance='1')
@@ -337,5 +331,3 @@ def attend(request,object_id):
def one_comment(request,object_id):
comment = Comment.objects.get(pk=object_id)
return render_to_response('agenda/one_comment.html', {'comment': comment},context_instance=RequestContext(request))
-
-