示例#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 addprofile():
    result = {}
    json_data = request.json
    minutes = json_data['minutes']
    profile = Profile.query.filter_by(linkid=json_data['linkid'], keyword=json_data['keyword']).first()
    link = Link.query.filter_by(id=json_data['linkid']).join(Deck).first()
    try:
        minutes = int(minutes)
        if (minutes < app.config['MINIMUM_INTERVAL_TIME']):
            result['status'] = 0
            result['msg'] = 'Interval time must to be more than %s minutes' % app.config['MINIMUM_INTERVAL_TIME']
        elif (profile != None):
            result['status'] = -1
            result['msg'] = 'Profile is already existed.'
        elif (link.deck == None):
            result['status'] = -1
            result['msg'] = 'Deck is not available.'
        else:
            profile = Profile(
                linkid=json_data['linkid'],
                keyword=json_data['keyword'],
                minutes=json_data['minutes'],
                run_status=link.deck.login_code
            )
            db.session.add(profile)
            db.session.commit()
            result['status'] = 1
            result['msg'] = 'Succefully Added Profile.'
            driver = getdriver(link.deck.name)
            if (driver != None):
                if (link.deck.login_code > 0):
                    scheduler.add_job(
                        func=auto_rt,
                        kwargs={'profile_id': profile.id, 'driver': driver},
                        trigger=IntervalTrigger(minutes=profile.minutes),
                        # trigger=IntervalTrigger(minutes=1),
                        id='retweet_%s' % (profile.id),
                        replace_existing=False,
                        misfire_grace_time=app.config['MISFIRE_GRACE_TIME'])
                    Profile.query.filter_by(id=profile.id).update({'run_status': 1})
            else:
                Profile.query.filter_by(id=profile.id).update({'run_status': 0})
                db.session.commit()
                result['status'] = -1
                result['msg'] = 'Driver is not available.'
            #send email
            # username = User.query.filter_by(id=link.userid).first().username
            # subject = "Deck row is submitted by %s with %s deck account." % (username, link.deck.name)
            # msg = "Deck row is submitted by %s with %s , %s minutes" % (
            #     username, json_data['keyword'], json_data['minutes'])
            # if (send_email(link.deck.email_address, msg, subject) != True):
            #     result['status'] = -1
            #     result['msg'] = 'Fail to send mail.'
    except:
        result['status'] = -1
        result['msg'] = 'Occured error in db session.'
    db.session.close()
    return jsonify({'result': result})
示例#4
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))
示例#5
0
def acceptPendingById():
    json_data = request.json
    result = {}
    approve = Approve.query.filter_by(id=json_data['id']).first()
    if(approve == None):
        result['status'] = -1
        result['msg'] = 'Approve is not existed.'
    else:
        if (is_deck()):
            try:
                link = Link.query.filter_by(id=approve.linkid).join(Deck).first()
                profile = Profile.query.filter_by(linkid=link.id, keyword=approve.keyword).first()
                if (link.deck == None):
                    result['status'] = -1
                    result['msg'] = 'Deck is not available.'
                else:
                    if (profile != None):
                        Profile.query.filter_by(id=profile.id).update({"minutes": approve.minutes})
                        result['status'] = 1
                        result['msg'] = 'Succefully added request to profile.'
                        if (profile.run_status == 1):
                            driver = getdriver(link.deck.name)
                            if (driver != None):
                                jobid = 'retweet_%s' % (profile.id)
                                if (is_running(jobid)):
                                    scheduler.remove_job(jobid)
                                params = {'profile_id': profile.id, 'driver': driver}
                                scheduler.add_job(
                                    func=auto_rt,
                                    kwargs={'profile_id': profile.id, 'driver': driver},
                                    trigger=IntervalTrigger(minutes=approve.minutes),
                                    # trigger=IntervalTrigger(minutes=1),
                                    id='retweet_%s' % (profile.id),
                                    replace_existing=False,
                                    misfire_grace_time=app.config['MISFIRE_GRACE_TIME'])
                                Profile.query.filter_by(id=profile.id).update({'run_status': 1})
                            else:
                                Profile.query.filter_by(id=profile.id).update({'run_status': 0})
                                result['status'] = -1
                                result['msg'] = 'Driver is not available.'
                        db.session.delete(approve)
                        db.session.commit()
                    else:
                        newprofile = Profile(
                            linkid=link.id,
                            keyword=approve.keyword,
                            minutes=approve.minutes,
                            run_status=link.deck.login_code
                        )
                        db.session.add(newprofile)
                        db.session.delete(approve)
                        db.session.commit()
                        result['status'] = 1
                        result['msg'] = 'Succefully added request to profile.'
                        driver = getdriver(link.deck.name)
                        if (driver != None):
                            if (link.deck.login_code > 0):
                                scheduler.add_job(
                                    func=auto_rt,
                                    kwargs={'profile_id': newprofile.id, 'driver': driver},
                                    trigger=IntervalTrigger(minutes=approve.minutes),
                                    # trigger=IntervalTrigger(minutes=1),
                                    id='retweet_%s' % (newprofile.id),
                                    replace_existing=False,
                                    misfire_grace_time=app.config['MISFIRE_GRACE_TIME'])
                        else:
                            Profile.query.filter_by(id=newprofile.id).update({'run_status':0})
                            db.session.commit()
                            result['status'] = -1
                            result['msg'] = 'Driver is not available.'
            except:
                result['status'] = 0
                result['msg'] = 'Occured error in db session.'
        else:
            result['status'] = -1
            result['msg'] = 'Please login now.'
    return jsonify({'result': result})
示例#6
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)
示例#7
0
def get_room():
    p = Profile.get(Profile.user == current_user.id)
    return p.room == 'room2'
示例#8
0
def new_profile():
    form = ProfileForm()
    if form.validate_on_submit():
        try:
            with database.transaction():
                Profile.create(user=current_user._get_current_object(),
                               room=form.room.data,
                               gift=form.gift.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)
                photo = form.photo.data
                generated_name = uuid4().hex
                photo.filename = secure_filename(generated_name +
                                                 photo.filename)
                output = upload_file_to_s3(photo, 'yestomeetyou')
                p = Photo(url=str(output),
                          user=current_user._get_current_object(),
                          default=True)
                if form.room.data == 'room2':
                    p.private = True
                    p.save()
                if form.gift.data == 1:
                    return redirect(url_for('profile.address'))
                return redirect(url_for('profile.profile'))
        except IntegrityError:
            flash('Unable to create profile', 'danger')

    return render_template('profile/new-profile.html', form=form)