예제 #1
0
def register(request):
    if request.user.is_authenticated():
        logout(request)

    registered = False

    if request.method == 'POST':
        userForm = UserForm(data=request.POST)
        profileForm = PatientProfileForm(data=request.POST)
        medicalForm = PatientMedicalForm(data=request.POST)
        log = Log()

        if userForm.is_valid() and profileForm.is_valid() and medicalForm.is_valid():
            print("valid")
            patient = userForm.save()

            patient.set_password(patient.password)
            patient.save()

            profile = profileForm.save(commit=False)
            medProfile = medicalForm.save(commit=False)

            profile.patient = patient

            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.height = medProfile.height
            profile.weight = medProfile.weight
            profile.insuranceNum = medProfile.insuranceNum
            profile.doctor = medProfile.doctor
            profile.hospital = medProfile.hospital
            profile.bloodType = medProfile.bloodType
            profile.emergencyContactFirst = medProfile.emergencyContactFirst
            profile.emergencyContactLast = medProfile.emergencyContactLast
            profile.emergencyContactEmail = medProfile.emergencyContactEmail
            profile.emergencyContactPhone = medProfile.emergencyContactPhone

            profile.save()

            registered = True

            log.user = profile.patient
            log.username = profile.patient.username
            log.time = timezone.now()
            log.type = 'Patient register'

            log.save()

        else:
            print(userForm.errors, profileForm.errors, medicalForm.errors)

    else:
        userForm = UserForm()
        profileForm = PatientProfileForm()
        medicalForm = PatientMedicalForm()

    return render(request, 'HealthNet/register.html',
                  {'userForm': userForm, 'profileForm': profileForm, 'medicalForm': medicalForm, 'registered': registered})
예제 #2
0
파일: views.py 프로젝트: ASRANetOrg/adWind
def index(request):

    site_settings = SiteSetting.objects.all().first()

    if request.method == 'POST':
        form = UserForm(request.POST)

        if form.is_valid():
            form.save(commit=True)
            return render(request, 'register/successPage.html', {'site_settings': site_settings})

        else:
            print form.errors
    else:
        form = UserForm()

    return render(request, 'register/register.html', {'form': form, 'site_settings': site_settings})
예제 #3
0
파일: views.py 프로젝트: ehg17/prelaunch
def add_user(request):
	context = RequestContext(request)

	if request.method == 'POST':
		form = UserForm(request.POST)

		if form.is_valid():
			instance = form.save(commit=True)

			return index(request, instance)

		else:
			print form.errors

	else:
		form = UserForm()

	return render_to_response('add_user.html', {'form':form}, context)
예제 #4
0
def modprofile(request):
    updated = False

    user = request.user

    # redirect if user isn't logged in
    if not user.is_authenticated():
        return redirect('/login')

    patient = PatientProfile.objects.get(patient=user)

    # process posted data
    if request.method == "POST":
        userForm = UserForm(data=request.POST, instance=user)
        profileForm = ModProfileForm(data=request.POST, instance=patient)

        if userForm.is_valid() and profileForm.is_valid():
            log = Log()
            log.user = request.user
            log.username = request.user.username
            log.time = timezone.now()
            log.type = 'Edit Profile'
            log.save()

            user = userForm.save()
            user.save()

            patient.user = user
            patient = profileForm.save()
            patient.save()

            updated = True

        else:
            print(userForm.errors, profileForm.errors)

    else:
        userForm = UserForm(instance=user)
        profileForm = ModProfileForm(instance=patient)

    context = {'userForm': userForm, 'profileForm': profileForm, 'updated': updated, 'user': user}
    return context
예제 #5
0
파일: views.py 프로젝트: sujay6995/user
def register(request):
    registered = False

    if request.method == "POST":
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()

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

            if 'pictures' in request.FILES:
                profile.picture = request.FILES['profile_pic']

            profile.save()
            registered = True
        else:
            print(user_form.errors, profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()

    return render(request, 'register/register.html', {
        'user_form': user_form,
        'profile_form': profile_form
    })
예제 #6
0
def register(request):
    registered = False
    if request.method == 'POST':

        # Name = (data=request.POST)
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            if 'profile_pic' in request.FILES:
                print('found it')
                profile.profile_pic = request.FILES['profile_pic']
            profile.save()
            registered = True
        else:
            print(user_form.errors, profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()
    return render(
        request, 'dapp/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
예제 #7
0
def register(request):
	#get the requests context
	context = RequestContext(request)

	# A boolean value for telling the template whether the registration was successful
	# Set to false initially. Code changes value to True when Registration succeds.
	registered = False

	#If its an HTTP POST, we are interested in processing the form data.
	if request.method == 'POST':
		# Attempt to grab information from the raw form information
		# NOte that we make use of both UserForm and UserProfileForm
		user_form = UserForm(data = request.POST)
		profile_form = UserProfileForm(data = request.POST)

		#If the two formas are valid.....
		if user_form.is_valid() and profile_form.is_valid():
			#Save the user's form to the database.
			user = user_form.save()

			#now we hash the password with the set_password method.
			# ONce hashed, we can update the user OBject
			user.set_password(user.password)
			user.save()

			#Now sort out the UserProfile instance since we need to set the user attribute ourselves,
			# We set commit=False. THis delays saving the model until we're ready to avoid integrity problems
			profile = profile_form.save(commit=False)
			profile.user = user

			#Did the user provide a profile picture?
			#If so, we need to get it from the input form and put it in the UserProfile model.
			if 'picture' in request.FILES:
				profile.picture = request.FILES['picture']

				#Now we save the UserProfile model instance.
				profile.save()

				# Update our variable to tell the template registration was successful.
				registered = True

			#invalid form or forms - mistakes or something else?
			#Print problems to the terminal. they will also be shown to the user.
			else:
				print user_form.errors, profile_form,errors

	# Not a HTTP POST, so we render our form using two ModelForm instances.
	# These forms will be blank, ready for user input.
	else:
		user_form = UserForm()
		profile_form =  UserProfileForm()

	#Render the template depending on the context.
	return render_to_response (
		'register/register.html',{'user_form': user_form, 'profile_form': profile_form, 
		'registered': registered})
예제 #8
0
def index(request):

    if request.method == 'POST':
        form = UserForm(request.POST)

        if form.is_valid():
            form.save(commit=True)
            return render(request, 'register/successPage.html')

        else:
            print form.errors
    else:
        form = UserForm()

    return render(request, 'register/register.html', {'form': form})
예제 #9
0
def index(request):

    site_settings = SiteSetting.objects.all().first()

    if request.method == 'POST':
        form = UserForm(request.POST)

        if form.is_valid():
            form.save(commit=True)
            return render(request, 'register/successPage.html',
                          {'site_settings': site_settings})

        else:
            print form.errors
    else:
        form = UserForm()

    return render(request, 'register/register.html', {
        'form': form,
        'site_settings': site_settings
    })
def create_manager(request):
    if request.method == 'POST':
        user_form = UserForm(request.POST)
        manager_form = ManagerForm(request.POST, request.FILES)
        print(manager_form.is_valid())
        print(request.POST)
        if user_form.is_valid() and manager_form.is_valid():
            user = user_form.save()
            manager = manager_form.save(commit=False)
            manager.user = user
            manager.save()
            return redirect('register-manager')
    else:
        user_form = UserForm()
        manager_form = ManagerForm()
    return render(request, 'register_manager.html', {
        'user_form': user_form,
        'manager_form': manager_form
    })
예제 #11
0
def register(request):

    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        if user_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()

            registered = True

        else:
            print(user_form.errors)
    else:
        user_form = UserForm()
    context = {'user_form': user_form, 'registered': registered}

    return render(request, 'register.html', context)
예제 #12
0
def register(request):
    # Like before, get the request's context.
    context = RequestContext(request)

    # A boolean value for telling the template whether the registration was successful.
    # Set to False initially. Code changes value to True when registration
    # succeeds.
    registered = False

    # If it's a HTTP POST, we're interested in processing form data.
    if request.method == 'POST':
        # Attempt to grab information from the raw form information.
        # Note that we make use of both UserForm and UserProfileForm.
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        # If the two forms are valid...
        if user_form.is_valid() and profile_form.is_valid():
            # Save the user's form data to the database.
            user = user_form.save()

            # Now we hash the password with the set_password method.
            # Once hashed, we can update the user object.
            user.set_password(user.password)
            user.save()

            # Now sort out the UserProfile instance.
            # Since we need to set the user attribute ourselves, we set commit=False.
            # This delays saving the model until we're ready to avoid integrity
            # problems.
            profile = profile_form.save(commit=False)
            profile.user = user

            # Did the user provide a profile picture?
            # If so, we need to get it from the input form and put it in the
            # UserProfile model.
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            # Now we save the UserProfile model instance.
            profile.save()

            # Update our variable to tell the template registration was
            # successful.
            registered = True

        # Invalid form or forms - mistakes or something else?
        # Print problems to the terminal.
        # They'll also be shown to the user.
        else:
            print (user_form.errors, profile_form.errors)

    # Not a HTTP POST, so we render our form using two ModelForm instances.
    # These forms will be blank, ready for user input.
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    # Render the template depending on the context.
    return render_to_response(
        'register.html',
        {'user_form': user_form, 'profile_form': profile_form,
         'registered': registered},
        context)