Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *************************************************************************************
- Models.py
- *************************************************************************************
- class Patient_Profile(forms.Form):
- fname = forms.CharField(label = "First Name:")
- lname = forms.CharField(label = "Last Name:")
- username = forms.CharField()
- password = forms.CharField(widget = forms.PasswordInput)
- password2 = forms.CharField(widget = forms.PasswordInput)
- dob = forms.DateField(label = "DOB:");
- email = forms.EmailField(label = "Email:")
- insurance = forms.CharField(label = "Insurance Provider:")
- insuranceNum = forms.IntegerField(label = "Insurance Number:")
- # widgets= {
- # 'password' : forms.PasswordInput(),
- # 'password2' : forms.PasswordInput(),
- # }
- def clean(self):
- password1 = self.cleaned_data.get('password')
- password2 = self.cleaned_data.get('password2')
- if not password2:
- raise forms.ValidationError("You must confirm your password")
- if password1 != password2:
- raise forms.ValidationError("Your passwords do not match")
- return password2
- *************************************************************************************
- Views.py
- *************************************************************************************
- def Register(request):
- registered = False
- # if this is a POST request ie. something submitted from the browser
- if request.method == 'POST':
- #create a form insance and populate it with data from the request
- form = Patient_Profile(request.POST)
- #check wether its valid
- if form.is_valid():
- user = form.save()
- user.set_password(user.password)
- user.save()
- user.groups.add(Group.objects.get(name='Patient'))
- profile = patient_form.save(commit = False)
- profile.user = user
- profile.save()
- registered = True
- return HttpResponseRedirect('/login/')
- else:
- print(form.errors)
- #if a GET (or any other method) we'll create a blank form
- else:
- form = Patient_Profile()
- return render(request,'name.html',{'form':form})
- #return render_to_response('name.html',{'user_form': form,'registered':registered},RequestContext(request))
- *************************************************************************************
- name.html Form handling done by django
- *************************************************************************************
- <form action="/register/" method="post">
- {% csrf_token %}
- {{ form.non_field_errors }}
- {{ form.as_p }}
- <ul class = "errorlist">
- <li></li>
- </ul>
- <input type="submit" value="Submit" />
- </form>
- *************************************************************************************
- Alternate Version of name.html doc using manual form handling
- *************************************************************************************
- <!DOCTYPE html>
- <html>
- {% if registered %}
- <p> Registration successful! </p>
- <a href="/">Click here to go to login.</a>
- {% else %}
- {% csrf_token %}
- {{ form }}
- <!--First Name field-->
- <div class="fieldWrapper">
- {{form.fname.errors}}
- <p><label for="fname">First Name: </label>
- <input id="fname" type="text" name="fname" maxlength="100"></p>
- {{form.fname}}
- </div>
- <!--Last Name field-->
- <div class="fieldWrapper">
- {{form.lname.errors}}
- <p><label for="lname">Last Name: </label>
- <input id="lname" type="text" name="lname" maxlength="100"></p>
- {{form.lname}}
- </div>
- <!--Username field-->
- <div class="fieldWrapper">
- {{form.username.errors}}
- <p><label for="username">Username: </label>
- <input id="username" type="text" name="username" maxlength="100"></p>
- {{form.lname}}
- </div>
- <div class="fieldWrapper">
- {{form.password.errors}}
- <p><label for="password">Password: </label>
- <input type="password" name="password" maxlength="100"></p>
- {{form.password}}
- </div>
- <div class="fieldWrapper">
- {{form.password2.errors}}
- <p><label for="password2">Confirm Password: </label>
- <input type="password" name="password" maxlength="100"></p>
- {{form.password2}}
- </div>
- <!--dob field-->
- <div class="fieldWrapper">
- {{form.dob.errors}}
- <p><label for="dob">DOB: </label>
- <input type="date" name="dob" maxlength="100"></p>
- {{form.dob}}
- </div>
- <!--email field-->
- <div class="fieldWrapper">
- {{form.Email.errors}}
- <p><label for="email">Email: </label>
- <input type="email" name="email" maxlength="100"></p>
- {{form.Email}}
- </div>
- <!--insurance field-->
- <p><label for="Insurance">Insurance Provider: </label>
- <input type="text" name="provider" maxlength="100"></p>
- <!--Insurance number field-->
- <p><label for="Insurance Number">Insurance Number: </label>
- <input type="int" name="iNumber" maxlength="100"></p>
- <input type="submit" name="submit" value="Register" />
- </form>
- {% endif %}
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement