예제 #1
0
파일: views.py 프로젝트: hisoka999/silverbb
def base_profile(request):
    f_password = forms.PasswordChangeForm(request.POST)
    f_profile = ProfileForm(instance=request.user.profile)
    f_user = UserEditForm(instance=request.user)
    commit = False
    if request.method == "POST":
        f_profile = ProfileForm(request.POST, request.FILES, instance=request.user.profile)
        f_user = UserEditForm(request.POST, request.FILES, instance=request.user)
        if f_password.is_valid():
            f_password.save(commit=True)
            # handle_uploaded_file(request.FILES['avatar'])
            f_profile.save(commit=True)
            commit = True
        if f_profile.is_valid():
            f_profile.save(commit=True)
            # handle_uploaded_file(request.FILES['avatar'])
            commit = True
        if f_user.is_valid():
            user = f_user.save(commit=True)
            commit = True
    return render_to_response(
        "user/profile.html",
        {"profile": f_profile, "f_pw": f_password, "f_user": f_user, "commit": commit},
        context_instance=RequestContext(request),
    )
예제 #2
0
파일: views.py 프로젝트: asuvorov/mvp
def edit_profile(request):
    user = request.user
    try:
        profile = UserProfile.objects.get(user=user)
    except:
        profile = UserProfile()

    pform = UserEditForm(request.user, request.POST or None, instance=profile)

    if request.method == "POST":
        if pform.is_valid():
            # Update User
            user.first_name = pform.cleaned_data["first_name"]
            user.last_name = pform.cleaned_data["last_name"]
            #user.email = pform.cleaned_data["email"]
            user.save()
            pform.save()

            return HttpResponseRedirect('/accounts/profile/view/')

    return render_to_response('account_edit.html',
            RequestContext(request, {
                    "pform": pform,
                    "profile": profile,
                    }))
예제 #3
0
def edit_profile(request):
    user = request.user
    try:
        profile = UserProfile.objects.get(user=user)
    except:
        profile = UserProfile()

    pform = UserEditForm(request.user, request.POST or None, instance=profile)

    if request.method == "POST":
        if pform.is_valid():
            # Update User
            user.first_name = pform.cleaned_data["first_name"]
            user.last_name = pform.cleaned_data["last_name"]
            #user.email = pform.cleaned_data["email"]
            user.save()
            pform.save()

            return HttpResponseRedirect('/accounts/profile/view/')

    return render_to_response(
        'account_edit.html',
        RequestContext(request, {
            "pform": pform,
            "profile": profile,
        }))
예제 #4
0
파일: views.py 프로젝트: HanabiDev/Ursus
def edit_user(request, user_id):

	user = User.objects.get(id=user_id)

	if request.method == 'GET':
		
		form = UserEditForm(instance=user)
		if user.type == 'E':
			form = UserEditForm(initial={'role': user.role}, instance=user)

		return render_to_response('edit_user.html', {'form':form, 'site_user':user}, 
						context_instance=RequestContext(request))

	if request.method == 'POST':
		form = UserEditForm(request.POST, instance=user)

		if form.is_valid():

			user = form.save()

			if request.FILES:
				user.avatar = request.FILES.get('avatar')
			
			user.save()

			if user.type == 'C':
				return redirect(reverse_lazy('admin:users:clients'))
			
			return redirect(reverse_lazy('admin:users:employees'))


    	return render_to_response('edit_user.html', {'form':form, 'site_user':user}, 
						context_instance=RequestContext(request))
예제 #5
0
def profile_edit(request):

    if request.method == "POST":
        user_form = UserEditForm(request.POST,
                                 request.FILES,
                                 instance=request.user)
        profile_form = UserProfileForm(request.POST,
                                       request.FILES,
                                       instance=request.user.user)

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

        return redirect('profile')
    else:
        if not request.user:
            return redirect('login')
        else:
            user_form = UserEditForm(instance=request.user)
            profile_form = UserProfileForm(instance=request.user.user)
            return render(request, 'campusthrift/profile_edit.html', {
                'user_form': user_form,
                'profile_form': profile_form
            })
