Advertisement
Guest User

Untitled

a guest
Mar 1st, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. from django.http import HttpResponseRedirect
  2. from django.shortcuts import render_to_response
  3. from drinker.models import Drinker
  4. from django.template import RequestContext
  5. from drinker.forms import RegistrationForm
  6.  
  7. def drinker_reg(request):
  8. if request.user.is_authenticated():
  9. return HttpResponseRedirect("/profile/")
  10. if request.method == 'POST':
  11. pass
  12. else:
  13. #''' user is not submitting the form, show them a blank registration form '''
  14.  
  15. #form = RegistrationForm()
  16. #context={'form':form}
  17. return render_to_response('registration.html',{'form':RegistrationForm()} , context_instance=RequestContext(request))
  18.  
  19. from django import forms
  20. from django.contrib.auth.models import User
  21. from django.forms import ModelForm
  22. from drinker.models import Drinker
  23.  
  24. class RegistrationForm(ModelForm):
  25. username = forms.Charfield(label=(u'User Name'))
  26. email = forms.EmailField(label=(u'Email Address'))
  27. password = forms.CharField(label=(u'Password'), widget=forms.PasswordInput(render_value=False))
  28. password1 = forms.CharField(label=(u'Verify Password'), widget=forms.PasswordInput(render_value=False))
  29.  
  30. class Meta:
  31. model=Drinker
  32. exclude=('user',)
  33.  
  34. def clean_username(self):
  35. username=self.cleaned_data['username']
  36. try:
  37. User.objects.get(username=username)
  38. except User.DoesNotExist:
  39. return username
  40. raise forms.ValidationError("The Username is already taken, please try another.")
  41. def clean_password(self):
  42. password=self.cleaned_data['password']
  43. password1=self.cleaned_data['password1']
  44. if password != password1:
  45. raise forms.ValidationError("The Password did not match, please try again.")
  46. return password
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement