--- /dev/null
+# -*- coding: utf-8 -*-
+# Copyright (C) 2008 Lincoln de Sousa <lincoln@minaslivre.org>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with this program; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
urlpatterns = patterns('',
(r'^login/', 'eventos.views.login'),
(r'^logout/', 'eventos.views.logout'),
+ (r'^lecturer/(\d+)/$', 'eventos.views.lecturer_details'),
+ (r'^lecturer/(\d+)/talks/$', 'eventos.views.lecturer_talks'),
+ (r'^talks/(\d+)/$', 'eventos.views.talk_details'),
+ (r'^talks/(\d+)/delete/$', 'eventos.views.talk_delete'),
+ (r'^talks/add/$', 'eventos.views.talk_add'),
)
# License along with this program; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
-from django.http import HttpResponseRedirect
+from django.http import HttpResponseRedirect, HttpResponseForbidden
from django.contrib import auth
from django.contrib.auth.forms import AuthenticationForm
+from django.newforms import form_for_instance, form_for_model
+from django.shortcuts import render_to_response, get_object_or_404
+from django.template import RequestContext, Context, loader
+from eventos.models import Palestrante, Trabalho
def login(request):
"""This is a function that will be used as a front-end to the
be mapped to an url and simply called without any parameter.
"""
auth.logout(request)
- return HttpResponseRedirect('/login')
+ return HttpResponseRedirect('/')
+
+def lecturer_details(request, lid):
+ """Shows a simple form containing all editable fields of a
+ lecturer and gives the lecturer the possibility to save them =)
+ """
+ entity = request.user.palestrante_set.get()
+ # avoiding problems if some other user tries to edit the lecturer
+ # info.
+ if entity.id != int(lid):
+ return HttpResponseForbidden('<h2>You are not '
+ 'allowed to edit '
+ 'this info.<h2>')
+
+ FormKlass = form_for_instance(entity)
+ del FormKlass.base_fields['usuario']
+
+ form = FormKlass(request.POST or None)
+ if request.POST and form.is_valid():
+ form.save()
+
+ c = {'form': form}
+ return render_to_response('eventos/lecturer-details.html', Context(c),
+ context_instance=RequestContext(request))
+
+def lecturer_talks(request, lid):
+ """Lists all talks of a lecturer (based on lecturer id -- lid
+ parameter).
+ """
+ lecturer = get_object_or_404(Palestrante, pk=lid)
+ talks = Trabalho.objects.filter(palestrante=lecturer)
+ c = {'lecturer': lecturer, 'talks': talks}
+ return render_to_response('eventos/talk-list.html', Context(c),
+ context_instance=RequestContext(request))
+
+def talk_details(request, tid):
+ """Shows a form to edit a talk
+ """
+ entity = get_object_or_404(Trabalho, pk=tid)
+ FormKlass = form_for_instance(entity)
+ form = FormKlass(request.POST or None)
+ if request.POST and form.is_valid():
+ form.save()
+
+ c = {'form': form}
+ return render_to_response('eventos/talk-details.html', Context(c),
+ context_instance=RequestContext(request))
+
+def talk_delete(request, tid):
+ """Drops a talk but only if the logged in user is its owner.
+ """
+ entity = get_object_or_404(Trabalho, pk=tid)
+ palestrante = request.user.palestrante_set.get()
+ owner = Trabalho.objects.filter(pk=tid, palestrante=palestrante)
+ if not owner:
+ return HttpResponseForbidden('<h2>You are not '
+ 'allowed to edit '
+ 'this info.<h2>')
+ entity.delete()
+ return HttpResponseRedirect('/lecturer/%d/talks/' % palestrante.id)
+
+def talk_add(request):
+ """Shows a form to the lecturer send a talk
+ """
+ palestrante = request.user.palestrante_set.get()
+ FormKlass = form_for_model(Trabalho)
+ form = FormKlass(request.POST or None)
+ if request.POST and form.is_valid():
+ form.save()
+ return HttpResponseRedirect('/lecturer/%d/talks/' % palestrante.id)
+
+ c = {'form': form}
+ return render_to_response('eventos/talk-add.html', Context(c),
+ context_instance=RequestContext(request))