implementing personal info edit screen, talk list,
authorLincoln de Sousa <lincoln@minaslivre.org>
Tue, 1 Jul 2008 13:40:48 +0000 (10:40 -0300)
committerLincoln de Sousa <lincoln@minaslivre.org>
Tue, 1 Jul 2008 13:40:48 +0000 (10:40 -0300)
talk add, talk del and talk edit and making logout redirecto to /

eventos/forms.py [new file with mode: 0644]
eventos/templates/eventos/lecturer-details.html [new file with mode: 0644]
eventos/templates/eventos/talk-add.html [new file with mode: 0644]
eventos/templates/eventos/talk-details.html [new file with mode: 0644]
eventos/templates/eventos/talk-list.html [new file with mode: 0644]
eventos/urls.py
eventos/views.py
templates/base.html

diff --git a/eventos/forms.py b/eventos/forms.py
new file mode 100644 (file)
index 0000000..8e3980e
--- /dev/null
@@ -0,0 +1,17 @@
+# -*- 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.
diff --git a/eventos/templates/eventos/lecturer-details.html b/eventos/templates/eventos/lecturer-details.html
new file mode 100644 (file)
index 0000000..15c3610
--- /dev/null
@@ -0,0 +1,8 @@
+{% extends "base.html" %}
+
+{% block content %}
+<form id="lecturer-details" method="post" action="./">
+  {{ form.as_p }}
+  <input type="submit" value="Ok" />
+</form>
+{% endblock %}
diff --git a/eventos/templates/eventos/talk-add.html b/eventos/templates/eventos/talk-add.html
new file mode 100644 (file)
index 0000000..333adff
--- /dev/null
@@ -0,0 +1,8 @@
+{% extends "base.html" %}
+
+{% block content %}
+<form id="talk-add" method="post" action="./">
+  {{ form.as_p }}
+  <input type="submit" value="Ok" />
+</form>
+{% endblock %}
diff --git a/eventos/templates/eventos/talk-details.html b/eventos/templates/eventos/talk-details.html
new file mode 100644 (file)
index 0000000..093b991
--- /dev/null
@@ -0,0 +1,8 @@
+{% extends "base.html" %}
+
+{% block content %}
+<form id="talk-details" method="post" action="./">
+  {{ form.as_p }}
+  <input type="submit" value="Ok" />
+</form>
+{% endblock %}
diff --git a/eventos/templates/eventos/talk-list.html b/eventos/templates/eventos/talk-list.html
new file mode 100644 (file)
index 0000000..921e4b9
--- /dev/null
@@ -0,0 +1,26 @@
+{% extends "base.html" %}
+
+{% block content %}
+<h2>Trabalhos do palestrante {{ lecturer }}</h2>
+
+<table id="talks-list">
+  <thead>
+    <tr>
+      <th>Título</th>
+      <th>Tipo</th>
+      <th>Evento</th>
+    </tr>
+  </thead>
+  <tbody>
+    {% for t in talks %}
+    <tr>
+      <td><a href="/talks/{{ t.id }}/">{{ t.titulo }}</a></td>
+      <td>{{ t.tipo }}</td>
+      <td>{{ t.evento }}</td>
+      <td><a href="/talks/{{ t.id }}/delete/">Apagar</a></td>
+    </tr>
+    {% endfor %}
+  </tbody>
+</table>
+
+{% endblock %}
index ba07a72..35bb882 100644 (file)
@@ -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'),
 )
index ce68872..a5735cb 100644 (file)
 # 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('<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))
index 5e7dc13..4f285c7 100644 (file)
@@ -31,9 +31,9 @@
       {% if user.is_authenticated %}
 
       {% if user.palestrante_set.all %}
-      <li><a href="/editar-dados">Edite seus dados</a></li>
-      <li><a href="/enviar-trabalho">Enviar trabalho</a></li>
-      <li><a href="/trabalhos-cadastrados">Ver trabalhos cadastrados</a></li>
+      <li><a href="/lecturer/{{ user.palestrante_set.get.id }}/">Editar dados pessoais</a></li>
+      <li><a href="/talks/add/">Enviar trabalho</a></li>
+      <li><a href="/lecturer/{{ user.palestrante_set.get.id }}/talks/">Ver trabalhos cadastrados</a></li>
       {% endif %}
 
       {% if user.participante_set.all %}