@enable_login_form
def cadastro(request):
+ c = {}
if request.POST:
# django's newforms lib requires a new instance of a form to be bounded
# with data, to be validated and used.
form = CadastroPalestrante(request.POST)
if form.is_valid():
cd = form.cleaned_data
+ badattr = form.errors
wrong = False
- # XXX: really ugly hack to use django validation machinary...
- badattr = form._BaseForm__errors
-
if not cd['telefone_comercial'] and \
not cd['telefone_residencial'] and \
not cd['telefone_celular']:
if not wrong:
group = Group.objects.get_or_create(name='palestrantes')[0]
+ user = User(username=cd['nome_usuario'], email=cd['email'])
+ user.set_password(cd['senha'])
+ user.save()
+ user.groups.add(group)
+
p = Palestrante()
- p.user = User(username=cd['nome_usuario'], email=cd['email'])
- p.user.set_password(cd['senha'])
- p.user.save()
- p.user.groups.add(group)
+ p.usuario = user
p.nome = cd['nome_completo']
p.email = cd['email']
login(request, got_user)
else:
form = CadastroPalestrante()
- return build_response(request, 'cadastro.html', {'form': form})
+ c.update({'form': form})
+ return build_response(request, 'cadastro.html', c)
@enable_login_form