summaryrefslogtreecommitdiffstats
path: root/agenda/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'agenda/views.py')
-rwxr-xr-xagenda/views.py341
1 files changed, 341 insertions, 0 deletions
diff --git a/agenda/views.py b/agenda/views.py
new file mode 100755
index 0000000..3a4b3ba
--- /dev/null
+++ b/agenda/views.py
@@ -0,0 +1,341 @@
+# Create your views here.
+from __future__ import with_statement
+from django.shortcuts import render_to_response, get_object_or_404, get_list_or_404
+from infopoint.agenda.models import *
+from datetime import date
+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 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
+
+address = 'Gaona 3'
+city = 'Malaga'
+
+today = date.today()
+
+def get_map(type,object_id):
+ map = open( '/var/www/media/maps/'+str(type)+'_'+str(object_id)+'.map' )
+ info = str(map.read())
+ return info
+
+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
+
+
+def justonegroup(request,object_id):
+ group = Group.objects.get(pk=object_id)
+ 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))
+
+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]
+ 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))
+ else:
+ event = Event.calendar.filter(public=True)
+ return render_to_response('agenda/event_list.html', {'log': log })
+
+def render (request):
+ event = Event.events.today_events.filter(public=True)
+
+ if request.user.is_authenticated():
+ 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 calendar (request):
+ event = Event.events.next_events()
+ if request.user.is_authenticated():
+ 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 random(request):
+ event = Event.events.next_events.order_by('?')[:1]
+
+ return render_to_response('agenda/random.html', {'event': event },context_instance=RequestContext(request))
+
+
+def event(request,object_id):
+ event = get_object_or_404(Event, pk=object_id)
+ try:
+ attendance = Attendance.objects.get(event=object_id,person=request.user.id)
+ invite = 'confirm'
+
+ except Attendance.DoesNotExist:
+ invite = 'True'
+ attendance = 'none'
+ newtodo = TodoRelatedCreateForm()
+ completed_todo = TodoCompletedForm()
+ map_coordinates = str(get_map('event',object_id)).encode()
+ 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))
+
+def adoptevent(request,object_id):
+ 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))
+
+def closetodo(request,todo_id,event_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)
+
+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)
+
+
+def addtodo(request):
+ newtodo = TodoCreateForm()
+ return render_to_response('agenda/add_todo.html', {'f': newtodo },context_instance=RequestContext(request))
+
+def addeventtogroup(request,event_id):
+ event = get_object_or_404(Event, pk=event_id)
+ addtogroup = GroupAddEventForm()
+ return render_to_response('agenda/add_event_to_group.html', {'f': addtogroup, 'event': event },context_instance=RequestContext(request))
+
+
+def addeventtogroupsave(request,event_id):
+ f = RedesForm(request.POST)
+ try:
+ f.save()
+ except:
+ pass
+ return HttpResponseRedirect('/agenda/'+event_id)
+ #return render_to_response('agenda/one_event.html', {'f': f, 'event': event},context_instance=RequestContext(request))
+
+def addtodotoevent(request,event_id):
+ event = get_object_or_404(Event, pk=event_id)
+ newtodo = TodoRelatedCreateForm()
+ return render_to_response('agenda/add_todo_to_event.html', {'f': newtodo, 'event': event },context_instance=RequestContext(request))
+
+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 render_to_response('agenda/one_event.html', {'f': f, 'event': event},context_instance=RequestContext(request))
+
+def savegrouptodo(request,object_id):
+ group = get_object_or_404(Group, pk=object_id)
+ f = TodoForm(request.POST)
+ f.save()
+ return HttpResponseRedirect('/group/'+object_id)
+
+def location(request, object_id):
+ """
+ This view helps you to get information about one of the places of the center
+ The information can be technical, about the programme, and about everything you
+ 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))
+ else:
+ return render_to_response('agenda/location_events.html', {'location': location })
+
+def attendance(request, object_id):
+ if request.user.is_authenticated():
+
+ event = get_object_or_404(Event, pk=object_id)
+ person = request.user.id()
+ attendance = request.POST['attendance']
+ try:
+ unapersona = Attendance.objects.get(event=object_id,person=person)
+ unapersona.attendance = request.POST['attendance']
+ attendance.save()
+ return render_to_response('agenda/one_event.html', {'event': event },context_instance=RequestContext(request))
+
+ except Attendance.DoesNotExist:
+ attendance = Attendance(event=event,person=person,attendance=1)
+ attendance.save()
+
+ return render_to_response('agenda/wanna_join.html', {'event': event },context_instance=RequestContext(request))
+ else:
+ return HttpResponseRedirect('django.contrib.auth.views.login')
+
+ # Always return an HttpResponseRedirect after successfully dealing
+ # with POST data. This prevents data from being posted twice if a
+ # user hits the Back button.
+
+def confirmation_pending(request):
+ object_id=request.user.id
+ 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')
+ pending = user.attendance.filter(attendance='NULL')
+ rejected = user.attendance.filter(attendance='0')
+ return render_to_response('agenda/user_events.html', {'user': user, 'attendance': attendance, 'confirmed': confirmed, 'pending': pending, 'rejected': rejected},context_instance=RequestContext(request))
+
+ else:
+ return HttpResponseRedirect('django.contrib.auth.views.login')
+
+def attend(request,object_id):
+ event = Event.calendar.get(pk=object_id)
+ return render_to_response('agenda/one_event.html', {'event': event},context_instance=RequestContext(request))
+
+
+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))
+
+