Beispiel #1
0
    def post(self, request, *args, **kwargs):
        user = User.objects.get(username=request.user.username)
        userform = UserForm(request.POST, instance=user)
        profileform = ProfileForm(request.POST, instance=user.profile)

        if request.POST.get("email") != user.email:
            user.profile.isVerified = False
            user.profile.save()

        if not (userform.is_valid() and profileform.is_valid()):
            kwargs["userform"] = userform
            kwargs["profileform"] = profileform
            return super(CProfile, self).post(request, *args, **kwargs)
        if userform.cleaned_data.get("email") != user.email:
            user.profile.isVerified = False
            user.profile.save()

        profileform.save()
        userform.save()
        password = userform.cleaned_data.get("password")
        if password:
            user.set_password(password)
            user.save()
            log = authenticate(username=user.username, password=password)
            login(request, log)
        messages.success(request, "會員資料修改成功")

        return redirect(reverse("account:profile"))
Beispiel #2
0
    def post(self, request, *args, **kwargs):
        user = User.objects.get(username=request.user.username)
        userform = UserForm(request.POST, instance=user)
        profileform = ProfileForm(request.POST, instance=user.profile)

        if request.POST.get('email')!=user.email:
            user.profile.isVerified=False
            user.profile.save()

        if not (userform.is_valid() and profileform.is_valid()):
            kwargs['userform'] = userform
            kwargs['profileform'] = profileform
            return super(CProfile, self).post(request, *args, **kwargs)
        if userform.cleaned_data.get('email')!=user.email:
            user.profile.isVerified=False
            user.profile.save()
        
        profileform.save()
        userform.save()
        password = userform.cleaned_data.get('password')
        if password:
            user.set_password(password)
            user.save()
            log = authenticate(username=user.username, password=password)
            login(request, log)
        messages.success(request, '會員資料修改成功')
        
        return redirect(reverse('account:profile'))
def edit_profile(request):
    if request.method == 'POST':
        form = ProfileForm(request.POST, request.FILES, instance=request.user)
        if form.is_valid():
            form.save()
    form = ProfileForm(instance=request.user)
    return render(request, 'pages/edit-profile.html', context={
        "form": form
    })
Beispiel #4
0
    def upload_avatar(self):
        if self.method == 'POST':
            form = ProfileForm(self.POST, self.FILES)

            if form.is_valid():
                form.save()
                return redirect('/success')
        else:
            form = ProfileForm()
        return render(self, 'account/profile.html', {'form': form})
Beispiel #5
0
def profileUpdate(request, userID):
    userProfile = get_object_or_404(UserProfile, id=userID)
    template = 'account/profileUpdate.html'
    if request.method=='GET':
        form = ProfileForm(instance=userProfile)
        return render(request, template, {'form':form, 'userProfile':userProfile})
    # POST
    form = ProfileForm(request.POST, instance=userProfile)
    if not form.is_valid():
        return render(request, template, {'form':form, 'userProfile':userProfile})
    form.save()
    return redirect('account:account', userID=userID)
Beispiel #6
0
def edit_profile(request):
    """Edit your profile"""
    form = ProfileForm(request.POST or None, user=request.user)

    if request.method == 'POST' and form.is_valid():
        form.save()
        return redirect('user-home')

    context = {
        'form': form,
    }
    return render(request, 'account/edit_profile.html', context)
Beispiel #7
0
    def post(self, request):
        user = UpdateUserForm(request.POST, instance=request.user)
        profile = ProfileForm(request.POST, request.FILES, instance=request.user.profile)

        if user.is_valid() and profile.is_valid():
            user.save()
            profile.save()
            messages.success(request, 'Account details updated...')
            return redirect('staff:profile')

        return render(request, self.template_name, context={"userForm": self.user, "profileForm": self.profile})
        
def user_profile(request):
    profile = Profile.objects.get(user=request.user)

    form = ProfileForm(instance=profile)
    if request.method == 'POST':
        form = ProfileForm(request.POST, instance=profile)
        if form.is_valid():
            form.save()
            messages.success(request, "Data updated successfully")
            form = ProfileForm(instance=profile)
    context = {'form': form}
    return render(request, 'account/change_profile.html', context)
Beispiel #9
0
def new_view(request):
    try:
        request.user.userprofile
        return redirect(request.GET.get("next") or reverse("account:home"))
    except ObjectDoesNotExist:
        form = ProfileForm({"email": request.user.email})
        if request.method == 'POST':
            form = ProfileForm(request.POST)
            if form.is_valid():
                form.save(request.user)
                _next = request.GET.get("next", '').strip()
                return redirect(_next or reverse("account:home"))

        return render_to_response('account/new.html', locals(), context_instance=RequestContext(request))
Beispiel #10
0
def account(request):
    name = "Congrat"
    form = ProfileForm(request.POST or None)
    if request.method == 'POST' and form.is_valid():
        print(request.POST)
        print(form.cleaned_data)
        data=form.cleaned_data
        print(data['name'])
        new_form = form.save(commit=False)
        new_form.set_password(
            form.cleaned_data['password'])
        new_form=form.save(

        )
    return render(request, 'base/base.html', locals())
Beispiel #11
0
def signup(request):
    if request.method == "POST":
        form = UsercreatinForm(request.POST)
        pro_form = ProfileForm(request.POST)
        if form.is_valid() and pro_form.is_valid():
            user = form.save()
            profile = pro_form.save(commit=False)
            profile.user = user
            pro_form.save()
            auth_login(request, user)
            return redirect('question:index')
    else:
        form = UserCreationForm()
        pro_form = ProfileForm()
    return render(request, 'account/signup.html', {'form':form, 'pro_form':pro_form})
Beispiel #12
0
    def post(self, request):
        self.class_taken = request.user.profile.timetable
        profile_form = ProfileForm(instance=request.user.profile)
        setting_form = PasswordChangeForm(request.user)
        tags = request.user.profile.interest_tag.all()

        if 'profile' in request.POST:
            profile_form = ProfileForm(request.POST, request.FILES, instance=request.user.profile)
            if profile_form.is_valid():
                profile_form.save()
                return redirect("index")
            else:

                return render(request, self.template_name, {"profile_form": profile_form, "setting_form": setting_form,
                                                            'classes_number': self.classes_number,
                                                            'class_taken': self.class_taken, 'tags': tags})

        elif 'setting' in request.POST:
            setting_form = PasswordChangeForm(user=request.user, data=request.POST)
            if setting_form.is_valid():
                setting_form.save()
                update_session_auth_hash(request, setting_form.user)
                return redirect("index")
            else:
                return render(request, self.template_name, {"profile_form": profile_form, "setting_form": setting_form,
                                                            'classes_number': self.classes_number,
                                                            'class_taken': self.class_taken, 'tags': tags})

        elif 'time-table' in request.POST:
            table = request.POST['table']
            profile = request.user.profile
            profile.timetable = table
            profile.save()
            self.class_taken = table
            return render(request, self.template_name, {"profile_form": profile_form, "setting_form": setting_form,
                                                        'classes_number': self.classes_number,
                                                        'class_taken': self.class_taken, 'tags': tags})

        elif 'interest' in request.POST:
            tags = request.POST.getlist('tags')
            print tags
            for tag in tags:
                t, created = Tag.objects.get_or_create(name=tag.lower())

                request.user.profile.interest_tag.add(t)
            return render(request, self.template_name, {"profile_form": profile_form, "setting_form": setting_form,
                                                        'classes_number': self.classes_number,
                                                        'class_taken': self.class_taken, 'tags': tags})
