adding a way to a normal user subscribe comment on talks
authorLincoln de Sousa <lincoln@alfaiati.net>
Thu, 6 Nov 2008 19:13:32 +0000 (17:13 -0200)
committerLincoln de Sousa <lincoln@alfaiati.net>
Thu, 6 Nov 2008 19:13:32 +0000 (17:13 -0200)
eventos/templates/eventos/subscribe.html [new file with mode: 0644]
eventos/views.py

diff --git a/eventos/templates/eventos/subscribe.html b/eventos/templates/eventos/subscribe.html
new file mode 100644 (file)
index 0000000..640f90d
--- /dev/null
@@ -0,0 +1,15 @@
+{% extends "base.html" %}
+
+{% block content %}
+<h2>Inscrição</h2>
+
+Atualmente esse cadastro servirá apenas para você poder avaliar os
+trabalhos propostos, porém assim que as inscrições estiverem
+liberadas, os dados preenchidos aqui serão reaproveitados, ou seja,
+você não precisará se cadastrar novamente.
+
+<form id="subscribe" method="post" action="./">
+  {{ form.as_p }}
+  <input type="submit" value="Ok" />
+</form>
+{% endblock %}
index 1f626be..a282844 100644 (file)
@@ -21,6 +21,7 @@ from django.contrib.auth import authenticate, login as login_django, \
     logout as logout_django
 from django.contrib.auth.models import User, Group
 from django.forms import HiddenInput, ModelForm
+from django import forms
 from django.shortcuts import render_to_response, get_object_or_404
 from django.template import RequestContext, Context, loader
 from eventos.models import Palestrante, Trabalho, TipoTrabalho, Trilha, Evento, Improve
@@ -43,6 +44,30 @@ class ImproveForm(ModelForm):
     class Meta:
         model = Improve
 
+class SubscribeForm(forms.Form):
+    full_name = forms.CharField(label=u'Nome completo', max_length=255)
+    email = forms.EmailField()
+    username = forms.CharField(max_length=255)
+    password = forms.CharField(label=u'Senha',
+                               max_length=255,
+                               widget=forms.PasswordInput)
+    confirm_password = forms.CharField(label=u'Confirmar senha',
+                                       max_length=255,
+                                       widget=forms.PasswordInput)
+
+    def clean_username(self):
+        data = self.cleaned_data['username']
+        if User.objects.filter(username=data):
+            raise forms.ValidationError(u'O usuário "%s" já existe' % data)
+        return data
+
+    def clean_confirm_password(self):
+        passwd = self.cleaned_data['password']
+        conf_passwd = self.cleaned_data['confirm_password']
+        if passwd != conf_passwd:
+            raise forms.ValidationError(u'A confirmação difere da senha')
+        return conf_passwd
+
 def login(request):
     """This is a function that will be used as a front-end to the
     django's login system. It receives username and password fields
@@ -53,6 +78,7 @@ def login(request):
     """
     username = request.POST['username']
     password = request.POST['password']
+
     user = authenticate(username=username, password=password)
 
     if user is not None:
@@ -301,3 +327,24 @@ def talk_improve(request, tid):
     c = {'talk': talk, 'form': form, 'improve': improve, 'speaker': speaker}
     return render_to_response('eventos/talk_improve.html', Context(c),
                               context_instance=RequestContext(request))
+
+def subscribe(request):
+    """This view shows a form with name, login and password fields and
+    if it receives a post, it will get data from the above fields and
+    create an User (yes, the django User). I think this user will be
+    used as an attendee.
+
+    This function authenticates the new user.
+    """
+    form = SubscribeForm(request.POST or None)
+
+    if request.POST and form.is_valid():
+        new_user = User.objects.create_user(request.POST['username'],
+                                            request.POST['email'],
+                                            request.POST['password'])
+        login(request)
+        return HttpResponseRedirect('/')
+
+    context = {'form': form}
+    return render_to_response('eventos/subscribe.html', Context(context),
+                              context_instance=RequestContext(request))