Esempio n. 1
0
def edit(request, pk):
    user = get_object_or_404(
        klass=User, 
        pk=pk
    )
    user_form = UserEditForm(
        data=request.POST or None,
        instance=user
    )
    user_password_form = UserEditPasswordForm(
        data=request.POST or None,
        user=user
    )
    if user_form.is_valid():
        user_form.save(auth.get_user(request))
        messages.success(request, u"Usuário editado com sucesso.")
        return redirect('user_list')

    template_context = {
        'user': user,
        'user_form': user_form,
        'user_password_form': user_password_form,
    }
    return render(
        request=request,
        template_name='edit.html',
        dictionary=template_context
    )
Esempio n. 2
0
def user_edit(request, id):
    voilet_list = User.objects.get(id=id)
    content = {}
    data_time = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
    if request.user.is_superuser:
        if request.method == 'POST':
            if request.POST.getlist("password1") == request.POST.getlist("password2"):
                uf = UserEditForm(request.POST)
                if uf.is_valid():
                    voilet_list.department = uf.instance.department
                    voilet_list.jobs = uf.instance.jobs
                    voilet_list.first_name = uf.instance.first_name
                    voilet_list.save()
                    return HttpResponseRedirect('/accounts/user/' + id + '/')
                else:
                    print "is over"
        else:
            content["userall"] = UserEditForm()
            content["user_list"] = voilet_list
            content["department"] = department_Mode.objects.all()
            content["jobs_name"] = manager_demo
            content.update(csrf(request))
            return render_to_response('user/user_edit.html',content,context_instance=RequestContext(request))
    else:
        return render_to_response('user/auth_error_index.html', context_instance=RequestContext(request))
Esempio n. 3
0
def edit_person(request):
    person = Person.objects.get(user=request.user)
    
    if request.method == 'POST':
        form = UserEditForm(request.POST, request.FILES)
        if form.is_valid():
            first_name = form.cleaned_data['first_name']
            last_name = form.cleaned_data['last_name']
            picture = form.cleaned_data['picture']
    
            person.user.first_name = first_name
            person.user.last_name = last_name
            person.user.save()
            person.picture = picture

            person.save()

            return HttpResponseRedirect('/')
    else:
        form = UserEditModelForm({'first_name': person.user.first_name,
                             'last_name': person.user.last_name,
                            'picture': person.picture
                            })
        #form = UserEditModelForm(instance=person)

        c = RequestContext(request, {'form': form })
        c.update(csrf(request))
        return render_to_response('registration/edit_person.html', c)
Esempio n. 4
0
class EditProfileView(LoginRequiredMixin, UpdateView):
    template_name = 'edit.html'
    user_form = UserEditForm
    profile_form = UserProfileEditForm

    def get(self, request, *args, **kwargs):
        self.user_form = UserEditForm(instance=request.user)
        self.profile_form = UserProfileEditForm(
            instance=request.user.userprofile)
        return render(request,
                      self.template_name,
                      context={
                          'user_form': self.user_form,
                          'profile_form': self.profile_form
                      })

    def post(self, request, *args, **kwargs):
        self.user_form = UserEditForm(instance=request.user, data=request.POST)
        self.profile_form = UserProfileEditForm(
            instance=request.user.userprofile,
            data=request.POST,
            files=request.FILES)
        if self.user_form.is_valid() and self.profile_form.is_valid():
            self.user_form.save()
            self.profile_form.save()
            messages.success(request, 'Profile updated successfully')
        else:
            messages.error(request, 'Error')
        return render(request, self.template_name, {
            'user_form': self.user_form,
            'profile_form': self.profile_form
        })
Esempio n. 5
0
def user_edit(request, id):
    voilet_list = User.objects.get(id=id)
    content = {}
    data_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
    if request.user.is_superuser:
        if request.method == 'POST':
            if request.POST.getlist("password1") == request.POST.getlist(
                    "password2"):
                uf = UserEditForm(request.POST)
                if uf.is_valid():
                    voilet_list.department = uf.instance.department
                    voilet_list.jobs = uf.instance.jobs
                    voilet_list.first_name = uf.instance.first_name
                    voilet_list.save()
                    return HttpResponseRedirect('/accounts/user/' + id + '/')
                else:
                    print "is over"
        else:
            content["userall"] = UserEditForm()
            content["user_list"] = voilet_list
            content["department"] = department_Mode.objects.all()
            content["jobs_name"] = manager_demo
            content.update(csrf(request))
            return render_to_response('user/user_edit.html',
                                      content,
                                      context_instance=RequestContext(request))
    else:
        return render_to_response('user/auth_error_index.html',
                                  context_instance=RequestContext(request))
Esempio n. 6
0
 def get(self, request, *args, **kwargs):
     self.user_form = UserEditForm(instance=request.user)
     self.profile_form = UserProfileEditForm(
         instance=request.user.userprofile)
     return render(request,
                   self.template_name,
                   context={
                       'user_form': self.user_form,
                       'profile_form': self.profile_form
                   })
Esempio n. 7
0
def profile_edit(request, username):
    username = request.user.username
    if request.method == "POST":
        profile_form = ProfileEditForm(request.POST or None,
                                       request.FILES,
                                       instance=request.user.profile)

        user_form = UserEditForm(request.POST or None, instance=request.user)
        if profile_form.is_valid() and user_form.is_valid():
            profile_form.user = request.user
            user_form.user = request.user
            user_form.email = request.user.email
            profile_form.save(commit=True)
            user_form.save(commit=True)
            return redirect('profile:userdetail',
                            username=request.user.username)
    else:
        profile_form = ProfileEditForm(instance=request.user.profile)

        user_form = UserEditForm(instance=request.user)
    context = {
        'user_form': user_form,
        'profile_form': profile_form,
    }
    return render(request, 'accounts/profile_edit.html', context)
Esempio n. 8
0
    def post(self, request):
        u_form = UserEditForm(request.POST, instance=request.user)
        p_form = ProfileEditForm(request.POST,
                                 request.FILES,
                                 instance=request.user.profile)

        context = {'u_form': u_form, 'p_form': p_form}

        if u_form.is_valid() and p_form.is_valid():
            u_form.save()
            p_form.save()
            return render(request, 'account/profile.html', context)
Esempio n. 9
0
def edit(request):
    if request.method == 'POST':
        form = UserEditForm(request.POST, request.FILES, instance=request.user)
        if form.is_valid():
            form.save()
            messages.success(request, _(u'Profile changed success!'))
            return redirect(request.user)
        messages.error(request, _(u'Please correct the error below.'))
    else:
        form = UserEditForm(instance=request.user)
    return {
        'form': form
    }
Esempio n. 10
0
    def post(self, request, *args, **kwargs):
        user_form = UserEditForm(instance=request.user, data=request.POST)
        profile_form = ProfileEditForm(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, 'Data has been successfully updated.')
        else:
            messages.error(request, 'Please correct the error below.')

            return reverse('accounts:edit_account')

        return redirect('accounts:users', username=request.user.username)
Esempio n. 11
0
 def post(self, request, *args, **kwargs):
     self.user_form = UserEditForm(instance=request.user, data=request.POST)
     self.profile_form = UserProfileEditForm(
         instance=request.user.userprofile,
         data=request.POST,
         files=request.FILES)
     if self.user_form.is_valid() and self.profile_form.is_valid():
         self.user_form.save()
         self.profile_form.save()
         messages.success(request, 'Profile updated successfully')
     else:
         messages.error(request, 'Error')
     return render(request, self.template_name, {
         'user_form': self.user_form,
         'profile_form': self.profile_form
     })
Esempio n. 12
0
    def get(self, request):
        print('GETTING HERE')
        u_form = UserEditForm(instance=request.user)
        p_form = ProfileEditForm(instance=request.user.profile)

        context = {'u_form': u_form, 'p_form': p_form}
        return render(request, 'account/profile_update.html', context)
Esempio n. 13
0
 def get(self, request, *args, **kwargs):
     user_form = UserEditForm(instance=request.user)
     profile_form = ProfileEditForm(instance=request.user.profile)
     return render(request, self.template_name, {
         'user_form': user_form,
         'profile_form': profile_form
     })
Esempio n. 14
0
def edit(request):
    if request.method == 'POST':
        user_form = UserEditForm(instance=request.user, data=request.POST)
        profile_form = ProfileEditForm(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, 'Данные пользователя изменены')
    else:
        user_form = UserEditForm(instance=request.user)
        profile_form = ProfileEditForm(instance=request.user.profile)

    return render(
        request,
        'accounts/edit.html',
        {
            'user_form': user_form,
            'profile_form': profile_form
        },
    )