예제 #6
0
파일: views.py 프로젝트: Anilraj82/YAAS
def edit_user(request):
    if request.method == 'POST':
        form = UserEditForm(data=request.POST, user=request.user)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/auction/')
    else:
        form = UserEditForm(user=request.user)
        return render_to_response('user/edit.html',
                              {'form': form, 'full_name': request.user.username },context_instance = RequestContext(request))
예제 #7
0
def edit_user(request):
	if request.user.is_authenticated():
		# Gets user info of the current user logged in the system
		if request.method == 'POST':
			form = UserEditForm(request.POST, instance=request.user)
			if form.is_valid():
				form.save()
				return HttpResponseRedirect('/')
		else:
			form = UserEditForm(instance=request.user)
		c = {'form': form}
		return render_to_response("edit_user.html", c, context_instance=RequestContext(request))
예제 #8
0
파일: views.py 프로젝트: agar3s/recluta
def userProfileEditView(request):
    user = request.user
    if request.method== 'POST':
        form = UserEditForm(request.POST)
        if form.is_valid():
            user_profile_factory = UserProfileFactory()
            user_profile_factory.save_instance_form(form=form, user=user)
            return HttpResponseRedirect("/")
    else:
        form_loader = UserEditFormLoader()
        form = form_loader.load_initial_data(user)
    ctx = {'form':form}
    return render_to_response('edit_profile.html',ctx,context_instance=RequestContext(request))
예제 #9
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})
예제 #10
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})
예제 #11
0
def publisher_settings_users_edit(request, id):
    ''' View to edit a Publisher's User '''
    from atrinsic.base.models import User
    from forms import UserEditForm

    try:
        u = User.objects.get(id=id)

        if request.organization not in u.userprofile_set.all(
        )[0].organizations.all():
            raise Http404

    except User.DoesNotExist:
        raise Http404

    if request.method == "POST":
        form = UserEditForm(request.POST)
        form.user_id = u.id

        if form.is_valid():
            u.first_name = form.cleaned_data['first_name']
            u.last_name = form.cleaned_data['last_name']
            u.email = form.cleaned_data['email']
            u.username = u.email.replace('@', '-')

            if form.cleaned_data.get("password", None):
                u.set_password(form.cleaned_data['password'])

            u.save()

            return HttpResponseRedirect('/publisher/settings/users/')
    else:
        form = UserEditForm(
            initial={
                'first_name': u.first_name,
                'last_name': u.last_name,
                'email': u.email,
            })

    return AQ_render_to_response(request,
                                 'publisher/settings/users-edit.html', {
                                     'u': u,
                                     'form': form,
                                 },
                                 context_instance=RequestContext(request))
예제 #12
0
def view_user(request, user_id):
    try:
        user = User.objects.get(id=user_id)
    except User.DoesNotExist:
        raise Http404("User does not exist")

    if request.method == 'POST':
        form = UserEditForm(request.POST, request.FILES, instance=user)
        if form.is_valid():
            form.save()
            return redirect('view_user', user_id)

    else:
        form = UserEditForm(instance=user)

    # print(form)

    return render(request, 'answers/user.html', {'form': form})
예제 #13
0
def user_add(request, template="user_management/user_add.html"):
    context = {}
    try:
        form = UserEditForm(request.POST or None)
        if request.method == 'POST':
            if form.is_valid():
                user = form.save()
                messages.add_message(request, messages.SUCCESS, "User created")
            else:
                messages.add_message(request, messages.WARNING,
                                     "Form is not valid : %s" % form.errors)
            return HttpResponseRedirect(reverse("users:user_list"))
        else:
            context['groups'] = [
                x for x in Group.objects.all().order_by("name")
            ]
    except Exception, ex:
        logger.exception(ex)
        messages.add_message(request, messages.ERROR, ex)
예제 #14
0
def user_edit(request,
              user_id=None,
              template="user_management/user_edit.html"):
    context = {}
    try:
        user = get_user_model().objects.get(pk=user_id)
        form = UserEditForm(request.POST or None, instance=user)

        if request.method == "POST":
            if form.is_valid():
                user = form.save()
            else:
                messages.add_message(request, messages.INFO,
                                     "Failed to edit user")

            return HttpResponseRedirect(reverse("users:user_list"))
        context['form'] = form
    except Exception, ex:
        logger.exception(ex)
        messages.add_message(request, messages.WARNING, ex)