Beispiel #13
0
def register_view(request):
    reg_form = UserRegistrationForm(request.POST)
    profile_form = ProfileForm(request.POST)
    login_form = LoginForm()

    if request.method == 'POST':
        if reg_form.is_valid() and profile_form.is_valid():
            new_user = reg_form.save(commit=False)
            new_user_profile = profile_form.save(commit=False)
            new_user.set_password(reg_form.cleaned_data['password'])
            new_user.is_active = True
            new_user.save()
            new_user_profile.user = new_user
            new_user_profile.save()
            messages.success(request, 'Account created successfully!')

            return redirect('index')

        else:
            messages.error(request, f'{reg_form.errors}')
            return redirect('index')

    else:
        messages.error(request, 'Error registering, please try again.')
        return redirect('index')
Beispiel #14
0
def update_profile(request, update_sucess_url="home", template="account/update_profile.html"):
    form = ProfileForm(instance=request.user.get_profile() ,data=request.POST or None)
    if form.is_valid():
        profile_form=form.save(commit=False)
        profile_form.user=request.user
        profile_form.save()
        return redirect(update_sucess_url)

    return render(request, template, {'form':form})
Beispiel #15
0
def edit(request):
    if request.method == 'POST':
        user_form = UserEditForm(instance=request.user, data=request.POST)
        profile_form = ProfileForm(instance=request.user.profile,
                                   data=request.POST,
                                   files=request.FILES)
        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()
            messages.success(request, 'Profile updated successfully')
        else:
            messages.error(request, 'Error updating your profile')
    else:
        user_form = UserEditForm(instance=request.user)
        profile_form = ProfileForm(instance=request.user.profile)
    return render(request, 'account/edit.html', {
        'user_form': user_form,
        'profile_form': profile_form
    })
	def post(self, request):
		user = request.user
		profile = Profile.objects.get(account=user)
		form = ProfileForm(request.POST)
		if form.is_valid():
			profile = form.save(commit=False)
			profile.account = request.user
			profile.save()
			form = ProfileForm()
			return redirect('index')
		return render(request, self.template_name, {'form':form, 'profile':profile})
Beispiel #17
0
def update_profile(request):
    if request.method == 'POST':
        user_form = UserForm(request.POST, instance=request.user)
        profile_form = ProfileForm(request.POST, instance=request.user.profile)
        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()
            messages.success(request,
                             _('Your profile was successfully updated!'))
            return redirect('dashboard')

        else:
            messages.error(request, _('Please correct the error below.'))
    else:
        user_form = UserForm(instance=request.user)
        profile_form = ProfileForm(instance=request.user.profile)
    return render(request, 'accounts/profile.html', {
        'user_form': user_form,
        'profile_form': profile_form
    })
def user_profile(request):
    avatar_form = PhotoProfileForm(instance=request.user.profile)
    if request.method == 'POST':
        user_form = UserEditForm(instance=request.user, data=request.POST)
        profile_form = ProfileForm(instance=request.user.profile,
                                   data=request.POST)
        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()
            messages.success(request, 'Профиль успешно обновлен')
        else:
            messages.error(request, 'Что-то пошло не так')
    else:
        user_form = UserEditForm(instance=request.user)
        profile_form = ProfileForm(instance=request.user.profile)
    return render(
        request, 'account/profile.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'avatar_form': avatar_form,
        })
Beispiel #19
0
def profile(request, template_name="profile.html"):
    if request.user.is_authenticated():
        if request.method == "POST":
            if request.POST["action"] == "update":
                profile_form = ProfileForm(request.POST, instance=request.user.get_profile())
                if profile_form.is_valid():
									email = profile_form.cleaned_data["email"]
									firstname = profile_form.cleaned_data["firstname"]
									lastname = profile_form.cleaned_data["lastname"]
									if profile.email != email or profile.firstname != firstname or profile.lastname != lastname:
										profile.email = request.user.email = email
										profile.firstname = request.user.firstname = firstname
										profile.lastname = request.user.lastname = lastname
										request.user.save()
									profile_form.save()
        else:
            profile_form = ProfileForm(instance=request.user.get_profile())
    else:
        profile_form = None

    return render_to_response(template_name, {
        "form": profile_form,
    }, context_instance=RequestContext(request))