# send_mail('Привет из Django',
#     'Тело письма, отправленного из приложения, выглядит именно вот так',
#     settings.EMAIL_HOST_USER, ['*****@*****.**'], fail_silently=False)
Esempio n. 15
0
def edit_profile(request):
    """
    Edit User Profile
    """
    """edit both the user and profile model instances"""
    if request.method == 'POST':
        user_form = UserEditForm(data=request.POST or None,
                                 instance=request.user)
        profile_form = ProfileEditForm(data=request.POST or None,
                                       instance=request.user.profile,
                                       files=request.FILES)

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

        return redirect('profile', id=request.user.id)
    else:
        user_form = UserEditForm(instance=request.user)
        profile_form = ProfileEditForm(instance=request.user.profile)

    return render(request, 'edit_profile.html', {
        'user_form': user_form,
        'profile_form': profile_form
    })
Esempio n. 16
0
def edit(request):
    context = {}
    edit_form = UserEditForm(instance=request.user)
    edit_profile_form = UserProfileForm(instance=request.user.get_profile())

    if request.method == "POST":
        edit_form = UserEditForm(data=request.POST, instance=request.user)
        if edit_form.is_valid():
            edit_profile_form = UserProfileForm(data=request.POST, instance=request.user.get_profile())
            if edit_profile_form.is_valid():
                try:
                    team = Team.objects.get(name=request.POST['team'])
                except:
                    team = Team.objects.create(name=request.POST['team'])
                try:
                    old_team = TeamUser.objects.get(user=request.user)
                except:
                    old_team = TeamUser.objects.none()


                if not old_team or old_team.team.name != team.name:
                    old_team.delete()
                    print old_team
                    team_user = TeamUser.objects.create(team=team, user=request.user)
            
            
                user = edit_form.save()
                user.set_password(user.password)
                user.email = request.POST['email']
                user.first_name = request.POST['first_name']
                user.last_name = request.POST['last_name']
                user.save();
                
                user_profile = edit_profile_form.save()
                return HttpResponseRedirect(reverse('dashboard.views.index'))
            else:
                print edit_profile_form.errors
        else:
            print userform.errors
                

    context = {'edit_user_form': edit_form, 
               'edit_user_profile_form': edit_profile_form}

    return render_to_response('edit.html', RequestContext(request, context))
Esempio n. 17
0
def edit(request):
    """view for editing user profile data. Includes fields from User and Profile tables"""
    if request.method == 'POST':
        user_form = UserEditForm(instance=request.user, data=request.POST)
        profile_form = ProfileEditForm(request.POST,
                                       instance=request.user.profile,
                                       files=request.FILES)

        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()
            return redirect('tasks:list')
    else:
        user_form = UserEditForm(instance=request.user)
        profile_form = ProfileEditForm(instance=request.user.profile)

    return render(
        request,
        'accounts/edit.html',
        {
            'user_form': user_form,
            'profile_form': profile_form,
            'request': request.user
        },
    )
Esempio n. 18
0
def user_editor(request, data):
    try:
        user = UserInfo.objects.get(pk=data)
        if not request.user.is_superuser and (request.user.pk != user.pk):
            return redirect(reverse('accounts:permission-deny'))
    except Exception:
        return redirect(reverse('accounts:user-add'))
    if request.method == 'POST':
        JSON_RESULT = {'status': 200, 'message': '', 'error': '', 'data': []}
        forms = UserEditForm(request, data=request.POST, instance=user)
        print(request.POST)
        if forms.is_valid():
            forms.save()
            JSON_RESULT['message'] = '%s-更新成功' % forms.cleaned_data.get(
                'username')
            return JsonResponse(JSON_RESULT)
        JSON_RESULT['status'] = 201
        JSON_RESULT['error'] = forms.errors.as_json()
        return JsonResponse(JSON_RESULT)
    else:
        forms = UserEditForm(request, instance=user)
    kwargs = {
        'html_title': '更新用户',
        'cancel': reverse('accounts:user-list'),
        'col_md': 'col-md-2',
        'forms': forms
    }
    return render(request, 'accounts/user-add.html', kwargs)
