예제 #1
0
파일: views.py 프로젝트: sivajipr/flipkart
def edit_profile(request):
    user = request.user
    users = User.objects.get(username=user)
    profile = Profile.objects.get(user=user)
    group = Group.objects.get(name='user')
    user_members = group.user_set.all()
    if user in user_members:
        if request.method == 'POST':
            form1 = EditUserForm(request.POST, instance=users)
            form2 = ProfileForm(request.POST, instance=profile)
            if form1.is_valid() and form2.is_valid():
                form2.save()
                form1.save()
                return HttpResponseRedirect('/')
        else:
     	    form1 = EditUserForm(instance=users)
       	    form2 = ProfileForm(instance=profile)
       	variables = RequestContext(request, {'user':user,'user_members':user_members,'form1': form1, 'form2':form2})
    else:
    	if request.method == 'POST':
    		form1 = MerchantForm(request.POST, instance=users)
    		if form1.is_valid():
    			form1.save()
    			return HttpResponseRedirect('/')
    	else:
    		form1 = MerchantForm(instance=users)

        variables = RequestContext(request, {'user':user,'user_members':user_members,'form1': form1})
    return render_to_response('users/edit_profile.html', variables)
예제 #2
0
def edit_user(request, username):
    user = get_object_or_404(User, username=username)
    member = user.member_set.get()
    team = member.team
    coaches = True if request.user.member.coaches(member) else False
    c = {}
    c.update(csrf(request))
    if request.method == 'POST':  # If the form has been submitted...
        if request.POST.get('delete'):
            member.delete()
            messages.add_message(request, messages.SUCCESS, 'Member Deleted!')
            return HttpResponseRedirect(
                reverse('team_details', args=(team.id, )))
        form = EditUserForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            user.username = form.cleaned_data['username']
            user.email = form.cleaned_data['email']
            user.first_name = form.cleaned_data['first_name']
            user.last_name = form.cleaned_data['last_name']
            member.number = form.cleaned_data['number']
            member.position = form.cleaned_data['position']
            member.city = form.cleaned_data['city']
            member.state = form.cleaned_data['state']
            member.phone = form.cleaned_data['phone']
            member.country = form.cleaned_data['country']
            member.year = form.cleaned_data['year']
            member.kind = form.cleaned_data['user_type']
            user.save()
            member.save()
            messages.add_message(request, messages.SUCCESS,
                                 'User details updated!')
            return HttpResponseRedirect(
                reverse('user_details', args=(user.username, )))
        messages.add_message(
            request, messages.ERROR,
            'Sorry, something bad happend updatting a new user!')
    else:
        form = EditUserForm({
            'username': user.username,
            'first_name': user.first_name,
            'last_name': user.last_name,
            'email': user.email,
            'user_type': member.kind,
            'position': member.position,
            'number': member.number,
            'city': member.city,
            'phone': member.phone,
            'state': member.state,
            'year': member.year,
            'country': member.country,
        })  # An unbound form
    return render_to_response("users/edit.html", {
        'coach_editing': coaches,
        'form': form,
        'c': c,
        'edit_user': user
    },
                              context_instance=RequestContext(request))
예제 #3
0
 def post(self, request):
     user_form = EditUserForm(request.POST, instance=request.user)
     profile_form = EditProfileForm(request.POST, request.FILES, instance=request.user.profile)
     
     if user_form.is_valid() and profile_form.is_valid():
         user_form.save()
         profile_form.save()
         return redirect('users:view_profile')
     return HttpResponse("Something went wrong")
예제 #4
0
def change_password(request):
    person = get_object_or_404(Person, user__id=request.user.id)
    success_message = None
    error_message = None
    if request.method == 'POST':
        pwd_form = CustomPasswordChangeForm(data=request.POST,
                                            user=request.user)
        if pwd_form.is_valid():
            try:
                pwd_form.save(commit=True)
                success_message = 'Ваш пароль успешно изменен!'
                update_session_auth_hash(request, pwd_form.user)
            except:
                error_message = 'Ошибка при сохранении данных'
    else:
        pwd_form = CustomPasswordChangeForm(user=request.user)
    form = EditPersonForm(instance=person)
    email_form = EditUserForm(instance=request.user)
    return render(
        request, 'users/profile.html', {
            'form': form,
            'email_form': email_form,
            'pwd_form': pwd_form,
            'success_message': success_message,
            'error_message': error_message
        })
예제 #5
0
def edit_user(request, username):
    user = get_object_or_404(User, username=username)
    member = user.member_set.get()
    team = member.team
    coaches  = True if request.user.member.coaches(member) else False
    c = {}
    c.update(csrf(request))
    if request.method == 'POST': # If the form has been submitted...
        if request.POST.get('delete'):
            member.delete()
            messages.add_message(request, messages.SUCCESS, 'Member Deleted!')
            return HttpResponseRedirect(reverse('team_details', args=(team.id,)))
        form = EditUserForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            user.username = form.cleaned_data['username']
            user.email = form.cleaned_data['email']
            user.first_name = form.cleaned_data['first_name']
            user.last_name = form.cleaned_data['last_name']
            member.number = form.cleaned_data['number']
            member.position = form.cleaned_data['position']
            member.city = form.cleaned_data['city']
            member.state = form.cleaned_data['state']
            member.phone = form.cleaned_data['phone']
            member.country = form.cleaned_data['country']
            member.year = form.cleaned_data['year']
            member.kind = form.cleaned_data['user_type']
            user.save()
            member.save()
            messages.add_message(request, messages.SUCCESS, 'User details updated!')
            return HttpResponseRedirect(reverse('user_details', args=(user.username,)))
        messages.add_message(request, messages.ERROR, 'Sorry, something bad happend updatting a new user!')
    else:
        form = EditUserForm({'username': user.username,
                             'first_name': user.first_name,
                             'last_name': user.last_name,
                             'email': user.email,
                             'user_type': member.kind,
                             'position': member.position,
                             'number': member.number,
                             'city': member.city,
                             'phone': member.phone,
                             'state': member.state,
                             'year': member.year,
                             'country': member.country,
                            }) # An unbound form
    return render_to_response("users/edit.html", {'coach_editing': coaches, 'form': form, 'c':c, 'edit_user':user},
                               context_instance=RequestContext(request))
예제 #6
0
def user_profile(request):
    person = get_object_or_404(Person, user__id=request.user.id)
    success_message = None
    error_message = None
    if request.method == 'POST':
        form = EditPersonForm(request.POST, instance=person)
        email_form = EditUserForm(request.POST, instance=request.user)
        if form.is_valid() or email_form.is_valid(
        ):  # or user_form.is_valid():
            try:
                form.save(commit=True)
                email_form.save(commit=True)
                success_message = 'Данные успешно сохранены'
            except:
                error_message = 'Ошибка при сохранении данных'
        else:
            error_message = '<br>'.join([item for key, value in form.errors.items() for item in value]) + '<br>' +\
                            '<br>'.join([item for key, value in email_form.errors.items() for item in value])# + '<br>' +\
            #'<br>'.join([value for key, value in user_form.errors.items()])
    else:
        form = EditPersonForm(instance=person)
        email_form = EditUserForm(instance=request.user)
    user_form = CustomPasswordChangeForm(user=request.user)
    return render(
        request, 'users/profile.html', {
            'form': form,
            'email_form': email_form,
            'pwd_form': user_form,
            'success_message': success_message,
            'error_message': error_message
        })
예제 #7
0
def EditUser(request, ID):
    user = get_user_model().objects.get(id=ID)
    print user

    if request.method == 'POST':
        form = EditUserForm(request.POST, instance=user)
        if form.is_valid():
            form.save()
            userid = User.objects.get(username=request.user)
            username = User.objects.get(username=user)
            Message.objects.create(username=userid,
                                   type=u'信息修改',
                                   action=u'修改用户信息',
                                   action_ip=UserIP(request),
                                   content='修改%s用户信息' % username)
            return HttpResponseRedirect(reverse('listuserurl'))
    else:
        form = EditUserForm(instance=user)

    kwvars = {
        'ID': ID,
        'form': form,
        'request': request,
    }

    return render_to_response('users/user.edit.html', kwvars,
                              RequestContext(request))
