def rebuild(): if config == 'development': with app.app_context(): db.drop_all() db.create_all() Role.insert_roles() admin_me = User(email=app.config['FLASKR_ADMIN'], username=app.config['MY_USERNAME'], password=app.config['MY_PASSWORD'], confirmed=True, name=forgery_py.name.full_name(), location=forgery_py.address.city(), about_me=forgery_py.lorem_ipsum.sentences(10), member_since=forgery_py.date.date(True, min_delta=10)) db.session.add(admin_me) ordinary_me = User(email=forgery_py.internet.email_address(), username='******', password='******', confirmed=True, name=forgery_py.name.full_name(), location=forgery_py.address.city(), about_me=forgery_py.lorem_ipsum.sentences(10), member_since=forgery_py.date.date(True, min_delta=10)) db.session.add(ordinary_me) db.session.commit() User.generate_fake(30) Post.generate_fake(500) Follow.generate_fake(500) Comment.generate_fake(500) else: print('Permission denied.')
def reset(): """重置数据库""" print('开始重置数据库...') print('清空数据库...') db.drop_all() print('创建数据库...') db.create_all() print('生成角色...') Role.insert_roles() print('生成我...') u = User(wow_faction='联盟', wow_race='暗夜精灵', wow_class='德鲁伊', username='******', email='*****@*****.**', password='******', confirmed=True, wow_title='野蛮角斗士', location='试炼之环', about_me='非著名猫德') u2 = User(wow_faction='部落', wow_race='兽人', wow_class='萨满祭司', username='******', email='*****@*****.**', password='******', role=Role.query.filter_by(name='官员').first(), confirmed=True, wow_title='神出鬼没的', location='奥格瑞玛', about_me='部落精神领袖,世界萨') u3 = User(username='******', email='*****@*****.**', password='******', role=Role.query.filter_by(name='官员').first(), confirmed=True, location='冬泉谷', about_me='这封信上写的什么?') db.session.add_all((u, u2, u3)) db.session.commit() print('生成小弟...') User.generate_fake(100) u = User(wow_faction='部落', wow_race='血精灵', wow_class='法师', username='******', email='*****@*****.**', avatar='../static/wow/task/kaelthas0.png', password='******', location='奎尔萨拉斯', wow_title="迷失的", about_me="魔法,能量。我的人民陷入其中不能自拔,自从太阳之井被摧毁之后就是如此。欢迎来到未来!真遗憾,你们无法阻止什么,没有人可以阻止我了!Selama ashal'anore......") db.session.add(u) db.session.commit() User.generate_fake(100) print('生成文章...') Post.generate_fake(200) print('生成评论...') Comment.generate_fake(5, 15) print('生成关注...') Follow.generate_fake(5, 20) print('生成自关注...') User.add_self_follows() def generate_likes_and_collections(): from random import randint for i in range(1000): u = User.query.get(randint(1, User.query.count())) u2 = User.query.get(randint(1, User.query.count())) if u.username == '凯尔萨斯之魂' or u2.username == '凯尔萨斯之魂': continue c = Comment.query.get(randint(1, Comment.query.count())) p = Post.query.get(randint(1, Post.query.count())) if c not in u.comments_like: u.comments_like.append(c) c.likes += 1 db.session.add(u) if p not in u2.posts_collected: u2.posts_collected.append(p) p.collects += 1 db.session.add(u2) db.session.add(p) db.session.commit() print('生成点赞和收藏...') generate_likes_and_collections() print('重置数据库完成,谢谢使用!') quit()
def setUpClass(cls): try: cls.client = webdriver.Chrome('/usr/lib/chromium-browser/chromedriver') except: pass if cls.client: cls.app = create_app('testing') cls.app_context = cls.app.app_context() cls.app_context.push() import logging logger = logging.getLogger('werkzeug') logger.setLevel("ERROR") db.create_all() Role.insert_roles() User.generate_fake(10) Post.generate_fake(10) Comment.generate_fake(3, 5) Follow.generate_fake(3, 5) admin_role = Role.query.filter_by(name='Administrator').first() admin = User(role=admin_role, email='*****@*****.**', username='******', password='******', confirmed=True) db.session.add(admin) db.session.commit() threading.Thread(target=cls.app.run).start()
def fake(): from flask_migrate import upgrade from app.models import Role, User #User.generate_fake(30) #Post.generate_fake(200) #Comment.generate_fake(3000) Follow.generate_fake(1000)
def followeReq(followedId): reqData = request.json newFollow = Follow() newFollow.followed_id = followedId newFollow.follower_id = reqData['userId'] db.session.add(newFollow) db.session.commit() return "New followe added"
def test_following(self): u1 = User.create(username='******') u2 = User.create(username='******') u3 = User.create(username='******') f1 = Follow.create(b=u2) u1.following.append(f1) f2 = Follow.create(b=u3) u1.following.append(f2) exp = [u2, u3] self.assertEqual(u1.get_following(), exp)
def generate_fake(): """Generate fake data""" Role.insert_roles() admin = User(email='*****@*****.**', password='******', confirmed=True, username='******') db.session.add(admin) db.session.commit() print('Inserting admin user: [email protected]') User.generate_fake() Post.generate_fake() Comment.generate_fake() Follow.generate_fake()
def test_followers(self): u1 = User.create(username='******') u2 = User.create(username='******') u3 = User.create(username='******') f2 = Follow.create(b=u2) u1.following.append(f2) f2 = Follow.create(b=u2) u3.following.append(f2) u1.save() u3.save() exp = [u1, u3] self.assertEqual(u2.get_followers(), exp)
def follow_user(user_id): data = request.json print(data) # the person to be followed. Obtaining info from the POST body rather than the route params target_id = data["follower_id"] user_id = getUserID() tar_user = User.query.get(target_id) # ensure the target user exists in the db and that the user isn't trying to follow his/herself if tar_user and target_id != user_id: # check if user is already following target user follow = Follow.query.filter_by(user_id=user_id, follower_id=target_id).first() if follow == None: follow = Follow(user_id, target_id) db.session.add(follow) db.session.commit() return jsonify({"message": "You are now following that user"}) else: # unfollow db.session.delete(follow) db.session.commit() followers = Follow.query.filter_by(follower_id=target_id).count() return jsonify( {"message": "You are no longer following that user"}) # return jsonify({'code': -1, "message": "You are already following that user", 'errors': []}) else: return jsonify({ 'code': -1, 'message': 'Target user does not exist/User cannot follow oneself', 'errors': [] })
def follow_user(current_user, user_id): """Creates a relationship where the currently logged in user follows the user with id <user_id> """ user = User.query.filter_by(id=user_id).first() if user == None: return jsonify({'error': 'This user does not exist'}) if request.method == 'POST': follower_id = current_user.id pre_existing_relationship = Follow.query.filter_by( follower_id=follower_id, userid=user_id).first() if pre_existing_relationship == None: follow_relationship = Follow(follower_id=follower_id, userid=user_id) print(follow_relationship) db.session.add(follow_relationship) db.session.commit() response = { 'message': 'You are now following that user', 'newRelationship': 'true' } return jsonify(response) else: response = { 'message': 'You are already following that user', 'newRelationship': 'false' } print(response) return jsonify(response)
def fixture(): for i in range(5): user = User("user" + str(i), i, "user" + str(i) + "@ynov.com", "aaaa", "default.png") receive = User("user1" + str(i), i, "user" + str(i) + "@ynov.com", "aaaa", "default.png") db.session.add(user) db.session.add(receive) db.session.commit() follow = Follow(user, receive) db.session.add(follow) db.session.commit() for j in range(5): post = Post("post" + str(i), "vdbziego", "default.png", '2019-01-16 00:00:00', '2019-01-16 00:00:00', user) db.session.add(post) user.like.append(post) commentary = Comment(content="blabla", publication_date='2019-01-16 00:00:00') commentary.post = post user.comment.append(commentary) for k in range(5): message = Message('message' + str(k), '2019-01-16 00:00:00', user, receive) db.session.add(message) return 'fixtures'
def follow(): result = True data = request.get_data().decode('utf-8') data = json.loads(data) follower_id = int(data['follower']) followed_id = int(data['followed']) opt = data['opt'] follower = UserInfo.query.get_or_404(follower_id) followed = UserInfo.query.get_or_404(followed_id) print('=============================================') try: if opt == 'following': follow = Follow(follower=follower,followed=followed) db.session.add(follow) else: f = follower.followed.filter_by(followed_id=followed_id).first() if f: db.session.delete(f) # else: # f = follower.followed.filter(followed_id=followed_id) # db.session.delete(f) except Exception as e: result = False db.session.rollback() print('关注对象时出错 ! ') print(e) return jsonify({'result':result})
def follow(): req_json = request.get_json() following_user_id = req_json.get("user_id") my_user_id = g.get("user_id") my_username = session.get("username") if not following_user_id: return jsonify(re_code=400, msg="参数不完整") try: user = User.query.get(following_user_id) except Exception as e: current_app.logger.error(e) user = None if not user: return jsonify(re_code=400, msg="查询不到当前要关注的用户") try: ip_addr = request.remote_addr # 获取用户的ip operate_detail = "用户id:%r,用户名:%s,关注了id:%r,用户名:%s" % ( my_user_id, my_username, user.id, user.username) user_operate_log = UserOperateLog(user_id=user.id, ip=ip_addr, detail=operate_detail) try_follow = Follow(follower_id=my_user_id, followed_id=following_user_id) db.session.add(user_operate_log) db.session.add(try_follow) db.session.commit() return jsonify(re_code=200, msg="关注用户成功 !") except Exception as e: current_app.logger.error(e) db.session.rollback() return jsonify(re_code=400, msg="数据库失败,关注用户失败,请稍后重试")
def follow(user_id): current_user = get_jwt_identity() follower = UserProfile.query.filter_by(username=current_user).first() follower_id = follower.id new_follower = Follow(user_id, follower_id) db.session.add(new_follower) db.session.commit() return jsonify({'message': 'Following'}), 200
def followAndUnfollow(self, request): account = request.data.get("account") account_other = request.data.get("account_other") relation = models.Follow.objects.filter(follower_account=account, followed_account=account_other) Follow = models.Follow() if len(relation) == 0: Follow.follower_account = User.objects.get(account = account) Follow.followed_account = User.objects.get(account = account_other) Follow.save() return JsonResponse({"status": 1}) # 状态码为1,表示关注成功 elif len(relation) == 1: relation.delete() return JsonResponse({"status": 0}) # 状态码为0,表示取关成功 else: return JsonResponse({"status": -1}) # 状态码为-1,表示异常
def follow(username): user=User.query.filter_by(username=username).first() if user is not None and not current_user.is_following(user): follow=Follow( followed_id=user.id, follower_id=current_user.id ) db.session.add(follow) return redirect(url_for('main.profile',username=username))
def init_db(): print 'drop all tables...', db.drop_all() print 'done\ncreate all tables...', db.create_all() print 'done\ninsert roles...', Role.insert_roles() print 'done\ninsert me...', generate_me() print 'done\ninsert users...', User.generate_fake() print 'done\ninsert follows...', Follow.generate_fake() print 'done\ninsert posts...', Post.generate_fake() print 'done\ninsert comments...', Comment.generate_fake() print 'done'
def follow_user(user_id): user = g.current_user #adding to the followers database follow = Follow(user_id, user['sub']) db.session.add(follow) db.session.commit() return make_response( jsonify({'message': 'You are now following that user'}), 201)
def follow(): session_user_id = request.json['session_user_id'] follow_user_id = request.json['follow_user_id'] following = request.json['following'] if following: old_follow = Follow.query \ .filter(Follow.follower_id == session_user_id, Follow.followee_id == follow_user_id) \ .first() db.session.delete(old_follow) db.session.commit() return old_follow.to_dict() else: new_follow = Follow(follower_id=session_user_id, followee_id=follow_user_id) db.session.add(new_follow) db.session.commit() return new_follow.to_dict()
def generateData(numUser,numCategory,numBlog): User.fake(numUser) Follow.fake(numUser) Category.fake(numCategory) Blog.fake(numBlog,numUser) Comment.fake(numBlog,numUser) BlogCategory.fake(numBlog,numCategory*5) BlogLabel.fake(numBlog) BlogLike.fake(numBlog*20,numUser,numBlog) CommentLike.fake(numBlog*30,numUser,numBlog*8) Collection.fake(numBlog*10,numUser,numBlog)
def article(id): article = Article.query.get_or_404(id) if not article.published: abort(403) next = next_article(article) prev = prev_article(article) form = CommentForm(request.form, follow_id=-1) if form.validate_on_submit(): followed_id = int(form.follow_id.data if form.follow_id.data else -1) reply_to = form.follow.data content = form.content.data if reply_to: content = form.content.data.replace("@" + reply_to + " ", "") comment = Comment(article=article, content=content, author_name=form.name.data, author_email=form.email.data) db.session.add(comment) db.session.commit() if followed_id != -1: followed = Comment.query.get_or_404(followed_id) f = Follow(follower=comment, followed=followed) comment.comment_type = 'reply' # comment.reply_to = followed.author_name comment.reply_to = reply_to if reply_to else followed.author_name db.session.add(f) db.session.add(comment) db.session.commit() # flash(u'提交评论成功!', 'success') return redirect(url_for('.article', id=article.id, page=-1)) # if form.errors: # flash(u'发表评论失败', 'danger') page = request.args.get('page', 1, type=int) counts = article.comments.count() if page == -1: page = int((counts - 1) / Comment.PER_PAGE + 1) pagination = article.comments.order_by(Comment.created.asc()).paginate( page, per_page=Comment.PER_PAGE, error_out=False) comments = pagination.items return render_template('article.html', article=article, category_id=article.category_id, next_article=next, prev_article=prev, comments=comments, counts=counts, pagination=pagination, form=form, endpoint='.article', id=article.id)
def fake_follow(): """Generating some random following relationship.""" user_count = User.query.count() for b in range(500): follower = User.query.offset(randint(0, user_count - 1)).first() followed = User.query.offset(randint(0, user_count - 1)).first() follow_ship = Follow(follower=follower, followed=followed) db.session.add(follow_ship) db.session.commit() return True
def settings(): fbform = AddFbForm(request.form) twform = AddTwitterForm(request.form) accform = AddAccForm(request.form) u = flask_login.current_user if twform.validate_on_submit(): acc = TwitterAccount(username=twform.twacc.data) u.accounts.append(acc) u.save() flash("Twitter acount added!", "success") return redirect(url_for(".settings")) if fbform.validate_on_submit(): acc = FacebookAccount(url=fbform.fburl.data) u.accounts.append(acc) u.save() flash("Facebook acount added!", "success") return redirect(url_for(".settings")) if accform.validate_on_submit(): print(accform.user) print(u.following) # http://docs.sqlalchemy.org/en/latest/orm/basic_relationships.html#association-object f = Follow(a_id=u.id, b_id=accform.user.id) f.a = u f.b = accform.user f.save() flash("You follow " + accform.user.username + " now", "success") return redirect(url_for(".settings")) twaccounts = u.get_twitter_accounts() fbaccounts = u.get_facebook_accounts() return render_template('user/settings.html', fbform=fbform, twform=twform, twaccounts=twaccounts, fbaccounts=fbaccounts, accform=accform, following=u.get_following(), followers=u.get_followers())
def follow(): form = FollowForm() if form.validate_on_submit(): to_follow = Follow(code=form.station_id.data.upper(), text_alert=form.text_alert.data, email_alert=form.email_alert.data, user_id=current_user.id) db.session.add(to_follow) db.session.commit() flash( f'Congratulations, you are now following {form.station_id.data}!') return redirect(url_for('index')) return render_template('follow.html', title='Follow', form=form)
def follow_user(current_user, user_id): """Creates a relationship where the currently logged in user follows the user with id <user_id> """ user = User.query.filter_by(id=user_id).first() if user == None: return jsonify({'error': 'This user does not exist'}) if request.method == 'POST': follower_id = current_user.id follow_relationship = Follow(follower_id=follower_id, userid=user_id) db.session.add(follow_relationship) db.session.commit() response = {'follower_id': follower_id, 'user_id': user_id} return jsonify(response) return jsonify_errors(['Only POST requests are accepted'])
def seed_follows(): follow1 = Follow(followee_id=1, follower_id=2) follow2 = Follow(followee_id=1, follower_id=3) follow3 = Follow(followee_id=1, follower_id=4) follow4 = Follow(followee_id=2, follower_id=1) follow5 = Follow(followee_id=2, follower_id=4) follow6 = Follow(followee_id=3, follower_id=4) follow7 = Follow(followee_id=4, follower_id=3) db.session.add(follow1) db.session.add(follow2) db.session.add(follow3) db.session.add(follow4) db.session.add(follow5) db.session.add(follow6) db.session.add(follow7) db.session.commit()
def test_followed_posts(self): user1 = User(email="*****@*****.**", username="******", password="******") user2 = User(email="*****@*****.**", username="******", password="******") db.session.add(user1) db.session.add(user2) db.session.commit() post = Post(title="test", body="test") post.user = user2 db.session.add(post) db.session.commit() follow = Follow(follower_id=user1.id, followed_id=user2.id) db.session.add(follow) db.session.commit() res = self.open_with_auth("api/followedposts", "get", "test1", "test") self.assertTrue(res["all_posts"] == 1)
def follow(user_id): form = FollowForm() if form.validate_on_submit(): follower_id = form.follower_id.data follow = Follow(user_id, follower_id) try: db.session.add(follow) db.session.commit() response = {'message': 'You are now following that user.'}, 200 except: response = {'errors': ['You are already following that user.']}, 400 else: response = {'errors': form_errors(form)}, 400 return jsonify(response[0]), response[1]
def test_user_follow(self): user1 = User(email="*****@*****.**", username="******", password="******") user2 = User(email="*****@*****.**", username="******", password="******") db.session.add(user1) db.session.add(user2) db.session.commit() follow = Follow(follower_id=user1.id, followed_id=user2.id) db.session.add(follow) db.session.commit() res = self.client.get("api/user/" + str(user2.username) + "/followers") res = json.loads(res.data) self.assertTrue(res["all_users"] == 1) res = self.client.get("api/user/" + str(user1.username) + "/followings") res = json.loads(res.data) self.assertTrue(res["all_users"] == 1)
def contact(): form = CommentForm(request.form, follow_id=-1) if form.validate_on_submit(): followed_id = int(form.follow_id.data if form.follow_id.data else -1) reply_to = form.follow.data content = form.content.data if reply_to: content = form.content.data.replace("@" + reply_to + " ", "") comment = Comment(content=content, author_name=form.name.data, author_email=form.email.data, comment_type='contact') db.session.add(comment) db.session.commit() if followed_id != -1: followed = Comment.query.get_or_404(followed_id) f = Follow(follower=comment, followed=followed) comment.comment_type = 'reply' # comment.reply_to = followed.author_name comment.reply_to = reply_to if reply_to else followed.author_name db.session.add(f) db.session.add(comment) db.session.commit() # flash(u'提交评论成功!', 'success') return redirect(url_for('.contact', page=-1)) page = request.args.get('page', 1, type=int) _query = Comment.query.filter_by(comment_type='contact') counts = _query.count() if page == -1: page = int((counts - 1) / Comment.PER_PAGE + 1) pagination = _query.order_by(Comment.created.asc()).paginate( page, per_page=Comment.PER_PAGE, error_out=False) comments = pagination.items return render_template('contact.html', comments=comments, counts=counts, pagination=pagination, form=form, endpoint='.contact')
def db_rebuild(): """ Destroy and rebuild database with fake data. """ # destroy and rebuild tables db.reflect() db.drop_all() db.create_all() # insert roles as defined in model Role.insert_roles() # insert geos and usertypes as defined in model Geo.insert_geos() UserType.insert_user_types() # insert firm types/tiers as defined in model FirmType.insert_firm_types() FirmTier.insert_firm_tiers() # insert fake admin/test users from random import seed import forgery_py seed() test_user_1 = User( email='*****@*****.**', username='******', password='******', confirmed=True, name='Salim Hamed', location='Seattle, WA', about_me=forgery_py.lorem_ipsum.sentence(), member_since=forgery_py.date.date(True) ) test_user_2 = User( email='*****@*****.**', username='******', password='******', confirmed=True, name='Bryan Davis', location='Seattle, WA', about_me=forgery_py.lorem_ipsum.sentence(), member_since=forgery_py.date.date(True) ) test_user_3 = User( email='*****@*****.**', username='******', password='******', confirmed=True, name='Joe Smith', location='San Francisco, CA', about_me=forgery_py.lorem_ipsum.sentence(), member_since=forgery_py.date.date(True) ) test_user_4 = User( email='*****@*****.**', username='******', password='******', confirmed=True, name='Bill Gates', location='Bellevue, WA', about_me=forgery_py.lorem_ipsum.sentence(), member_since=forgery_py.date.date(True) ) admin_user = User( email='*****@*****.**', username='******', password='******', confirmed=True, name='Bill Gates', location='Seattle, WA', about_me=forgery_py.lorem_ipsum.sentence(), member_since=forgery_py.date.date(True) ) db.session.add_all([test_user_1, test_user_2, test_user_3, test_user_4, admin_user]) db.session.commit() # insert fake user data User.generate_fake(60) # insert fake post data Post.generate_fake(400) # insert fake followers Follow.generate_fake(2000) # insert fake firms Firm.generate_fake(5000) # insert fake companies Company.generate_fake(10000) # insert fake relationships Relationship.generate_fake(60000) # print results inspector = db.inspect(db.engine) print 'The following tables were created.' print '-'*17 for table in inspector.get_table_names(): print table
def db_rebuild(): """ Destroy and rebuild database with fake data. """ # destroy and rebuild tables db.reflect() db.drop_all() db.create_all() # insert roles as defined in model Role.insert_roles() # insert geos and usertypes as defined in model Geo.insert_geos() UserType.insert_user_types() # insert firm types/tiers as defined in model FirmType.insert_firm_types() FirmTier.insert_firm_tiers() # insert fake admin/test users from random import seed import forgery_py seed() test_user_1 = User(email='*****@*****.**', username='******', password='******', confirmed=True, name='Salim Hamed', location='Seattle, WA', about_me=forgery_py.lorem_ipsum.sentence(), member_since=forgery_py.date.date(True)) test_user_2 = User(email='*****@*****.**', username='******', password='******', confirmed=True, name='Bryan Davis', location='Seattle, WA', about_me=forgery_py.lorem_ipsum.sentence(), member_since=forgery_py.date.date(True)) test_user_3 = User(email='*****@*****.**', username='******', password='******', confirmed=True, name='Joe Smith', location='San Francisco, CA', about_me=forgery_py.lorem_ipsum.sentence(), member_since=forgery_py.date.date(True)) test_user_4 = User(email='*****@*****.**', username='******', password='******', confirmed=True, name='Bill Gates', location='Bellevue, WA', about_me=forgery_py.lorem_ipsum.sentence(), member_since=forgery_py.date.date(True)) admin_user = User(email='*****@*****.**', username='******', password='******', confirmed=True, name='Bill Gates', location='Seattle, WA', about_me=forgery_py.lorem_ipsum.sentence(), member_since=forgery_py.date.date(True)) db.session.add_all( [test_user_1, test_user_2, test_user_3, test_user_4, admin_user]) db.session.commit() # insert fake user data User.generate_fake(60) # insert fake post data Post.generate_fake(400) # insert fake followers Follow.generate_fake(2000) # insert fake firms Firm.generate_fake(5000) # insert fake companies Company.generate_fake(10000) # insert fake relationships Relationship.generate_fake(60000) # print results inspector = db.inspect(db.engine) print('The following tables were created.') print('-' * 17) for table in inspector.get_table_names(): print(table)
def profil(id=None): if not (current_user.is_authenticated): return redirect(url_for('main.login')) userLog = current_user URL_ROOT = request.url_root error = None follow = 0 if (id == None): # user connecter url = URL_ROOT + 'api/post/user/' + str(userLog.id) user = User.query.filter_by(id=userLog.id).first() if request.method == 'POST': username = request.form.get('username') age = request.form.get('age') avatar = request.files.get('avatar') print(avatar) if username != None: if username == "": error = "vous n'avez pas mis votre username" elif age == "": error = "vous n'avez pas mis votre age" else: if avatar != "": resp = uploadImage(avatar, user) if resp: user.avatar = avatar.filename else: error = "l'image n'a pas été envoyer car ce n'est pas une image" user.username = username user.age = age db.session.commit() elif id == userLog.id: return redirect(url_for('main.profil', id=None)) else: url = URL_ROOT + 'api/post/user/' + str(id) user = User.query.filter_by(id=id).first() follow = Follow.query.filter_by(follower_id=userLog.id, followby_id=id).first() if not (follow): follow = 1 if request.method == 'POST': if follow == 1: following = Follow(userLog, user) db.session.add(following) else: db.session.delete(follow) following = Follow.query.filter_by(follower_id=user.id).count() followers = Follow.query.filter_by(followby_id=user.id).count() numberPosts = Post.query.filter_by(user_id=user.id).count() stats = { "followers": followers, "following": following, "posts": numberPosts } if request.method == 'POST': post = request.form.get('post') if post != None: postDelete = Post.query.filter_by(id=post).first() postDelete.like = [] db.session.commit() commentDelete = Comment.query.filter_by(id=post).all() for comment in commentDelete: db.session.delete(comment) db.session.delete(postDelete) db.session.commit() return redirect(url_for('main.profil', id=id)) response = requests.get(url) user = response.json() return render_template('pages/user/profil.html', stats=stats, error=error, id=id, user=user, follow=follow, userLog=userLog, currentUser=current_user)
user3 = User( username='******', hashed_password= '******', email='*****@*****.**', bio='I am a professional photographer', ) user4 = User( username='******', hashed_password= '******', email='*****@*****.**', bio='hi im a guest! ', ) f1 = Follow( follower=user1, followed=user2, ) f2 = Follow( follower=user2, followed=user1, ) f3 = Follow(follower=user4, followed=user1) f4 = Follow( follower=user4, followed=user2, ) f5 = Follow( follower=user4, followed=user3, )