Esempio n. 19
0
def edit_profile(request):
    if request.method == 'POST':
        print('3')
        user_form = UserEditForm(data=request.POST or None, instance=request.user)
        profile_form = ProfileEditForm(data=request.POST or None, instance=request.user.userprofile, files=request.FILES)
        if profile_form.is_valid():
            print('1')
            if user_form.is_valid():
                print('4')
                #print(profile_form)
                user_form.save()
                profile_form.save()
                return HttpResponseRedirect(reverse("accounts:edit_profile"))
            else:
                print('6')
        else:
            print('5')
    else:
        print('2')
        user_form = UserEditForm(instance=request.user)
        profile_form = ProfileEditForm(instance=request.user.userprofile)

    context = {
        'user_form': user_form,
        'profile_form': profile_form,
    }
    return render(request, 'accounts/edit_profile.html', context)
Esempio n. 20
0
def edit(request, pk):
    user = get_object_or_404(klass=User, pk=pk)
    user_form = UserEditForm(data=request.POST or None, instance=user)
    user_password_form = UserEditPasswordForm(data=request.POST or None,
                                              user=user)
    if user_form.is_valid():
        user_form.save(auth.get_user(request))
        messages.success(request, u"Usuário editado com sucesso.")
        return redirect('user_list')

    template_context = {
        'user': user,
        'user_form': user_form,
        'user_password_form': user_password_form,
    }
    return render(request=request,
                  template_name='edit.html',
                  dictionary=template_context)
Esempio n. 21
0
def edit_account(request):
    if request.method == "POST":
        form = UserEditForm(request.POST)
        if form.is_valid():
            request.user.first_name = form.cleaned_data["first_name"]
            request.user.last_name = form.cleaned_data["last_name"]
            request.user.email = form.cleaned_data["email"]
            request.user.save()
            messages.success(request, 'You account has been successfully updated!')
        else:
            messages.error(request, 'The form had errors. Please correct them and submit again.')
    else:
        form = UserEditForm({
            "first_name": request.user.first_name,
            "last_name": request.user.last_name,
            "email": request.user.email,
        })
    return render(request, 'accounts/edit.html', {"form": form})
Esempio n. 22
0
def edit_account(request):
    if request.method == "POST":
        form = UserEditForm(request.POST)
        if form.is_valid():
            request.user.first_name = form.cleaned_data["first_name"]
            request.user.last_name = form.cleaned_data["last_name"]
            request.user.email = form.cleaned_data["email"]
            request.user.save()
            messages.success(request,
                             'You account has been successfully updated!')
        else:
            messages.error(
                request,
                'The form had errors. Please correct them and submit again.')
    else:
        form = UserEditForm({
            "first_name": request.user.first_name,
            "last_name": request.user.last_name,
            "email": request.user.email,
        })
    return render(request, 'accounts/edit.html', {"form": form})
Esempio n. 23
0
def edit(request, user_id):
    """
    Custom View to allow for custom users with username as email. Mitigates:

    https://github.com/torchbox/wagtail/issues/158
    """
    user = get_object_or_404(User, id=user_id)
    if request.POST:
        form = UserEditForm(request.POST, instance=user)
        if form.is_valid():
            user = form.save()
            messages.success(request,
                             _("User '{0}' updated.").format(user),
                             buttons=[
                                 messages.button(
                                     reverse('wagtailusers_users_edit',
                                             args=(user.id, )), _('Edit'))
                             ])
            return redirect('wagtailusers_users_index')
        else:
            messages.error(request,
                           _("The user could not be saved due to errors."))
    else:
        form = UserEditForm(instance=user)

    return render(request, 'wagtailusers/users/edit.html', {
        'user': user,
        'form': form,
    })