예제 #8
0
def edit_profile(request):
    activate(request.user.extended.language)

    if request.method == 'POST':
        user_form = EditUserForm(data=request.POST,
                                 request=request,
                                 instance=request.user)
        profile_form = UserExtendedForm(data=request.POST,
                                        instance=request.user.extended)
        user_tz = request.POST.get('timezone')
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save(commit=False)
            new_pass = request.POST.get('new_password')
            do_redirect = False
            if len(new_pass) > 0:
                user.set_password(new_pass)
                do_redirect = True
            user.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            if user_tz:
                profile.timezone = user_tz
            profile.save()
            if 'sch_login' in request.POST and 'sch_password' in request.POST:
                if len(request.POST['sch_login']) > 0 and len(
                        request.POST['sch_password']) > 0:
                    from service.models import SchedulerUser
                    try:
                        sch_user = SchedulerUser.objects.get(user=request.user)
                    except ObjectDoesNotExist:
                        sch_user = SchedulerUser()
                        sch_user.user = request.user
                    sch_user.login = request.POST['sch_login']
                    sch_user.password = request.POST['sch_password']
                    sch_user.save()
                elif len(request.POST['sch_login']) == 0:
                    try:
                        request.user.scheduleruser.delete()
                    except ObjectDoesNotExist:
                        pass

            if do_redirect:
                return HttpResponseRedirect(reverse('users:login'))
            else:
                return HttpResponseRedirect(reverse('users:edit_profile'))
    else:
        user_form = EditUserForm(instance=request.user)
        profile_form = UserExtendedForm(instance=request.user.extended)

    from users.notifications import NotifyData
    return render(
        request, 'users/edit-profile.html', {
            'user_form': user_form,
            'tdata': NotifyData(request.user),
            'profile_form': profile_form,
            'profile_errors': profile_form.errors,
            'user_errors': user_form.errors,
            'timezones': pytz.common_timezones,
            'LANGUAGES': LANGUAGES
        })
예제 #9
0
def edit_profile(request):
    user=request.user
    users=User.objects.get(username=user)
    profile = Profile.objects.get(user=user)
    if request.method == 'POST':
        form1 = EditUserForm(request.POST, instance=users)
        # form2 = EditForm(request.POST)
        form2 = ProfileForm(request.POST, instance=profile)
        form3 = UserImageForm(request.POST, request.FILES)
        if form1.is_valid() and form2.is_valid() and form3.is_valid():
            if not form3.cleaned_data['profile_pic'] and form3.cleaned_data['cover_pic']:
                UserImage.objects.filter(user=user).update(is_active_cover = False)
            if not form3.cleaned_data['cover_pic'] and form3.cleaned_data['profile_pic']:
                UserImage.objects.filter(user=user).update(is_active_profile = False)
            if form3.cleaned_data['cover_pic'] and form3.cleaned_data['profile_pic']:
                UserImage.objects.filter(user=user).update(is_active_profile = False, is_active_cover= False)
            image = form3.save(commit=False)
            image.user = user
            image.is_active_profile = True
            image.is_active_cover = True
            image.is_public = True
            image.save()
            form2.save()
            form1.save()
            return HttpResponseRedirect('/home')
    else:
        form1 = EditUserForm(instance=users)
        form2 = ProfileForm(instance=profile)
        form3 = UserImageForm()

    variables = RequestContext(request, {'form1': form1, 'form2':form2, 'form3':form3})
 
    return render_to_response(
    'users/editprofile.html',
    variables,
    )
예제 #10
0
파일: views.py 프로젝트: binu456m/billing
def edit_user(request, pk):
    instance = get_object_or_404(
        Profile.objects.filter(pk=pk, is_deleted=False))

    if request.method == 'POST':
        form = EditUserForm(request.POST, instance=instance.user)
        profile = ProfileForm(request.POST, instance=instance)

        if form.is_valid() and profile.is_valid():

            #save auth user
            user_data = form.save(commit=False)
            user_data.save()

            #save profile
            profile_data = profile.save(commit=False)
            profile_data.updater = request.user
            profile_data.date_updated = datetime.datetime.now()
            profile_data.save()
            profile.save_m2m()

            request.session['message'] = 'User Successfully Edited'
            return HttpResponseRedirect(
                reverse('users:view_user', kwargs={'pk': instance.pk}))

        else:
            errors = generate_form_errors(form, formset=False)
            errors += generate_form_errors(profile, formset=False)
            context = {
                'message': 'Form Validation Error',
                'title': 'Edit Form',
                'form': form,
                'profile': profile,
                "errors": errors,
                "users_active": "active",
                'url': reverse('users:edit_user', kwargs={'pk': instance.pk}),
            }
            return render(request, 'users/entry_user.html', context)

    else:

        form = EditUserForm(instance=instance.user)
        profile = ProfileForm(instance=instance)

        context = {
            'title': 'Edit User' + instance.user.username,
            'form': form,
            'profile': profile,
            'instance': instance,
            'url': reverse('users:edit_user', kwargs={'pk': instance.pk}),
            "users_active": "active"
        }
        return render(request, 'users/entry_user.html', context)
