From f7448e54dfe15923e0f23c8ef6fd91539bd94796 Mon Sep 17 00:00:00 2001 From: Lincoln de Sousa Date: Thu, 6 Nov 2008 17:13:32 -0200 Subject: [PATCH] adding a way to a normal user subscribe comment on talks --- eventos/templates/eventos/subscribe.html | 15 ++++++++ eventos/views.py | 47 ++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 eventos/templates/eventos/subscribe.html diff --git a/eventos/templates/eventos/subscribe.html b/eventos/templates/eventos/subscribe.html new file mode 100644 index 0000000..640f90d --- /dev/null +++ b/eventos/templates/eventos/subscribe.html @@ -0,0 +1,15 @@ +{% extends "base.html" %} + +{% block content %} +

Inscrição

+ +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.as_p }} + +
+{% endblock %} diff --git a/eventos/views.py b/eventos/views.py index 1f626be..a282844 100644 --- a/eventos/views.py +++ b/eventos/views.py @@ -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)) -- 2.20.1