Пример #1
0
def edit_profile():

    if current_user.is_anonymous:
        return(redirect(url_for('cats.index')))

    contributor = Contributor.query.get(current_user.id)
    form = EditProfile()
    navbar_links = (('cancel', url_for('cats.index')), )

    if request.method == 'GET':
        form.username.data = contributor.name
        form.email.data = contributor.email

    if form.validate_on_submit():
        if contributor.check_password(form.password.data):
            contributor.name = form.username.data
            contributor.email = form.email.data
            db.session.commit()
            flash("Thanks for the update!")
            return(redirect(url_for('cats.index')))
        else:
            flash("Error Invalid Password")
            return(redirect(url_for('prof.edit_profile')))

    return render_template(
        'edit_profile.html',
        title='Edit Profile', form=form,
        contributor_use_totp=contributor.use_totp,
        navbar_links=navbar_links
    )
Пример #2
0
def edit_profile(request):
    '''
    If the user already edited the profile, then use that instance.
    Else, create a new entry.
    '''
    if UserProfile.objects.filter(user=request.user).exists():
        profile = UserProfile.objects.get(user=request.user)
    else:
        profile = None

    if request.method == 'POST':
        if profile:
            form = EditProfile(request.POST, instance=profile)
        else:
            form = EditProfile(request.POST)
        if form.is_valid():
            profile = form.save(commit=False)
            profile.user = request.user
            profile.save()
            messages.success(request, 'Form submission successful')
            return HttpResponseRedirect('/edit_profile/')
        else:
            messages.error(request, 'Form not valid')
    else:
        if profile:
            form = EditProfile(instance=profile)
        else:
            form = EditProfile()
    return render(request, 'registration/edit_profile.html', {'form': form})
Пример #3
0
def edit_profile():
    form = EditProfile(current_user.username)
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.about_me = form.about_me.data
        db.session.commit()
        flash("You changes have been saved.")
        return redirect(url_for('edit_profile'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me
    return render_template("edit_profile.html",
                           title='Edit Profile',
                           form=form)
Пример #4
0
    def test_profile_form_correct_input(self):
        User = get_user_model()
        self.client.login(username='******', password='******')
        user = User.objects.get(username='******')

        form = EditProfile(
            data={
                'user': user.id,
                'first_name': 'temp',
                'last_name': 'temp',
                'email': '*****@*****.**',
                'current_job': 'temp'
            })
        self.assertTrue(form.is_valid())
Пример #5
0
def profile():
    profileform = EditProfile()

    if profileform.validate_on_submit():
        user_id = profileform.username.data

        profile = {
            u'bio': profileform.bio.data,
        }
        db.collection(u'users').document(user_id).set(profile)
        return redirect(url_for('index'))

    return render_template("profile.html",
                           title='Edit Profile',
                           profileform=profileform)
Пример #6
0
def edit_profile():
    form = EditProfile(current_user.username)
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.fname = form.fname.data
        current_user.lname = form.lname.data
        current_user.about_me = form.about_me.data
        db.session.commit()
        flash('Settings have been updated.')
        return redirect(url_for('edit_profile'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.fname.data = current_user.fname
        form.lname.data = current_user.lname
        form.about_me.data = current_user.about_me
    return render_template('edit_profile.html', title='Settings', form=form)
Пример #7
0
def groupposts(groupid):
    commentform=Comment()
    uploadform=UploadProfilePic()
    form=CreatePost()
    grouppostinfo=[]
    groupinfo=db.engine.execute("SELECT * FROM groups join profiles on profiles.userid=groups.createdby WHERE groupid = '"+groupid+"'")
    groupmembers = db.engine.execute("SELECT * FROM joinsgroup JOIN users ON users.userid = joinsgroup.userid INNER JOIN profiles ON profiles.userid = users.userid JOIN gallery ON gallery.photoid = profiles.profilepic WHERE groupid = '"+groupid+"'")
    nonMembers = db.engine.execute("SELECT * FROM users u JOIN profiles p ON u.userid = p.userid INNER JOIN gallery g ON g.photoid = p.profilepic WHERE u.userid NOT IN (SELECT userid FROM joinsgroup WHERE groupid = "+groupid+") order by u.userid desc limit 20")
    ingroup=False
    for x in groupmembers:
        if(int(session['userid'])==x.userid):
            ingroup=True

    if(ingroup):
        groupposts=db.engine.execute("select user_post_log.postid, user_post_log.userid, content, ctype, postdatetime, profileno, profilepic, username, countryliving, photoid, photourl from user_post_log join (SELECT * FROM posts WHERE postid IN (SELECT postid FROM groupposts WHERE groupid = "+groupid+")) AS posts on posts.postid=user_post_log.postid INNER join profiles on profiles.userid=user_post_log.userid  INNER join gallery on profiles.profilepic=gallery.photoid order by posts.postid desc")
    else:
        groupposts=[]
    for a in groupinfo:
        creatorid = a.createdby
        groupname = a.groupname
        createddate = a.createddate
        groupcreator = a.username


    return render_template('groupPosts.html',editprofile=EditProfile(), form=form, uploadform=uploadform, searchform=SearchForm(),  creatorid=int(creatorid), groupid = groupid, groupname=groupname, groupmembers=groupmembers,nonMembers=nonMembers, createddate=createddate, commentform=commentform, creator=groupcreator, groupinfo=groupinfo, posts=groupposts,profilepic=session['profilepic'],fname=session['fname'],username= session['username'],lname=session['lname'],email=session['email'],location=session['location'],biography=session['biography'],followers=session['followers'],following=session['following'],userid=int(session['userid']))
Пример #8
0
def mygroups():
    createGroupForm = CreateGroupForm()
    userid=session['userid']
    groups=db.engine.execute("SELECT g.groupid, groupname, createdby, createddate FROM groups g INNER JOIN joinsgroup jg ON g.groupid = jg.groupid WHERE userid = '"+userid+"';")
    uploadform=UploadProfilePic()

    
    return render_template('mygroups.html',editprofile=EditProfile(),searchform=SearchForm(), uploadform=uploadform, createGroupForm=createGroupForm, groups=groups,profilepic=session['profilepic'],fname=session['fname'],username= session['username'],lname=session['lname'],email=session['email'],location=session['location'],biography=session['biography'],followers=session['followers'],following=session['following'],userid=session['userid'])
Пример #9
0
def searchuser():
    form=CreatePost()
    fform=FriendType()
    uploadform=UploadProfilePic()
    searcform=SearchForm()
    commentform=Comment()
    searchusername=searcform.username.data
    searchusers=db.engine.execute(" select username,photourl,firstname,lastname,countryliving,profile.userid from (SELECT username,countryliving,userid,profilepic FROM profiles WHERE lower(username) LIKE '"+searchusername.lower()+"%%') as profile inner join users on profile.userid=users.userid inner join gallery on gallery.photoid=profile.profilepic limit 10")
    return render_template('searchlist.html',editprofile=EditProfile(),uploadform=uploadform,searchusers=searchusers,searchform=SearchForm(), fform=fform,commentform=commentform,posts=posts,form=form,profilepic=session['profilepic'],fname=session['fname'],username= session['username'],lname=session['lname'],email=session['email'],location=session['location'],biography=session['biography'],followers=session['followers'],following=session['following'],userid=session['userid'])
Пример #10
0
def userposts(userid):
    form=CreatePost()
    fform=FriendType()

    commentform=Comment()
    users=db.engine.execute("select * from profiles join users on profiles.userid=users.userid where users.userid='"+userid+"'")
    # posts=db.engine.execute("select * from (select * from texts union select * from  images)as allpost join posts on posts.postid= allpost.postid join profiles on posts.userid=profiles.userid  where posts.userid='"+str(userid)+"' order by posts.postid desc")
    posts=db.engine.execute("select * from user_post_log join posts on posts.postid=user_post_log.postid where posts.userid='"+str(userid)+"' order by posts.postid desc")
   
    return render_template('profilepage.html',editprofile=EditProfile(),searchform=SearchForm(), fform=fform,commentform=commentform,posts=posts,form=form,users=users,profilepic=session['profilepic'],fname=session['fname'],username= session['username'],lname=session['lname'],email=session['email'],location=session['location'],biography=session['biography'],followers=session['followers'],following=session['following'],userid=session['userid'])
Пример #11
0
def userprofile(request):
    usercheck = user_permission_check(request)
    navbaruserp = True
    if request.GET.get('success') == str(1):
        successform = 1
    elif request.GET.get('success') == str(0):
        successform = 2
    user = request.user
    userprofiledata = UserProfile.objects.get(user_id=request.user.id)
    if request.method == "POST":
        form = EditProfile(request.POST)
        if form.is_valid():
            # email = form.cleaned_data['email']
            first_name = form.cleaned_data['first_name']
            last_name = form.cleaned_data['last_name']
            dob = form.cleaned_data['dob']

            userprofiledata.dob = dob
            userprofiledata.save()

            userdata = User.objects.get(id=user.id)
            userdata.first_name = first_name
            userdata.last_name = last_name
            # userdata.email = email
            userdata.save()
            context = {}
            send_mail(
                'Updated Profile Details',
                render_to_string('emails/updatedprofile.txt', context),
                sendingemailaddress,
                [user.email],
                fail_silently=True,
            )
            return HttpResponseRedirect("/userprofile?success=1")
        else:
            return HttpResponseRedirect("/userprofile?success=0")
    else:
        form = EditProfile()
    if PublicEcf.objects.filter(user_id=user).count() >= 1:
        userpubdata = PublicEcf.objects.get(user_id=user)
    else:
        pass
    return render(request, 'userprofile.html', locals())
Пример #12
0
def editprofile():
    editprofile=EditProfile()
    if request.method == "POST":
        username=editprofile.username.data
        if(username!=session['username']):
            db.engine.execute("update profiles set username='******' where userid="+session['userid'])
            session['username']=username

        lname=editprofile.lname.data
        if(lname!=session['lname']):
            db.engine.execute("update users set lastname='"+lname+"' where userid="+session['userid'])
            session['lname']=lname


        fname=editprofile.fname.data
        if(fname!=session['fname']):
            db.engine.execute("update users set firstname='"+fname+"' where userid="+session['userid'])
            session['fname']=fname


        email=editprofile.email.data
        if(email!=session['email']):
            db.engine.execute("update users set email='"+email+"' where userid="+session['userid'])
            session['email']=email


    
        # gender = editprofile.gender.data
        # if(email!=session['gender']):
        #     db.engine.execute("update")

        
        password =editprofile.password.data
        repassword = editprofile.repassword.data

        if(password!="" and repassword!="" and password==repassword):
            db.engine.execute("update users set password='******' where userid="+session['userid'])

        
        location = editprofile.location.data
        if(location!=session['location']):
            db.engine.execute("update profiles set countryliving='"+location+"' where userid="+session['userid'])
            session['location']=location


        # biography = editprofile.biography.data
        # if(biography!=""):
        #     db.engine.execute("update profiles set biography='"+biography+"'")

     

        return redirect(url_for('posts'))
    return render_template('editprofile.html',editprofile=editprofile,searchform=SearchForm(),profilepic=session['profilepic'],fname=session['fname'],username= session['username'],lname=session['lname'],email=session['email'],location=session['location'],biography=session['biography'],followers=session['followers'],following=session['following'],userid=session['userid'])
Пример #13
0
def posts():
    # form=CreatePost()
    commentform=Comment()


    form=CreatePost()
  
    posts=db.engine.execute("select * from user_post_log inner join posts on posts.postid=user_post_log.postid inner join friendship on friendship.fuserid=user_post_log.userid inner join profiles on profiles.userid=user_post_log.userid  inner join gallery on profiles.profilepic=gallery.photoid where friendship.userid="+session['userid']+"order by posts.postid desc")
    uploadform=UploadProfilePic()

    
    return render_template('posts.html',editprofile=EditProfile(),searchform=SearchForm(), uploadform=uploadform,commentform=commentform,posts=posts,form=form,profilepic=session['profilepic'],fname=session['fname'],username= session['username'],lname=session['lname'],email=session['email'],location=session['location'],biography=session['biography'],followers=session['followers'],following=session['following'],userid=session['userid'])
Пример #14
0
def friendlist(userid):
    friends=db.engine.execute("select * from friendship join users on users.userid=friendship.fuserid join profiles on profiles.userid=users.userid join gallery on gallery.photoid=profiles.profilepic where friendship.userid='"+userid+"' ")
    work=db.engine.execute("select * from friendship join users on users.userid=friendship.fuserid join profiles on profiles.userid=users.userid join gallery on gallery.photoid=profiles.profilepic where ftype='Work' AND friendship.userid='"+userid+"' ")
    school=db.engine.execute("select * from friendship join users on users.userid=friendship.fuserid join profiles on profiles.userid=users.userid join gallery on gallery.photoid=profiles.profilepic where ftype='School' AND friendship.userid='"+userid+"' ")
    relatives=db.engine.execute("select * from friendship join users on users.userid=friendship.fuserid join profiles on profiles.userid=users.userid join gallery on gallery.photoid=profiles.profilepic where ftype='Relatives' AND friendship.userid='"+userid+"' ")
    # need to choice which one is more optimized
    # select * from friendship join users on users.userid=friendship.fuserid join profiles on profiles.userid=users.userid where friendship.userid=2;

    # select * from users join ((select fuserid,ftype from friendship where userid=2) as friends join (select userid,profileno,profilepic,username,biography,countryliving from profiles)as profile on profile.userid=friends.fuserid) as friend on friend.fuserid=users.userid;
    uploadform=UploadProfilePic()

    return render_template('friendslist.html',editprofile=EditProfile(), searchform=SearchForm(), uploadform=uploadform,work=work, school=school, relatives=relatives, friends=friends,profilepic=session['profilepic'],fname=session['fname'],username= session['username'],lname=session['lname'],email=session['email'],location=session['location'],biography=session['biography'],followers=session['followers'],following=session['following'],userid=session['userid'])
Пример #15
0
def userprofile(request):

    user_id = request.GET.get('userid', '')

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

    reviews = Review.objects.filter(author_id=user_id)

    print(request.POST)
    print(request.method)

    form = EditProfile(request.POST, request.FILES)
    if request.method == 'POST':

        print(form.errors)
        if form.is_valid():
            print(request.FILES)
            usr = the_user
            usr.img = request.FILES["img"]
            usr.save()
    try:

        print("request.user: "******"User get: " + the_user.authentication.username)

        form = EditProfile if str(request.user) == str(
            the_user.authentication.username) else ''
    except User.DoesNotExist:
        form = ''

    if user_id:
        return render(request, 'userprofile.html', {
            'user': the_user,
            'reviews': reviews,
            'editform': form
        })
    else:
        return render(request, 'userprofile.html', {})
Пример #16
0
def myprofile():
    form=CreatePost()

    fform=FriendType()
    commentform=Comment()
    uploadform=UploadProfilePic()
    users=db.engine.execute("select * from profiles join users on profiles.userid=users.userid join gallery on gallery.photoid=profiles.profilepic where users.userid='"+session['userid']+"'")
    # posts=db.engine.execute("select * from (select * from texts union select * from  images)as allpost join posts on posts.postid= allpost.postid join profiles on posts.userid=profiles.userid  where posts.userid='"+str(userid)+"' order by posts.postid desc")
    posts=db.engine.execute("select * from user_post_log join posts on posts.postid=user_post_log.postid  join profiles on profiles.userid=user_post_log.userid  join gallery on profiles.profilepic=gallery.photoid where profiles.userid='"+str(session['userid'])+"' AND user_post_log.postid NOT IN(SELECT postid FROM groupposts) order by posts.postid desc")
    postsCounts= db.engine.execute("SELECT COUNT(postid) AS post_counts FROM user_post_log  where userid="+session['userid']+" and postid NOT IN(select postid from groupposts)")
    for x in postsCounts:
        postcount=x.post_counts

    return render_template('myprofilepage.html',postcount=postcount,editprofile=EditProfile(),searchform=SearchForm(), form=form,uploadform=uploadform,commentform=commentform,fform=fform,posts=posts,users=users,profilepic=session['profilepic'],fname=session['fname'],username= session['username'],lname=session['lname'],email=session['email'],location=session['location'],biography=session['biography'],followers=session['followers'],following=session['following'],userid=session['userid'])
Пример #17
0
def creategroup():
    createGroupForm = CreateGroupForm()
    userid=session['userid']
    groups=db.engine.execute("SELECT g.groupid, groupname, createdby, createddate FROM groups g INNER JOIN joinsgroup jg ON g.groupid = jg.groupid WHERE userid = '"+userid+"';")
    uploadform=UploadProfilePic()

    if request.method == "POST":
        groupname = createGroupForm.groupname.data
        time = datetime.datetime.now()
        time = time.strftime("%Y-%m-%d %H:%M:%S")
        db.engine.execute("INSERT INTO  groups(groupname,createdby, createddate) values('"+groupname+"','"+str(userid)+"','"+time+"');")
        lastGroupID= db.engine.execute("SELECT groupid FROM groups ORDER BY groupid DESC LIMIT 1")
        for last in lastGroupID:
            groupid=last.groupid

        time = datetime.datetime.now()
        time = time.strftime("%Y-%m-%d %H:%M:%S")
        db.engine.execute("INSERT INTO joinsGroup (groupid,userid,status,joindate) values('"+str(groupid)+"','"+userid+"','Editor','"+time+"');")
        flash("You just created the '"+groupname+"' MyBook Group" , "success")


    
    return render_template('mygroups.html',editprofile=EditProfile(),searchform=SearchForm(), uploadform=uploadform, createGroupForm=createGroupForm, groups=groups,profilepic=session['profilepic'],fname=session['fname'],username= session['username'],lname=session['lname'],email=session['email'],location=session['location'],biography=session['biography'],followers=session['followers'],following=session['following'],userid=session['userid'])
Пример #18
0
def profile(userid):
    friendship=False
    form=FriendType()
    commentform=Comment()
    uploadform=UploadProfilePic()
    users=db.engine.execute("select * from profiles join users on profiles.userid=users.userid join gallery on gallery.photoid=profiles.profilepic where users.userid='"+userid+"'")
    # posts=db.engine.execute("select * from (select * from texts union select * from  images)as allpost join posts on posts.postid= allpost.postid join profiles on posts.userid=profiles.userid  where posts.userid='"+str(userid)+"' order by posts.postid desc")
    # checking if loggedin user  is friends with the userid
    friends=db.engine.execute("select * from friendship where userid="+str(session['userid'])+"and fuserid="+str(userid))
    for x in friends:
        friendship=True

    if(friendship):
        posts=db.engine.execute("select * from user_post_log join posts on posts.postid=user_post_log.postid  join profiles on profiles.userid=user_post_log.userid  join gallery on profiles.profilepic=gallery.photoid where profiles.userid='"+str(userid)+"' order by posts.postid desc")
    else:
        posts=[]
    postsCounts= db.engine.execute("SELECT COUNT(postid) AS post_counts FROM user_post_log  where userid="+userid+" and postid NOT IN(select postid from groupposts)")
    for x in postsCounts:
        postcount=x.post_counts
    friends=db.engine.execute("select count(userid) as following from friendship where fuserid='"+userid+"'")  
    for x in friends:
                # print(x.following)
        userfollower=x.following
    return render_template('profilepage.html',userfollower=userfollower,postcount=postcount,editprofile=EditProfile(),searchform=SearchForm(), uploadform=uploadform,commentform=commentform,fform=form,posts=posts,users=users,profilepic=session['profilepic'],fname=session['fname'],username= session['username'],lname=session['lname'],email=session['email'],location=session['location'],biography=session['biography'],followers=session['followers'],following=session['following'],userid=session['userid'])
Пример #19
0
 def test_profile_form_email_help_text(self):
     form = EditProfile()
     self.assertEqual(form.fields['email'].help_text,
                      "Provide an email peers can reach you at.")
Пример #20
0
 def test_profile_form_current_job_help_text(self):
     form = EditProfile()
     self.assertEqual(
         form.fields['current_job'].help_text,
         "Current job or status (e.g. software engineer, student, entrepreneur)"
     )
Пример #21
0
def grouplist():
    
    groups=db.engine.execute("SELECT * FROM groups;")
    uploadform=UploadProfilePic()

    return render_template('grouplist.html',editprofile=EditProfile(),searchform=SearchForm(), uploadform=uploadform, groups=groups,profilepic=session['profilepic'],fname=session['fname'],username= session['username'],lname=session['lname'],email=session['email'],location=session['location'],biography=session['biography'],followers=session['followers'],following=session['following'],userid=session['userid'])