예제 #11
0
def edit_profile(request):
    if request.method == 'POST':
        form_user = EditUserForm(data=request.POST, instance=request.user)
        form_profile = EditProfileForm(data=request.POST, files=request.FILES, instance=request.user.profile)
    else:
        form_user = EditUserForm(instance=request.user)
        form_profile = EditProfileForm(instance=request.user.profile)
    context = dict(
        form_user=form_user,
        form_profile=form_profile,
    )

    if request.method == 'POST' and form_user.is_valid() and form_profile.is_valid():
        form_user.save()
        form_profile.save()
        return redirect(reverse('users.profile'))
    return render(request, 'users/profile_edit.html', context)
예제 #12
0
파일: views.py 프로젝트: danielkjellid/puro
def editUser(request, pk):

    # Query appropriate user based on pk returned in url
    user = User.objects.get(pk=pk)

    # Get the EditUserForm and add the user as instance
    edit_user_form = EditUserForm(instance=user)

    if request.method == 'POST':

        # Bind data to the form class, and add the user as instance
        edit_user_form = EditUserForm(request.POST,
                                      error_class=DivErrorList,
                                      instance=user)

        old_user_instance = User.objects.get(pk=pk)

        # Validate form inputs
        if edit_user_form.is_valid():

            # Save edits
            edit_user_form.save()

            # Log change
            ChangeLog.change_message(request.user, User, old_user_instance)

            # Give the user successful feedback and redirect
            messages.success(request, successMessage('Redigering', 'bruker'))
            return redirect('user', pk)

        else:
            # If form inputs is invalid, give user feedback
            messages.error(
                request,
                'Det skjedde en feil ved redigering av bruker. Se detaljer nedenfor.'
            )

    context = {
        'user': user,
        'edit_user_form': edit_user_form,
    }

    # Render request, template and context
    return render(request, 'users/backend/user/user_edit.html', context)
예제 #13
0
def edit_user(request, id):

    form = EditUserForm()
    user = User.objects.get(id=id)

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

        if form.is_valid():

            user_form = form.save()
            custom_form = user.save(False)
            custom_form = user_form
            custom_form.save()
            return redirect('users')

    context = {
        'form': form,
    }
    return render(request, 'users/edit.html', context)
예제 #14
0
 def get(self, request):
     user_form = EditUserForm(instance=request.user)
     profile_form = EditProfileForm(instance=request.user.profile)
     args = {'user_form': user_form, 'profile_form': profile_form}
     return render(request, 'users/edit_profile.html', args)
예제 #15
0
def edit(request, slug):
    """Edit user page."""
    user = user_exists(slug)
    # Correct user
    if request.user.pk is not user.pk or not request.user.is_staff:
        return HttpResponseRedirect(reverse('readings.views.list_user', 
            args=[request.user.profile.slug]))
    profile = user.profile
    if request.method == 'POST':
        form = EditUserForm(request.POST, instance=user)
        profile_form = ProfileForm(request.POST, request.FILES, 
            instance=profile)
        if form.is_valid() and profile_form.is_valid():
            username = request.POST.get('username')
            password = request.POST.get('password1')
            # If user changed their password
            if password:
                user.set_password(password)
                user.save()
            user = form.save()
            # If an image is uploaded
            profile = profile_form.save()
            # If user changed their username
            if username:
                profile.slug = slugify(username)
                # if user has a profile image and checked clear image
                if profile.image and request.POST.get('clear_image'):
                    profile.image = ''
                    s3_delete_file(user)
                profile.save()
            if request.FILES.get('image'):
                file_path = settings.MEDIA_ROOT + '/' + profile.image.name
                try:
                    f = open(file_path)
                    f.close()
                    name = str(user.pk) + '_orig.jpg'
                    # Get absolute path of image
                    absolute_path = absolute_image_path(profile)
                    # Rename image
                    rename_image(name, absolute_path)
                    # Resize original image if too large
                    resize_orig_image(user)
                    # Create medium and small images
                    create_extra_images(user)
                    # Upload images to Amazon S3
                    s3_upload(user)
                    # Remove any old images
                    remove_images(user)
                    # Save profile image name
                    profile.image = name
                    profile.save()
                except IOError as e:
                    pass
            messages.success(request, 'User updated')
            return HttpResponseRedirect(reverse('readings.views.list_user', 
                args=[user.profile.slug]))
    else:
        form = EditUserForm(instance=user)
        profile_form = ProfileForm(instance=profile)
    d = {
            'title': 'Edit %s' % user.first_name,
            'form': form,
            'profile_form': profile_form,
    }
    return render_to_response('users/edit.html', add_csrf(request, d), 
        context_instance=RequestContext(request))