Beispiel #1
0
def Modify_Profile(request):
	Updated = False
	#PatientFormset = modelformset_factory(Patient,form = PatientProfileForm, exclude=("user",),extra = 0)

	if request.method == 'POST':
		user_form = UserForm(data=request.POST, prefix ='user',instance=request.user)
		patient_form = PatientProfileForm(data = request.POST, prefix = 'patient', instance =request.user.patient)

		#formset = PatientFormset(request.POST)
		if patient_form.is_valid():
			profile = patient_form.save(commit = False)
			profile.user = request.user
			profile.save()

			#entry = LogEntry(username=request.POST['username'], datetime=timezone.now(), description='user login')
			#entry.save()
			Updated = True
		else:
			print(user_form.errors)

			#print(user_form.errors, patient_form.errors)
	else:

		user_form = UserForm(instance = request.user)
		#formset = PatientFormset()
		patient_form = PatientProfileForm(instance = request.user.patient)



	return render(request,'update.html',{'user_form': user_form,'patient_form':patient_form , 'Updated':
								Updated})
Beispiel #2
0
def Register(request):
	registered = False

	if request.method == 'POST':
		user_form = UserForm(data=request.POST,prefix = 'user')
		patient_form = PatientProfileForm(data = request.POST,prefix = 'patient')


		if user_form.is_valid() and patient_form.is_valid():
			user = user_form.save()
			user.set_password(user.password)
			user.save()
			
			try:
				user.groups.add(Group.objects.get(name='Patient'))
			except Group.DoesNotExist:
				Group.objects.create(name='Patient')
				user.groups.add(Group.objects.get(name='Patient'))

			profile = patient_form.save(commit = False)
			profile.user = user
			profile.save()

			entry = LogEntry(username=user.username, datetime=timezone.now(), description='user registered')
			entry.save()
			registered = True
		else:
			print(user_form.errors, patient_form.errors)
	else:
		user_form = UserForm(prefix = 'user')
		patient_form = PatientProfileForm(prefix = 'patient')
		

	return render(request,'register.html',{'user_form': user_form,'patient_form':patient_form , 'registered':
								registered})