Beispiel #20
0
def profile(request):
    if request.method == 'POST':
        form = ProfileForm(request.POST, request.FILES, instance=request.user)
        if form.is_valid():
            user = form.save()
            login(request, user)
            messages.success(request, 'ویرایش پروفایل با موفقیت انجام شد')
            form = ProfileForm(instance=request.user)
    else:
        form = ProfileForm(instance=request.user)

    return render(request, 'basic_form.html', {
        'form': form,
        'title': 'ویرایش پروفایل'
    })
Beispiel #21
0
def update_profile(request):
    # get user profile
    profile = request.user.get_profile()

    if request.method == 'POST':
        profile_form = ProfileForm(request.POST, 
                                   request.FILES, 
                                   instance=profile)

        user_form = UserForm(request.POST, 
                             instance=request.user)
        if profile_form.is_valid() and user_form.is_valid():
            profile_form.save()
            user_form.save()
            messages.success(request, _("Profile updated succesfully."))
            return redirect('update_profile')
    else:
        profile_form = ProfileForm(instance=profile)
        user_form = UserForm(instance=request.user)
       
    return render(request, 'account/profile.html', {
        'profile_form': profile_form,
        'user_form': user_form
    })
Beispiel #22
0
def edit_profile(request):
    my_profile = Profile.objects.get(user=request.user)
    if request.method == 'POST':
        profile_form = ProfileForm(request.POST,
                                   request.FILES,
                                   instance=my_profile)
        if profile_form.is_valid():
            profile = profile_form.save(commit=False)
            profile.avatar = profile_form.cleaned_data['avatar']
            profile.save()
            make_thumbnail(profile.avatar.path)
            return HttpResponseRedirect('/accounts/profile/')
    else:
        profile_form = ProfileForm(instance=my_profile)
    return render(request, 'account/edit_profile.html', {
        'profile_form': profile_form,
    })
Beispiel #23
0
def signup(request):
    if request.user.is_authenticated:
        return redirect('question:list')
    else:
        if request.method == "POST": # 사용자가 로그인을 요청했으면?
            form = UserCreationForm(request.POST)
            pro_form = ProfileForm(request.POST)
            if form.is_valid() and pro_form.is_valid():
                user = form.save()
                profile = pro_form.save(commit=False)
                profile.user = user
                profile.save()
                auth_login(request, user)
                return redirect('question:list')
        else: # 로그인을 위한 폼을 요청했으면?
            form = UserCreationForm()
            pro_form = ProfileForm()
        return render(request,"account/signup.html",{'form':form,"pro_form":pro_form})
Beispiel #24
0
def register_new_doctor(request):

    # # this view provides an admin with the ability to register other users
    if request.user.is_superuser:

        title = "Register Doctor"
        form = UserRegisterForm(request.POST or None)
        profile_form = ProfileForm(request.POST or None)

        if form.is_valid() and profile_form.is_valid():
            user = form.save(commit=False)
            password = form.cleaned_data.get('password')
            user.set_password(password)
            user.save()

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

            doctor = Doctor()
            doctor.profile = profile
            doctor.save()

            messages.success(request, 'Form submission successful')

            log = Log(username="******",
                      action=" registered " + doctor.profile.user.username +
                      " as a doctor ")
            log.save()

            msg = "Doctor %s was successfully created" % doctor

            return landing(request, msg)

        context = {
            "form": form,
            "title": title,
            "prof": profile_form,
        }
        return render(request, 'administration/create_user.html', context)
    else:
        return redirect('/')
Beispiel #25
0
    def post(self, request, *args, **kwargs):
        userForm = SignupForm(request.POST)
        profileform = ProfileForm(request.POST)
        CForm = CaptchaForm(request.POST)
        if not (CForm.is_valid() and userForm.is_valid() and profileform.is_valid()):
            kwargs["userForm"] = userForm
            kwargs["profileform"] = profileform
            kwargs["CForm"] = CForm
            return super(CSignUp, self).get(request, *args, **kwargs)

        user = userForm.save()
        password = user.password
        user.set_password(password)
        user.save()
        userProfile = profileform.save(commit=False)
        userProfile.user = user
        userProfile.username = user.username
        userProfile.ip = get_client_ip(request)
        userProfile.save()
        log = authenticate(username=user.username, password=password)
        login(request, log)
        messages.add_message(request, 50, request.user.username + "會員 謝謝您的註冊", extra_tags="註冊成功")
        # messages.success(request, '歡迎註冊')
        return redirect(reverse("main:main"))
Beispiel #26
0
 def post(self, request, *args, **kwargs):
     userForm = SignupForm(request.POST)
     profileform = ProfileForm(request.POST)
     CForm = CaptchaForm(request.POST)
     if not (CForm.is_valid() and userForm.is_valid() and profileform.is_valid()):
         kwargs['userForm'] = userForm
         kwargs['profileform'] = profileform
         kwargs['CForm'] = CForm
         return super(CSignUp, self).get(request, *args, **kwargs)
     
     user = userForm.save()
     password = user.password
     user.set_password(password)
     user.save()
     userProfile = profileform.save(commit=False)
     userProfile.user = user
     userProfile.username = user.username
     userProfile.ip = get_client_ip(request)
     userProfile.save()
     log = authenticate(username=user.username, password=password)
     login(request, log)
     messages.add_message(request, 50, request.user.username+'會員 謝謝您的註冊', extra_tags='註冊成功')
     #messages.success(request, '歡迎註冊')
     return redirect(reverse('main:main'))
