Advertisement
Guest User

Untitled

a guest
Mar 16th, 2015
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. *************************************************************************************
  2. Models.py
  3. *************************************************************************************
  4. class Patient_Profile(forms.Form):
  5. fname = forms.CharField(label = "First Name:")
  6. lname = forms.CharField(label = "Last Name:")
  7. username = forms.CharField()
  8. password = forms.CharField(widget = forms.PasswordInput)
  9. password2 = forms.CharField(widget = forms.PasswordInput)
  10. dob = forms.DateField(label = "DOB:");
  11. email = forms.EmailField(label = "Email:")
  12. insurance = forms.CharField(label = "Insurance Provider:")
  13. insuranceNum = forms.IntegerField(label = "Insurance Number:")
  14. # widgets= {
  15. # 'password' : forms.PasswordInput(),
  16. # 'password2' : forms.PasswordInput(),
  17. # }
  18. def clean(self):
  19. password1 = self.cleaned_data.get('password')
  20. password2 = self.cleaned_data.get('password2')
  21.  
  22. if not password2:
  23. raise forms.ValidationError("You must confirm your password")
  24. if password1 != password2:
  25. raise forms.ValidationError("Your passwords do not match")
  26. return password2
  27. *************************************************************************************
  28. Views.py
  29. *************************************************************************************
  30. def Register(request):
  31. registered = False
  32. # if this is a POST request ie. something submitted from the browser
  33. if request.method == 'POST':
  34. #create a form insance and populate it with data from the request
  35. form = Patient_Profile(request.POST)
  36. #check wether its valid
  37. if form.is_valid():
  38. user = form.save()
  39. user.set_password(user.password)
  40. user.save()
  41.  
  42. user.groups.add(Group.objects.get(name='Patient'))
  43.  
  44. profile = patient_form.save(commit = False)
  45. profile.user = user
  46. profile.save()
  47.  
  48. registered = True
  49.  
  50. return HttpResponseRedirect('/login/')
  51. else:
  52. print(form.errors)
  53. #if a GET (or any other method) we'll create a blank form
  54. else:
  55. form = Patient_Profile()
  56. return render(request,'name.html',{'form':form})
  57. #return render_to_response('name.html',{'user_form': form,'registered':registered},RequestContext(request))
  58. *************************************************************************************
  59. name.html Form handling done by django
  60. *************************************************************************************
  61. <form action="/register/" method="post">
  62. {% csrf_token %}
  63. {{ form.non_field_errors }}
  64. {{ form.as_p }}
  65. <ul class = "errorlist">
  66. <li></li>
  67. </ul>
  68. <input type="submit" value="Submit" />
  69. </form>
  70. *************************************************************************************
  71. Alternate Version of name.html doc using manual form handling
  72. *************************************************************************************
  73. <!DOCTYPE html>
  74. <html>
  75. {% if registered %}
  76. <p> Registration successful! </p>
  77. <a href="/">Click here to go to login.</a>
  78. {% else %}
  79. {% csrf_token %}
  80. {{ form }}
  81.  
  82. <!--First Name field-->
  83. <div class="fieldWrapper">
  84. {{form.fname.errors}}
  85. <p><label for="fname">First Name: </label>
  86. <input id="fname" type="text" name="fname" maxlength="100"></p>
  87. {{form.fname}}
  88. </div>
  89.  
  90. <!--Last Name field-->
  91. <div class="fieldWrapper">
  92. {{form.lname.errors}}
  93. <p><label for="lname">Last Name: </label>
  94. <input id="lname" type="text" name="lname" maxlength="100"></p>
  95. {{form.lname}}
  96. </div>
  97.  
  98. <!--Username field-->
  99. <div class="fieldWrapper">
  100. {{form.username.errors}}
  101. <p><label for="username">Username: </label>
  102. <input id="username" type="text" name="username" maxlength="100"></p>
  103. {{form.lname}}
  104. </div>
  105.  
  106. <div class="fieldWrapper">
  107. {{form.password.errors}}
  108. <p><label for="password">Password: </label>
  109. <input type="password" name="password" maxlength="100"></p>
  110. {{form.password}}
  111. </div>
  112.  
  113. <div class="fieldWrapper">
  114. {{form.password2.errors}}
  115. <p><label for="password2">Confirm Password: </label>
  116. <input type="password" name="password" maxlength="100"></p>
  117. {{form.password2}}
  118. </div>
  119.  
  120. <!--dob field-->
  121. <div class="fieldWrapper">
  122. {{form.dob.errors}}
  123. <p><label for="dob">DOB: </label>
  124. <input type="date" name="dob" maxlength="100"></p>
  125. {{form.dob}}
  126. </div>
  127.  
  128. <!--email field-->
  129. <div class="fieldWrapper">
  130. {{form.Email.errors}}
  131. <p><label for="email">Email: </label>
  132. <input type="email" name="email" maxlength="100"></p>
  133. {{form.Email}}
  134. </div>
  135.  
  136. <!--insurance field-->
  137.  
  138. <p><label for="Insurance">Insurance Provider: </label>
  139. <input type="text" name="provider" maxlength="100"></p>
  140.  
  141. <!--Insurance number field-->
  142.  
  143. <p><label for="Insurance Number">Insurance Number: </label>
  144. <input type="int" name="iNumber" maxlength="100"></p>
  145.  
  146. <input type="submit" name="submit" value="Register" />
  147. </form>
  148. {% endif %}
  149. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement