Example #1
0
File: view.py Project: abideev/tsj
def user_panel_profile():
    form = UpdateProfile()

    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(
                form.picture.data
            )  # save_picture is the function created above
            current_user.image_file = picture_file

        if form.email.data != current_user.email:
            user_check = user.query.filter_by(email=form.email.data).first()
            if user_check:
                flash(
                    'Такой email уже используется в системе! Введите другой email'
                )
                return redirect(url_for('user_panel_profile'))

        current_user.phone = form.phone.data
        current_user.email = form.email.data
        db.session.commit()
        flash('Ваш профиль был обновлен', 'success')
        return redirect(url_for('user_panel_profile'))

    elif request.method == 'GET':
        form.phone.data = current_user.phone
        form.email.data = current_user.email

    image_file = url_for('static',
                         filename='avatars/' + current_user.image_file)
    return render_template('UserPanel/profile.html',
                           image_file=image_file,
                           form=form,
                           current_user=current_user)
Example #2
0
def edit_userpage(request):
    user = request.user
    print 'outside'
    if user.is_authenticated:
        print 'is authed'
        username = user.username
        try:
            print 'try'
            profile = UserProfile.objects.get(user_id=user.id)
            print profile
            picture = profile.profile_image.url
            interests = profile.interests
            accomodation = profile.accomodation
            about = profile.about
            twitter = profile.twitter
            facebook = str(profile.facebook)
            telegram = profile.telegram
        except Exception as err:
            print err
            interests = 'interests'
            picture = 'static_dev/img/default_profile_picture.jpg'
            accomodation = 'accomodation'
            about = 'about'
            twitter = '@username'
            facebook = 'user name'
            telegram = '@username'
        if request.method == 'POST':
            print user.id
            profileID = UserProfile.objects.get(user_id=user.id)
            print profileID
            profile_form = UpdateProfile(request.POST,
                                         request.FILES,
                                         instance=profileID)
            if profile_form.is_valid():
                instance = profile_form.save(commit=False)
                print 'instance %s' % profile_form
                print 'FILES: ', request.FILES
                if 'image' in request.FILES:
                    instance.profile_image = request.FILES['image']
                instance.save()
                return HttpResponseRedirect('/userpage/')
            else:
                print profile_form.errors

        context = {
            'username': username,
            'picture': picture,
            'interests': interests,
            'accomodation': accomodation,
            'about': about,
            'twitter': twitter,
            'facebok': str(facebook),
            'telegram': telegram,
        }
        return render(request, 'users/edit_userpage.html', context)
    else:
        return HttpResponseRedirect('/')
Example #3
0
def update_profile(request):
    args = {}

    if request.method == 'POST':
        form = UpdateProfile(request.POST, instance=request.user)
        if form.is_valid():
            form.save()
            return render(request, 'forms/hello.html')
    else:
        form = UpdateProfile()

    args['form'] = form
    return render(request, 'forms/update_profile.html', args)
Example #4
0
def update_profile(request):

    user = User.objects.get(pk=request.user.id)
    obj1 = UserProfile.objects.get(user=user)
    if request.POST:
        user = User.objects.get(pk=request.user.id)
        obj1 = UserProfile.objects.get(user=user)
        user.first_name = request.POST.get('first_name')
        user.last_name = request.POST.get('last_name')
        user.username = request.POST.get('username')
        user.email = request.POST.get('email')
        obj1.picture = request.FILES['picture']
        obj1.website = request.POST.get('website')

        user.save()
        obj1.save()

        return redirect('/forum/profile/?msg=ok')
        #return render(request,'profile.html',{'updated':updated})
    form = UpdateProfile(instance=user)
    form1 = UpdateImage(instance=obj1)
    return render_to_response('update_profile.html', {
        'form': form,
        'form1': form1
    },
                              context_instance=RequestContext(request))
Example #5
0
def update_profile(id):
    user = load_user(current_user.get_id())
    profile = Profile.query.filter_by(profile_id=id, user_id=user.user_id)

    if profile.count() != 1:
        flash("Can't find profile")
        return redirect(url_for("web_profiles.show_profiles"))

    form = UpdateProfile(obj=profile.first())
    if form.validate_on_submit():
        data = {
            "name": form.name.data,
            "restrictions": form.restriction.data
        }
        fields = profile_schema.load(data, partial=True)
        profile.update(fields)
        db.session.commit()
        flash("Profile updated!")
        return redirect(url_for("web_profiles.show_profiles"))

    return render_template("update_profile.html", form=form, id=id)
Example #6
0
def edit_profile(hiker_id):
    profile_to_edit = Hiker.objects.get({'_id': ObjectId(hiker_id)})
    form = UpdateProfile(obj=profile_to_edit)
    if form.validate_on_submit():
        try:
            Hiker.objects.raw({"_id": ObjectId(hiker_id)}).update(
                {"$set": {"fname": form.fname.data,
                          "lname": form.lname.data,
                          "origin": form.origin.data,
                          "email": form.email.data,
                          "trails_completed": form.trails_completed.data,
                          "profile_pic": form.profile_pic.data
                          }
                 }, upsert=False)
            flash("Profile Updated Successfully.", 'teal')
            return redirect(url_for('index'))
        except ValidationError as ve:
            errors = ve.message
            flash(errors, 'deep-orange darken-3')
    return render_template('trails/edit_profile.template.html', form=form,
                           profile=profile_to_edit, cloud_name=CLOUD_NAME,
                           upload_preset=UPLOAD_PRESET, api_key=API_KEY)
Example #7
0
def update_profile(request):
    args = {}

    if request.method == 'POST':
        form = UpdateProfile(request.POST, instance=request.user)
        if form.is_valid():
            form.save()
            return render(request, 'forms/hello.html')
    else:
        form = UpdateProfile()

    args['form'] = form
    return render(request, 'forms/update_profile.html', args)
Example #8
0
def profile():
    '''queries all the posts from database '''
    posts = Post.query.all()
    ''' form for updating profile , which updates profile picture of user'''
    form = UpdateProfile()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            '''saves the picture given by user'''
            current_user.image_file = picture_file
            ''' sets the user profile as the inputed image'''
        db.session.commit()
        ''' commits the changes done in database '''
        flash('Your account has been updated!', 'success')
        ''' flashes message on successfully updating profile picture '''
        return redirect(url_for('profile'))

    image_file = url_for('static',
                         filename='profile_pics/' + current_user.image_file)
    ''' sets the profile picture as updated(if updated) image'''
    return render_template('profile.html',
                           image_file=image_file,
                           form=form,
                           posts=posts)