Advertisement
Guest User

Untitled

a guest
Jul 30th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. from django import forms
  2. from django.contrib.auth.models import User
  3. from .models import *
  4.  
  5. from django.template.defaultfilters import slugify
  6.  
  7.  
  8. class UserForm(forms.ModelForm):
  9. password1 = forms.CharField(widget=forms.PasswordInput(attrs={
  10. 'class': 'form-control',
  11. 'required': 'true',
  12. 'placeholder': 'Password'}))
  13. password2 = forms.CharField(widget=forms.PasswordInput(attrs={
  14. 'class': 'form-control',
  15. 'required': 'true',
  16. 'placeholder': 'Re-type Password'}))
  17.  
  18. class Meta:
  19. model = User
  20. fields = [
  21. "username",
  22. "first_name",
  23. "last_name",
  24. "email",
  25. "password1",
  26. "password2",
  27. ]
  28.  
  29. def __init__(self, *args, **kwargs):
  30. super().__init__(*args, **kwargs)
  31. for field in iter(self.fields):
  32. self.fields[field].widget.attrs.update(
  33. {'class': 'form-control placeholder-no-fix'})
  34.  
  35. self.fields["first_name"].widget.attrs.update(
  36. {'placeholder': 'First Name', 'required': 'true'})
  37. self.fields["last_name"].widget.attrs.update(
  38. {'placeholder': 'Last Name', 'required': 'true'})
  39. self.fields["username"].widget.attrs.update(
  40. {'placeholder': 'Username', 'required': 'true'})
  41. self.fields["email"].widget.attrs.update(
  42. {'placeholder': 'E-Mail', 'required': 'true'})
  43.  
  44. def clean_password2(self):
  45. password1 = self.cleaned_data.get('password1')
  46. password2 = self.cleaned_data.get('password2')
  47.  
  48. if not password2:
  49. raise forms.ValidationError("You must confirm your password")
  50. if password1 != password2:
  51. raise forms.ValidationError("Your passwords do not match")
  52.  
  53. return password2
  54.  
  55.  
  56. class LoginForm(forms.Form):
  57. username = forms.CharField(widget=forms.TextInput(attrs={
  58. 'class': 'form-control form-control-solid placeholder-no-fix',
  59. 'required': 'true',
  60. 'placeholder': 'Username'}))
  61. password = forms.CharField(widget=forms.PasswordInput(attrs={
  62. 'class': 'form-control form-control-solid placeholder-no-fix',
  63. 'required': 'true',
  64. 'placeholder': 'Password', }))
  65.  
  66. class Meta:
  67. fields = [
  68. "username",
  69. "password",
  70. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement