Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.http import HttpResponseRedirect
- from django.shortcuts import render_to_response
- from drinker.models import Drinker
- from django.template import RequestContext
- from drinker.forms import RegistrationForm
- def drinker_reg(request):
- if request.user.is_authenticated():
- return HttpResponseRedirect("/profile/")
- if request.method == 'POST':
- pass
- else:
- #''' user is not submitting the form, show them a blank registration form '''
- #form = RegistrationForm()
- #context={'form':form}
- return render_to_response('registration.html',{'form':RegistrationForm()} , context_instance=RequestContext(request))
- from django import forms
- from django.contrib.auth.models import User
- from django.forms import ModelForm
- from drinker.models import Drinker
- class RegistrationForm(ModelForm):
- username = forms.Charfield(label=(u'User Name'))
- email = forms.EmailField(label=(u'Email Address'))
- password = forms.CharField(label=(u'Password'), widget=forms.PasswordInput(render_value=False))
- password1 = forms.CharField(label=(u'Verify Password'), widget=forms.PasswordInput(render_value=False))
- class Meta:
- model=Drinker
- exclude=('user',)
- def clean_username(self):
- username=self.cleaned_data['username']
- try:
- User.objects.get(username=username)
- except User.DoesNotExist:
- return username
- raise forms.ValidationError("The Username is already taken, please try another.")
- def clean_password(self):
- password=self.cleaned_data['password']
- password1=self.cleaned_data['password1']
- if password != password1:
- raise forms.ValidationError("The Password did not match, please try again.")
- return password
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement