def profile(username): if 'user' in session: infos = {} if session['user'] == username: infos['is_user_me'] = True else: infos['is_user_me'] = False infos['stalker'] = session['user'] victim = User.find_by('username', username) if victim == None: return redirect(url_for('profile_not_exists')) if victim.is_complete() == False: return redirect(url_for('profile_not_complete')) stalker = User.find_by('username', infos['stalker']) if View.find_both('stalker_id', stalker.getId(), 'victim_id', victim.getId()) == None: view = {} view['stalker_id'] = stalker.getId() view['victim_id'] = victim.getId() View.create(view) notif = {} notif['user_id'] = victim.getId() notif[ 'message'] = "Vu : <a href='/profile/" + stalker.getUserName( ) + "'>" + stalker.getUserName( ) + "</a> vous a rendu visite." Notification.create_if(notif, stalker.getId()) score = int(victim.getPopScore()) + 1 victim.modif('pop_score', str(score)) # if no Fakers # victim.modif('pop_score', str(View.howMany('victim_id', victim.getId()))) victim.save() auth = User.find_by('username', username) infos['username'] = auth.getUserName() infos['first_name'] = auth.getFirstName() infos['last_name'] = auth.getLastName() infos['email'] = auth.getEmail() infos['age'] = auth.getAge() if auth.getSex() == '1': infos['sex'] = "Homme" elif auth.getSex() == '2': infos['sex'] = "Femme" else: infos['sex'] = auth.getSex() if auth.getOrientation() == '0': infos['orientation'] = "H**o" elif auth.getOrientation() == '1': infos['orientation'] = "Hetero" else: infos['orientation'] = "Bi" infos['bio'] = html.unescape(auth.getBio()) infos['interests'] = UsersInterest.getAllInterests(auth.getId()) infos['main_picture'] = auth.getMainPicture() infos['pop_score'] = auth.getPopScore() infos['location'] = auth.getLocation() infos['last_connexion'] = auth.getLastConnexion() infos['status'] = auth.getStatus() picture = Picture.where('user_id', auth.getId()) infos['picture_1'] = Picture.fillInInfos(auth.getId(), '1') infos['picture_2'] = Picture.fillInInfos(auth.getId(), '2') infos['picture_3'] = Picture.fillInInfos(auth.getId(), '3') infos['picture_4'] = Picture.fillInInfos(auth.getId(), '4') infos['picture_5'] = Picture.fillInInfos(auth.getId(), '5') # Put in first ELSE at the top if infos['is_user_me'] == False: stalker = User.find_by('username', infos['stalker']) infos['has_liked'] = Like.exists('stalker_id', stalker.getId(), 'victim_id', auth.getId()) infos['he_liked_me'] = Like.exists('stalker_id', auth.getId(), 'victim_id', stalker.getId()) infos['has_blocked'] = Block.exists('by_id', stalker.getId(), 'blocked_id', auth.getId()) nb_picture = Picture.howMany('user_id', stalker.getId()) if nb_picture == 0: infos['stalker_can_like'] = False infos['nb_like'] = Like.howMany('victim_id', auth.getId()) all_views = View.where('victim_id', auth.getId()) join_infos_views = [] for item in all_views: join_infos_views = join_infos_views + User.join( 'users', 'views', 'id', 'stalker_id', str(item['stalker_id'])) infos['all_views'] = join_infos_views all_likes = Like.where('victim_id', auth.getId()) join_infos_likes = [] for item in all_likes: join_infos_likes = join_infos_likes + User.join( 'users', 'likes', 'id', 'stalker_id', str(item['stalker_id'])) infos['all_likes'] = join_infos_likes error = session.get('error') session['error'] = None tags = [ '#tag', '#bouffe', '#lol', '#cherchedesepérémentqqun', '#lovecats' ] return render_template('profile.html', infos=infos, error=error, tags=tags) else: return redirect(url_for('accueil'))