Beispiel #27
0
def edit_info(request):
    if request.user.is_authenticated:
        # gets the user id based on the request
        user_id = request.user.id
        # gets the user instance based on the id
        user_instance = User.objects.get(id=user_id)

        isPatient = (Patient.objects.filter(
            profile__user_id=user_id).count() == 1)
        isDoctor = (Doctor.objects.filter(
            profile__user_id=user_id).count() == 1)
        isNurse = (Nurse.objects.filter(profile__user_id=user_id).count() == 1)

        if isPatient:

            # if there is data that exists on the user, the forms will be prefilled
            user_init_data = {
                'first_name': user_instance.first_name,
                'last_name': user_instance.last_name,
                'email': user_instance.email,
                'username': user_instance.username
            }

            # create a new user form that is tied to the current instance and is prefilled with current data
            user_form = UserForm(instance=user_instance,
                                 initial=user_init_data)

            # get the profile instance based on the id
            profile_instance = Profile.objects.get(user_id=user_id)

            # if there is data that exists on the profile, the forms will be prefilled
            profile_init_data = {
                'streetAddress': profile_instance.streetAddress,
                'town': profile_instance.town,
                'zipCode': profile_instance.zipCode,
                'state': profile_instance.state,
                'phoneNumber': profile_instance.phoneNumber,
                'hospital_assignment': profile_instance.hospital_assignment
            }

            profile_form = ProfileForm(instance=profile_instance,
                                       initial=profile_init_data)

            # get the patient instance based on the id
            patient_instance = Patient.objects.get(profile__user_id=user_id)
            # if there is data that exists on the patient, the forms will be prefilled
            patient_init_data = {
                'height': patient_instance.height,
                'weight': patient_instance.weight,
                'age': patient_instance.age,
                'hospital_preferred': patient_instance.hospital_preferred
            }

            # create a new patient form that is tied to the current instance and is prefilled with current data

            # if the user is submitting a form, save it if it is valid
            if request.POST:
                patient_form = PatientForm(request.POST,
                                           instance=patient_instance)
                profile_form = ProfileForm(request.POST,
                                           instance=profile_instance)
                user_form = UserForm(request.POST, instance=user_instance)

                if user_form.is_valid() and patient_form.is_valid(
                ) and profile_form.is_valid():
                    user_form.save()
                    patient_form.save()
                    profile_form.save()

                    log = Log(username=patient_instance.profile.user.username,
                              action=" made profile changes ")
                    log.save()

                    return redirect('/profile')
                else:
                    print("error")
            else:
                patient_form = PatientForm(instance=patient_instance,
                                           initial=patient_init_data)
                profile_form = ProfileForm(instance=profile_instance,
                                           initial=profile_init_data)
                user_form = UserForm(instance=user_instance,
                                     initial=user_init_data)

            appointments = Appointment.objects.filter(patient=patient_instance)

            return render(
                request, "account/useredit.html", {
                    "user": request.user,
                    "profile": profile_instance,
                    "patient": patient_instance,
                    "userform": user_form,
                    "patientform": patient_form,
                    "profileform": profile_form,
                    "usertype": "Patient",
                    "appointments": appointments
                })

        elif isDoctor:

            # if there is data that exists on the user, the forms will be prefilled
            user_init_data = {
                'first_name': user_instance.first_name,
                'last_name': user_instance.last_name,
                'email': user_instance.email,
                'username': user_instance.username
            }

            # create a new user form that is tied to the current instance and is prefilled with current data
            user_form = UserForm(instance=user_instance,
                                 initial=user_init_data)

            # get the profile instance based on the id
            profile_instance = Profile.objects.get(user_id=user_id)

            # if there is data that exists on the profile, the forms will be prefilled
            profile_init_data = {
                'streetAddress': profile_instance.streetAddress,
                'town': profile_instance.town,
                'zipCode': profile_instance.zipCode,
                'state': profile_instance.state,
                'phoneNumber': profile_instance.phoneNumber,
                'hospital_assignment': profile_instance.hospital_assignment
            }

            profile_form = ProfileForm(instance=profile_instance,
                                       initial=profile_init_data)

            # get the doctor instance based on the id
            doctor_instance = Doctor.objects.get(profile__user_id=user_id)
            # if there is data that exists on the patient, the forms will be prefilled

            doctor_init_data = {'type': doctor_instance.type}

            # create a new patient form that is tied to the current instance and is prefilled with current data
            doctor_form = DoctorForm(instance=doctor_instance,
                                     initial=doctor_init_data)

            # if the user is submitting a form, save it if it is valid
            if request.POST:
                doctor_form = DoctorForm(request.POST,
                                         instance=doctor_instance,
                                         initial=doctor_init_data)
                profile_form = ProfileForm(request.POST,
                                           instance=profile_instance,
                                           initial=profile_init_data)
                user_form = UserForm(request.POST,
                                     instance=user_instance,
                                     initial=user_init_data)

                if user_form.is_valid() and profile_form.is_valid():
                    user_form.save()
                    doctor_form.save()
                    profile_form.save()

                    log = Log(username=doctor_instance.profile.user.username,
                              action=" made profile changes ")
                    log.save()

                    return redirect('/profile')
                else:
                    print("error")

            appointments = Appointment.objects.filter(
                doctor=doctor_instance).order_by('-date').reverse()

            return render(
                request, "account/useredit.html", {
                    "user": request.user,
                    "profile": profile_instance,
                    "doctor": doctor_instance,
                    "userform": user_form,
                    "doctorform": doctor_form,
                    "profileform": profile_form,
                    "usertype": "Doctor",
                    "appointments": appointments
                })

        elif isNurse:

            # if there is data that exists on the user, the forms will be prefilled
            user_init_data = {
                'first_name': user_instance.first_name,
                'last_name': user_instance.last_name,
                'email': user_instance.email,
                'username': user_instance.username
            }

            # create a new user form that is tied to the current instance and is prefilled with current data
            user_form = UserForm(instance=user_instance,
                                 initial=user_init_data)

            # get the profile instance based on the id
            profile_instance = Profile.objects.get(user_id=user_id)

            # if there is data that exists on the profile, the forms will be prefilled
            profile_init_data = {
                'streetAddress': profile_instance.streetAddress,
                'town': profile_instance.town,
                'zipCode': profile_instance.zipCode,
                'state': profile_instance.state,
                'phoneNumber': profile_instance.phoneNumber
            }

            profile_form = ProfileForm(instance=profile_instance,
                                       initial=profile_init_data)

            # get the nurse instance based on the id
            nurse_instance = Nurse.objects.get(profile__user_id=user_id)
            # if there is data that exists on the patient, the forms will be prefilled

            nurse_init_data = {'type': nurse_instance.type}

            # create a new nurse form that is tied to the current instance and is prefilled with current data
            nurse_form = NurseForm(instance=nurse_instance,
                                   initial=nurse_init_data)

            # if the user is submitting a form, save it if it is valid
            if request.POST:
                nurse_form = NurseForm(request.POST,
                                       instance=nurse_instance,
                                       initial=nurse_init_data)
                profile_form = ProfileForm(request.POST,
                                           instance=profile_instance,
                                           initial=profile_init_data)
                user_form = UserForm(request.POST,
                                     instance=user_instance,
                                     initial=user_init_data)

                if user_form.is_valid():
                    user_form.save()
                    nurse_form.save()
                    profile_form.save()

                    log = Log(username=nurse_instance.profile.user.username,
                              action=" made profile changes ")
                    log.save()

                    return redirect('/profile')
                else:
                    print("error")

            appointments = Appointment.objects.filter(
                hospital=profile_instance.hospital_assignment).order_by(
                    '-date').reverse()

            return render(
                request, "account/useredit.html", {
                    "user": request.user,
                    "profile": profile_instance,
                    "nurse": nurse_instance,
                    "userform": user_form,
                    "nurseform": nurse_form,
                    "profileform": profile_form,
                    "usertype": "Nurse",
                    "appointments": appointments
                })
    else:
        return redirect('/login')
Beispiel #28
0
    def post(self, request):
        self.class_taken = request.user.profile.timetable
        profile_form = ProfileForm(instance=request.user.profile)
        setting_form = PasswordChangeForm(request.user)
        tags = request.user.profile.interest_tag.all()

        if 'profile' in request.POST:
            profile_form = ProfileForm(request.POST,
                                       request.FILES,
                                       instance=request.user.profile)
            if profile_form.is_valid():
                profile_form.save()
                return redirect("index")
            else:

                return render(
                    request, self.template_name, {
                        "profile_form": profile_form,
                        "setting_form": setting_form,
                        'classes_number': self.classes_number,
                        'class_taken': self.class_taken,
                        'tags': tags
                    })

        elif 'setting' in request.POST:
            setting_form = PasswordChangeForm(user=request.user,
                                              data=request.POST)
            if setting_form.is_valid():
                setting_form.save()
                update_session_auth_hash(request, setting_form.user)
                return redirect("index")
            else:
                return render(
                    request, self.template_name, {
                        "profile_form": profile_form,
                        "setting_form": setting_form,
                        'classes_number': self.classes_number,
                        'class_taken': self.class_taken,
                        'tags': tags
                    })

        elif 'time-table' in request.POST:
            table = request.POST['table']
            profile = request.user.profile
            profile.timetable = table
            profile.save()
            self.class_taken = table
            return render(
                request, self.template_name, {
                    "profile_form": profile_form,
                    "setting_form": setting_form,
                    'classes_number': self.classes_number,
                    'class_taken': self.class_taken,
                    'tags': tags
                })

        elif 'interest' in request.POST:
            tags = request.POST.getlist('tags')
            print tags
            for tag in tags:
                t, created = Tag.objects.get_or_create(name=tag.lower())

                request.user.profile.interest_tag.add(t)
            return render(
                request, self.template_name, {
                    "profile_form": profile_form,
                    "setting_form": setting_form,
                    'classes_number': self.classes_number,
                    'class_taken': self.class_taken,
                    'tags': tags
                })