From e5d99c46f3370265fef9359617a336843f81472c Mon Sep 17 00:00:00 2001 From: Lincoln de Sousa Date: Tue, 1 Jul 2008 10:40:48 -0300 Subject: [PATCH] implementing personal info edit screen, talk list, talk add, talk del and talk edit and making logout redirecto to / --- eventos/forms.py | 17 ++++ .../templates/eventos/lecturer-details.html | 8 ++ eventos/templates/eventos/talk-add.html | 8 ++ eventos/templates/eventos/talk-details.html | 8 ++ eventos/templates/eventos/talk-list.html | 26 ++++++ eventos/urls.py | 5 ++ eventos/views.py | 81 ++++++++++++++++++- templates/base.html | 6 +- 8 files changed, 154 insertions(+), 5 deletions(-) create mode 100644 eventos/forms.py create mode 100644 eventos/templates/eventos/lecturer-details.html create mode 100644 eventos/templates/eventos/talk-add.html create mode 100644 eventos/templates/eventos/talk-details.html create mode 100644 eventos/templates/eventos/talk-list.html diff --git a/eventos/forms.py b/eventos/forms.py new file mode 100644 index 0000000..8e3980e --- /dev/null +++ b/eventos/forms.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2008 Lincoln de Sousa +# +# 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. diff --git a/eventos/templates/eventos/lecturer-details.html b/eventos/templates/eventos/lecturer-details.html new file mode 100644 index 0000000..15c3610 --- /dev/null +++ b/eventos/templates/eventos/lecturer-details.html @@ -0,0 +1,8 @@ +{% extends "base.html" %} + +{% block content %} +
+ {{ form.as_p }} + +
+{% endblock %} diff --git a/eventos/templates/eventos/talk-add.html b/eventos/templates/eventos/talk-add.html new file mode 100644 index 0000000..333adff --- /dev/null +++ b/eventos/templates/eventos/talk-add.html @@ -0,0 +1,8 @@ +{% extends "base.html" %} + +{% block content %} +
+ {{ form.as_p }} + +
+{% endblock %} diff --git a/eventos/templates/eventos/talk-details.html b/eventos/templates/eventos/talk-details.html new file mode 100644 index 0000000..093b991 --- /dev/null +++ b/eventos/templates/eventos/talk-details.html @@ -0,0 +1,8 @@ +{% extends "base.html" %} + +{% block content %} +
+ {{ form.as_p }} + +
+{% endblock %} diff --git a/eventos/templates/eventos/talk-list.html b/eventos/templates/eventos/talk-list.html new file mode 100644 index 0000000..921e4b9 --- /dev/null +++ b/eventos/templates/eventos/talk-list.html @@ -0,0 +1,26 @@ +{% extends "base.html" %} + +{% block content %} +

Trabalhos do palestrante {{ lecturer }}

+ + + + + + + + + + + {% for t in talks %} + + + + + + + {% endfor %} + +
TítuloTipoEvento
{{ t.titulo }}{{ t.tipo }}{{ t.evento }}Apagar
+ +{% endblock %} diff --git a/eventos/urls.py b/eventos/urls.py index ba07a72..35bb882 100644 --- a/eventos/urls.py +++ b/eventos/urls.py @@ -3,4 +3,9 @@ from django.conf.urls.defaults import * 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'), ) diff --git a/eventos/views.py b/eventos/views.py index ce68872..a5735cb 100644 --- a/eventos/views.py +++ b/eventos/views.py @@ -15,9 +15,13 @@ # 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 @@ -50,4 +54,77 @@ def logout(request): 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('

You are not ' + 'allowed to edit ' + 'this info.

') + + 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('

You are not ' + 'allowed to edit ' + 'this info.

') + 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)) diff --git a/templates/base.html b/templates/base.html index 5e7dc13..4f285c7 100644 --- a/templates/base.html +++ b/templates/base.html @@ -31,9 +31,9 @@ {% if user.is_authenticated %} {% if user.palestrante_set.all %} -
  • Edite seus dados
  • -
  • Enviar trabalho
  • -
  • Ver trabalhos cadastrados
  • +
  • Editar dados pessoais
  • +
  • Enviar trabalho
  • +
  • Ver trabalhos cadastrados
  • {% endif %} {% if user.participante_set.all %} -- 2.20.1