コード例 #1
0
    def home():
        if 'user' in session:
            auth = User.find_by('username', session['user'])
            if auth.is_complete() == False:
                session[
                    'error'] = "Vous devez remplir toutes vos informations (Age, intérêts, etc)."
                return redirect(url_for('profile', username=session['user']))
            orientation = auth.getOrientation()
            sex = auth.getSex()
            result = []
            if orientation == '0':
                infos = User.where('sex', sex)
                for item in infos:
                    if int(item['orientation']) == 0 or int(
                            item['orientation']) == 2:
                        result.append(item)
            elif orientation == '1' and sex == '1':
                infos = User.where('sex', '2')
                for item in infos:
                    if int(item['orientation']) == 1 or int(
                            item['orientation']) == 2:
                        result.append(item)
            elif orientation == '1' and sex == '2':
                infos = User.where('sex', '1')
                for item in infos:
                    if int(item['orientation']) == 1 or int(
                            item['orientation']) == 2:
                        result.append(item)
            else:
                infos = User.where_multi('sex', 1, 2)
                for item in infos:
                    if int(sex) == 1:
                        if int(item['sex']) == 1 and int(
                                item['orientation']) == 0:
                            result.append(item)
                        elif int(item['sex']) == 1 and int(
                                item['orientation']) == 2:
                            result.append(item)
                        elif int(item['sex']) == 2 and int(
                                item['orientation']) == 2:
                            result.append(item)
                        elif int(item['sex']) == 2 and int(
                                item['orientation']) == 1:
                            result.append(item)
                    if int(sex) == 2:
                        if int(item['sex']) == 2 and int(
                                item['orientation']) == 0:
                            result.append(item)
                        elif int(item['sex']) == 2 and int(
                                item['orientation']) == 2:
                            result.append(item)
                        elif int(item['sex']) == 1 and int(
                                item['orientation']) == 2:
                            result.append(item)
                        elif int(item['sex']) == 1 and int(
                                item['orientation']) == 1:
                            result.append(item)

            for item in result:
                if Block.exists('by_id', auth.getId(), 'blocked_id',
                                item['id']) == True:
                    result.remove(item)

            for item in result:
                item['profile_picture'] = Picture.fillInInfos(item['id'], '1')
                item.pop('password')

            for item in result:
                if item['username'] == session['user']:
                    result.remove(item)

            n = len(result)
            session['result'] = result
            return render_template('home.html', infos=result, length=n)
        else:
            return redirect(url_for('accueil'))
コード例 #2
0
ファイル: profile_controller.py プロジェクト: ssumodhe/Matcha
    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'))
コード例 #3
0
    def search(form):
        if 'user' in session:
            auth = User.find_by('username', session['user'])
            if auth.is_complete() == False:
                return redirect(url_for('profile', username=session['user']))
            orientation = auth.getOrientation()
            sex = auth.getSex()
            result = []
            if orientation == '0':
                infos = User.where('sex', sex)
                for item in infos:
                    if int(item['orientation']) == 0 or int(
                            item['orientation']) == 2:
                        result.append(item)
            elif orientation == '1' and sex == '1':
                infos = User.where('sex', '2')
                for item in infos:
                    if int(item['orientation']) == 1 or int(
                            item['orientation']) == 2:
                        result.append(item)
            elif orientation == '1' and sex == '2':
                infos = User.where('sex', '1')
                for item in infos:
                    if int(item['orientation']) == 1 or int(
                            item['orientation']) == 2:
                        result.append(item)
            else:
                infos = User.where_multi('sex', 1, 2)
                for item in infos:
                    if int(sex) == 1:
                        if int(item['sex']) == 1 and int(
                                item['orientation']) == 0:
                            result.append(item)
                        if int(item['sex']) == 1 and int(
                                item['orientation']) == 2:
                            result.append(item)
                        if int(item['sex']) == 2 and int(
                                item['orientation']) == 2:
                            result.append(item)
                        if int(item['sex']) == 2 and int(
                                item['orientation']) == 1:
                            result.append(item)
                    if int(sex) == 2:
                        if int(item['sex']) == 2 and int(
                                item['orientation']) == 0:
                            result.append(item)
                        if int(item['sex']) == 2 and int(
                                item['orientation']) == 2:
                            result.append(item)
                        if int(item['sex']) == 1 and int(
                                item['orientation']) == 2:
                            result.append(item)
                        if int(item['sex']) == 1 and int(
                                item['orientation']) == 1:
                            result.append(item)
            infos = []
            for item in result:
                if Block.exists('by_id', auth.getId(), 'blocked_id',
                                item['id']) == False:
                    infos.append(item)

            if form['age_min'] != '' and form['age_max'] != '':
                result = infos
                infos = []
                for item in result:
                    if int(item['age']) >= int(form['age_min']) and int(
                            item['age']) <= int(form['age_max']):
                        infos.append(item)

            if form['pop_score_min'] != '' and form['pop_score_max'] != '':
                result = infos
                infos = []
                for item in result:
                    if int(item['pop_score']) >= int(
                            form['pop_score_min']) and int(
                                item['pop_score']) <= int(
                                    form['pop_score_max']):
                        infos.append(item)

            if form['location'] != '':
                result = infos
                infos = []
                my_loc = (float(auth.getLat()), float(auth.getLong()))
                for item in result:
                    if item['lat'] is not None and item['long'] is not None:
                        other = User.find_by('username', item['username'])
                        else_loc = (float(other.getLat()),
                                    float(other.getLong()))
                        delta = vincenty(my_loc, else_loc)
                        if int(delta) <= int(form['location']):
                            infos.append(item)

            if form['interests'] != '':
                result = infos
                infos = []
                my_tags = UsersInterest.where('user_id', auth.getId())
                for item in result:
                    tags = 0
                    else_tags = UsersInterest.where('user_id', str(item['id']))
                    for tag_else in else_tags:
                        for tag_me in my_tags:
                            if tag_else['interest_id'] == tag_me[
                                    'interest_id']:
                                tags = tags + 1
                    if tags >= int(form['interests']):
                        infos.append(item)

            for item in infos:
                item['profile_picture'] = Picture.fillInInfos(item['id'], '1')
                item.pop('password')

            for item in infos:
                if item['username'] == session['user']:
                    infos.remove(item)

            n = len(infos)
            session['result'] = infos
            return render_template('home.html', infos=infos, length=n)
        else:
            return redirect(url_for('accueil'))