예제 #15
0
def publisher_settings_users_edit(request, id):
    ''' View to edit a Publisher's User '''
    from atrinsic.base.models import User
    from forms import UserEditForm
    
    try:
        u = User.objects.get(id=id)

        if request.organization not in u.userprofile_set.all()[0].organizations.all():
            raise Http404

    except User.DoesNotExist:
        raise Http404

    if request.method == "POST":
        form = UserEditForm(request.POST)
        form.user_id = u.id

        if form.is_valid():
            u.first_name = form.cleaned_data['first_name']
            u.last_name = form.cleaned_data['last_name']
            u.email = form.cleaned_data['email']
            u.username = u.email.replace('@', '-')

            if form.cleaned_data.get("password",None):
                u.set_password(form.cleaned_data['password'])

            u.save()

            return HttpResponseRedirect('/publisher/settings/users/')
    else:
        form = UserEditForm(initial={
                'first_name' : u.first_name,
                'last_name' : u.last_name,
                'email' : u.email,
            })

    return AQ_render_to_response(request, 'publisher/settings/users-edit.html', {
            'u' : u,
            'form' : form,
        }, context_instance=RequestContext(request))
예제 #16
0
def edit_user(request):
    context = {}

    if request.method == 'POST':
        form = UserEditForm(request.POST)
        if form.is_valid():
            first_name = form.cleaned_data['first_name']
            last_name = form.cleaned_data['last_name']
            email = form.cleaned_data['email']
            phone = form.cleaned_data['phone']
            new_password =  form.cleaned_data['new_password']
            new_password_confirm = form.cleaned_data['new_password_confirm']

            error = False
            if new_password and new_password_confirm:
                if (new_password != new_password_confirm):
                    # 400
                    form.errors['__all__'] = form.error_class(["Error: passwords didn't match."])
                    error = True
            elif (new_password and not new_password_confirm) or (new_password_confirm and not new_password):
                # 400
                form.errors['__all__'] = form.error_class(["Error: you must input the desired password twice."])
                error = True
            else:
                new_password = None

            if not error:
                user = users_manager.update_user(request.user, first_name, last_name, new_password, email, phone)
                context['success'] = not error
    else:
        data = {'first_name': request.user.first_name,
                'last_name': request.user.last_name,
                'email': request.user.email,
                'phone': request.user.profile.phone,}
        form = UserEditForm(data)

    # GET / POST with invalid input
    context['form'] = form
    return render_to_response('user/edit.html', context, context_instance=RequestContext(request))
예제 #17
0
def edit_user(request, user_id):

    user = User.objects.get(id=user_id)

    if request.method == 'GET':

        form = UserEditForm(instance=user)
        if user.type == 'E':
            form = UserEditForm(initial={'role': user.role}, instance=user)

        return render_to_response('edit_user.html', {
            'form': form,
            'site_user': user
        },
                                  context_instance=RequestContext(request))

    if request.method == 'POST':
        form = UserEditForm(request.POST, instance=user)

        if form.is_valid():

            user = form.save()

            if request.FILES:
                user.avatar = request.FILES.get('avatar')

            user.save()

            if user.type == 'C':
                return redirect(reverse_lazy('admin:users:clients'))

            return redirect(reverse_lazy('admin:users:employees'))

    return render_to_response('edit_user.html', {
        'form': form,
        'site_user': user
    },
                              context_instance=RequestContext(request))
예제 #18
0
def edit(request):

    user = request.user
    f = get_object_or_404(Farmer, user=user)
    u = user

    if request.method == 'POST':
        form = FarmerForm(request.POST, instance=f)
        uform = UserEditForm(request.POST, instance=u)

        if uform.is_valid() and form.is_valid():
            uform.save()
            form.save()

            return redirect(reverse('home'))
    else:
        form = FarmerForm(instance=f)
        uform = UserEditForm(instance=u)

    return render(request, 'registration/edit.html', {
        'form': form,
        'uform': uform
    })