Esempio n. 24
0
def edit(request):
    if request.method == "POST":
        user_form = UserEditForm(instance=request.user, data=request.POST)
        profile_form = ProfileEditForm(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()
    else: 
        user_form = UserEditForm(instance=request.user)
        profile_form = ProfileEditForm(instance=request.user.profile)
    return render(request, 'accounts/edit.html', {"user_form": user_form, "profile_form": profile_form})
Esempio n. 25
0
    def post(self, request, *args, **kwargs):
        user_form = UserEditForm(instance=request.user, data=request.POST)
        profile_form = ProfileEditForm(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, 'Data has been successfully updated.')
        else:
            messages.error(request, 'Please correct the error below.')

            return reverse('accounts:edit_account')

        return redirect('accounts:users', username=request.user.username)


# User fields
# date_joined, email, first_name, groups, id,
# is_active, is_staff, is_superuser, last_login,
# last_name, logentry, password, profile, user_permissions,
# username
Esempio n. 26
0
 def test_profile_edit_post_invalid(self):
     user = self.initialize_user()
     self.client.force_login(user)
     user_form = UserEditForm(instance=user, data={})
     profile_form = ProfileEditForm()
     profile_form.instance = user.profile
     response = self.client.post(reverse('auth:edit'),
                                 data={
                                     **profile_form.data,
                                     **user_form.data
                                 })
     self.assertEquals(response.status_code, 200)
     self.assertContains(response, 'Error updating your profile')
Esempio n. 27
0
def edit_profile(request):
    if request.method == 'POST':
        Userform = UserEditForm(request.POST, instance=request.user)
        if (Userform.is_valid()):
            Userform.save()
            return redirect('view_profile')

    else:
        Userform = UserEditForm(instance=request.user)
        args = {'Userform': Userform}
        return render(request, 'accounts/edit_profile.html', args)
Esempio n. 28
0
def edit_profile(request):
    if request.method == 'POST':
        user = UserProfile.objects.get(user=request.user)
        form = UserEditForm(request.POST, request.FILES, instance=user)
        if form.is_valid():
            form.save()
        return redirect(reverse('accounts:view_profile'))
    else:
        user = UserProfile.objects.get(user=request.user)
        form = UserEditForm(instance=user)
        args = {'form': form}
        return render(request, 'accounts/edit_profile.html', args)
Esempio n. 29
0
def edit(request, user_id):
    """
    Custom View to allow for custom users with username as email. Mitigates:

    https://github.com/torchbox/wagtail/issues/158
    """
    user = get_object_or_404(User, id=user_id)
    if request.POST:
        form = UserEditForm(request.POST, instance=user)
        if form.is_valid():
            user = form.save()
            messages.success(request, _("User '{0}' updated.").format(user), buttons=[
                messages.button(reverse('wagtailusers_users_edit', args=(user.id,)), _('Edit'))
            ])
            return redirect('wagtailusers_users_index')
        else:
            messages.error(request, _("The user could not be saved due to errors."))
    else:
        form = UserEditForm(instance=user)

    return render(request, 'wagtailusers/users/edit.html', {
        'user': user,
        'form': form,
    })
Esempio n. 30
0
def edit(request):
	context = {}
	user = request.user
	if request.method == 'POST':
		AccountsUserEditForm = UserEditForm(request.POST)
		if AccountsUserEditForm.is_valid():
			form_data = AccountsUserEditForm.cleaned_data
			user.username = form_data['username']
			user.first_name = form_data['first_name']
			user.last_name = form_data['last_name']
			user.email = form_data['email']
			if form_data['password']:
				user.set_password(form_data['password'])
			user.save()

			userProfile = user.get_profile()
			userProfile.gender = form_data['gender']
			userProfile.birthday = form_data['birthday']
			userProfile.save()

			if form_data['password']:
				user = authenticate(username=form_data['username'], password=form_data['password'])
				login(request, user)
			return redirect('accounts_accounts')
	else:
		AccountsUserEditForm = UserEditForm({
				'username': user.username,
				'first_name': user.first_name,
				'last_name': user.last_name,
				'email': user.email,
				'gender': user.profile.get().gender,
				'birthday': user.profile.get().birthday
			})
	context['AccountsUserEditForm'] = AccountsUserEditForm
	context['user'] = user
	return render_to_response('accounts/edit.html', context, context_instance=RequestContext(request))
Esempio n. 31
0
def edit(request):
    if request.method == "POST":
        user_form = UserEditForm(instance=request.user, data=request.POST)
        profile_form = ProfileEditForm(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, "Профиль изменён")

    else:
        user_form = UserEditForm(instance=request.user)
        profile_form = ProfileEditForm(instance=request.user.profile)

    return render(
        request,
        "accounts/edit.html",
        {"user_form": user_form, "profile_form": profile_form},
    )
Esempio n. 32
0
def edit(request):
    if request.method == 'POST':
        user_form = UserEditForm(instance=request.user,
                                 data=request.POST)
        profile_form = ProfileEditForm(instance=request.user,
                                       data=request.POST,
                                       files=request.FILES)
        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()
            return render(request, 'account/dashboard.html')
        else:
            messages.error(request, 'Error updating your profile')
    else:
        user_form = UserEditForm(instance=request.user)
        profile_form = ProfileEditForm(instance=request.user)
    return render(request, 'account/edit.html', {'user_form': user_form,
                                                 'profile_form': profile_form })
Esempio n. 33
0
def update_profile(request):
    if request.method == 'POST':
        user_form = UserEditForm(request.POST or None, instance=request.user)
        profile_form = ProfileEditForm(request.POST or None, instance=request.user.profile, files=request.FILES)
        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()
            
            return redirect('home:dashboard')
       
    else:
        user_form = UserEditForm(instance=request.user)
        profile_form = ProfileEditForm(instance=request.user.profile)

    return render(request, 'accounts/update_profile.html', {
        'user_form': user_form,
        'profile_form': profile_form
    })
Esempio n. 34
0
def edit(request, user_id):
    if request.user.id != int(user_id):
        return redirect(reverse('home'))
    user = User.objects.get(id=user_id)
    if request.method == 'POST':
        form = UserEditForm(request.POST, instance=user)
        if form.is_valid():
            edited_user = form.save()
            messages.success(request, 'Profile successfully edited.')
            return redirect(edited_user)
    else:
        form = UserEditForm(instance=user)

    return render(request, 'accounts/edit.html', {'form': form,
                                                  'user': user})
Esempio n. 35
0
def edit(request):
    if request.method == 'POST':
        """
        ???
        """
        user_form = UserEditForm(instance=request.user, data=request.POST)
        profile_form = UserProfileEditForm(instance=request.user.userprofile,
                                           data=request.POST,
                                           files=request.FILES)
        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()
    else:
        user_form = UserEditForm(instance=request.user)
        profile_form = UserProfileEditForm(instance=request.user.userprofile)
    return render(request, 'accounts/edit.html', {
        'user_form': user_form,
        'profile_form': profile_form
    })
Esempio n. 36
0
def edit_profile(request):
    """ Creates a view that allows the user to edit its profile fields """
    if request.method == 'POST':
        user_form = UserEditForm(instance = request.user, data=request.POST)
        profile_form = UserProfileEditForm(instance = request.user.userprofile, 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")
            return view_profile(request)
        else:
            messages.error(request, "Error updating your profile")
    else:
        user_form = UserEditForm(instance=request.user)
        profile_form = UserProfileEditForm(instance=request.user.userprofile)
    
    return render(request, 'edit_profile.html', {'user_form': user_form, 'profile_form': profile_form})
        
Esempio n. 37
0
    def test_avatar_uploads(self):

        u = User.objects.get(username='******')
        avatar = self.generate_photo_file()
        self.client.force_login(u)
        user_form = UserEditForm(instance=u, data=u.__dict__)
        profile_form = ProfileEditForm({'photo': avatar})
        profile_form.instance = u.profile
        res = self.client.post(reverse('auth:edit'),
                               data={
                                   **profile_form.data,
                                   **user_form.data
                               },
                               format='multipart',
                               follow=True)
        u.refresh_from_db()
        upload_url = os.path.join(
            os.path.join(os.path.abspath(settings.MEDIA_ROOT),
                         u.profile.photo.field.upload_to)) + 'test.png'
        self.assertEquals(res.status_code, 200)
        self.assertEquals(u.profile.photo.path, upload_url)
        u.profile.photo.delete()
Esempio n. 38
0
def edit(request):
    if request.method == 'POST':
        user_form = UserEditForm(instance=request.user, data=request.POST)
        profile_form = ProfileEditForm(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')
            return redirect('accounts:profile')
        else:
            messages.error(request, 'Error updating your profile.html')
    else:
        user_form = UserEditForm(instance=request.user)
        profile_form = ProfileEditForm(instance=request.user.profile)
    return render(request, 'accounts/edit.html', {
        'user_form': user_form,
        'profile_form': profile_form
    })