示例#1
0
def dialogue(sender=None):
    dia = None
    chat = None

    sender_user = User.get(User.username == sender)
    receiver_user = User.get(User.username == current_user.username)
    users = User.raw(
        'select * from user u, dialogue d '
        'where u.id != %s '
        'and u.id in (d.user1_id, d.user2_id) '
        'and %s in (d.user1_id, d.user2_id);', receiver_user.id,
        receiver_user.id)

    try:
        dia = Dialogue.get(((Dialogue.user1 == sender_user.id)
                            & (Dialogue.user2 == receiver_user.id))
                           | ((Dialogue.user1 == receiver_user.id)
                              & (Dialogue.user2 == sender_user.id)))
    except DoesNotExist:
        dia = None

    user_profile = Profile.get(Profile.user == sender_user.id)
    current_profile = Profile.get(Profile.user == receiver_user.id)

    if not dia:
        if user_profile.room == 'room2' or current_profile.room == 'room2':
            dia = Dialogue.create(user1=sender_user.id,
                                  user2=receiver_user.id,
                                  exchange=20)
        else:
            dia = Dialogue.create(user1=sender_user.id, user2=receiver_user.id)
    session['dia'] = dia.id

    chat = Chat.select().where(Chat.dialogue == dia.id)

    if Chat.select().where(Chat.receiver == current_user.id,
                           Chat.was_read == 0).exists():
        query = Chat.update(was_read=True).where(
            Chat.receiver == current_user.id)
        query.execute()

    count = Chat.select().where(Chat.dialogue == dia.id).count()
    return render_template('chat/dialogue.html',
                           users=users,
                           chat=chat,
                           sender=sender,
                           dia=dia,
                           count=count)
示例#2
0
def profile():
    profile = Profile.get(Profile.user == current_user.id)
    try:
        photo = Photo.select()\
                     .where(Photo.user == current_user.id, Photo.default == 1)\
                     .get()
        photos = Photo.select().where(Photo.user == current_user.id)
    except DoesNotExist:
        photo = None
        photos = None
    return render_template('profile/profile.html',
                           profile=profile,
                           nationality=dict(nationalities),
                           rom=dict(romantic),
                           religion=dict(religion),
                           mar=dict(marriage),
                           chil=dict(children),
                           body=dict(body_type),
                           st=dict(style),
                           status=dict(marriage_status),
                           ori=dict(origin),
                           eye=dict(eyes),
                           hair=dict(hair),
                           harle=dict(hair_length),
                           so=dict(smoke),
                           have_chil=dict(have_children),
                           live=dict(live),
                           job=dict(job),
                           eat=dict(eat),
                           pet=dict(pet),
                           speak=dict(speak),
                           edu=dict(education),
                           income=dict(income),
                           photo=photo,
                           photos=photos)
示例#3
0
def profile(username):
    try:
        user = User.select(User, Profile)\
                   .join(Profile).where(User.username == username).get()
        p = Profile.get(user=current_user.id)
        try:
            Visit.get(visitor=current_user.id, person=user.id)
        except DoesNotExist:
            Visit.create(visitor=current_user.id, person=user.id)
            if user.notif:
                visit_notif(user.email, current_user.username, user.username,
                            p.slogan)
        friend = Friend.select().where(
            ((Friend.friend1 == current_user.id) & (Friend.friend2 == user.id)
             | (Friend.friend1 == user.id) &
             (Friend.friend2 == current_user.id)))
        if friend.exists():
            photos = Photo.select().where(Photo.user == user.id)
        else:
            photos = Photo.select()\
                          .where(Photo.user == user.id, Photo.private == 0)

    except DoesNotExist:
        user = None
        photos = None
    return render_template('main/profile.html',
                           user=user,
                           photos=photos,
                           nationality=dict(nationalities),
                           rom=dict(romantic),
                           religion=dict(religion),
                           mar=dict(marriage),
                           chil=dict(children),
                           body=dict(body_type),
                           st=dict(style),
                           status=dict(marriage_status),
                           ori=dict(origin),
                           eye=dict(eyes),
                           hair=dict(hair),
                           harle=dict(hair_length),
                           so=dict(smoke),
                           have_chil=dict(have_children),
                           live=dict(live),
                           job=dict(job),
                           eat=dict(eat),
                           pet=dict(pet),
                           speak=dict(speak),
                           edu=dict(education),
                           income=dict(income))
示例#4
0
def edit_profile():
    profile = Profile.get(Profile.user == current_user.id)
    form = ProfileUpdateForm(obj=profile)
    if form.validate_on_submit():
        try:
            with database.transaction():
                p = Profile(user=current_user._get_current_object(),
                            gift=form.gift.data,
                            room=form.room.data,
                            description=form.description.data,
                            romantic=form.romantic.data,
                            marriage=form.marriage.data,
                            want_children=form.want_children.data,
                            nationality=form.nationality.data,
                            height=form.height.data,
                            body_type=form.body_type.data,
                            style=form.style.data,
                            origin=form.origin.data,
                            eyes=form.eyes.data,
                            hair=form.hair.data,
                            hair_length=form.hair_length.data,
                            weight=form.weight.data,
                            status=form.status.data,
                            smoke=form.smoke.data,
                            children=form.children.data,
                            live=form.live.data,
                            job=form.job.data,
                            eat=form.eat.data,
                            pet=form.pet.data,
                            speak1=form.speak1.data,
                            speak2=form.speak2.data,
                            speak3=form.speak3.data,
                            speak4=form.speak4.data,
                            education=form.education.data,
                            religion=form.religion.data,
                            income=form.income.data,
                            slogan=form.slogan.data,
                            first_meet=form.first_meet.data,
                            quality=form.quality.data,
                            defauts=form.defauts.data,
                            dream=form.dream.data,
                            love=form.love.data,
                            partner=form.partner.data,
                            loisir=form.loisir.data,
                            friend=form.friend.data,
                            experience=form.experience.data,
                            boulot=form.experience.data,
                            animal=form.animal.data,
                            enfant=form.enfant.data,
                            future=form.future.data,
                            fierte=form.fierte.data,
                            culture=form.culture.data,
                            malaise=form.malaise.data,
                            sortie=form.sortie.data,
                            voyage=form.voyage.data,
                            addication=form.addication.data,
                            passion=form.passion.data)
                p.save()
                if form.room.data == 'room1':
                    photo = Photo.select().where(Photo.user == current_user.id)
                    for p in photo:
                        p.private = False
                        p.save()
                flash('Your profile has been updated!')
                return redirect(url_for('profile.profile'))
        except IntegrityError:
            flash('Unable to create profile', 'danger')

    return render_template('profile/edit-profile.html', form=form)
示例#5
0
def get_room():
    p = Profile.get(Profile.user == current_user.id)
    return p.room == 'room2'