예제 #1
0
def find_landlords_by_name(fname=None, lname=None):
    """Returns a list of landlord objects that loosely match fname or lname in query"""

    print "At find landlords by name."
    print "Query: {} {}".format(fname, lname)

    # Query for landlords where fname or lname is like either of the fname or lname inputs
    if fname and lname:
        landlords = db.session.query(Landlord).filter(
            db.or_(Landlord.fname.ilike("%" + fname + "%"),
                   Landlord.fname.ilike("%" + lname + "%"),
                   Landlord.lname.ilike("%" + fname + "%"),
                   Landlord.lname.ilike("%" + lname + "%"))).all()

    elif fname and not lname:
        landlords = db.session.query(Landlord).filter(
            db.or_(Landlord.fname.ilike("%" + fname + "%"),
                   Landlord.lname.ilike("%" + fname + "%"))).all()

    elif lname and not fname:
        landlords = db.session.query(Landlord).filter(
            db.or_(Landlord.fname.ilike("%" + lname + "%"),
                   Landlord.lname.ilike("%" + lname + "%"))).all()

    else:
        print "Received no arguments"
        raise TypeError

    if landlords:
        for landlord in landlords:
            print "Found {} {}.\n".format(landlord.fname, landlord.lname)
        return landlords
    else:
        print "{} {} was not found.".format(fname, lname)
        return None
예제 #2
0
def find_landlords_by_name(fname=None, lname=None):
    """Returns a list of landlord objects that loosely match fname or lname in query"""

    print "At find landlords by name."
    print "Query: {} {}".format(fname, lname)

    # Query for landlords where fname or lname is like either of the fname or lname inputs
    if fname and lname:
        landlords = db.session.query(Landlord).filter(db.or_(Landlord.fname.ilike("%"+fname+"%"),
                                                             Landlord.fname.ilike("%"+lname+"%"),
                                                             Landlord.lname.ilike("%"+fname+"%"),
                                                             Landlord.lname .ilike("%"+lname+"%"))).all()

    elif fname and not lname:
        landlords = db.session.query(Landlord).filter(db.or_(Landlord.fname.ilike("%"+fname+"%"),
                                                             Landlord.lname.ilike("%"+fname+"%"))).all()

    elif lname and not fname:
        landlords = db.session.query(Landlord).filter(db.or_(Landlord.fname.ilike("%"+lname+"%"),
                                                             Landlord.lname.ilike("%"+lname+"%"))).all()

    else:
        print "Received no arguments"
        raise TypeError

    if landlords:
        for landlord in landlords:
            print "Found {} {}.\n".format(landlord.fname, landlord.lname)
        return landlords
    else:
        print "{} {} was not found.".format(fname, lname)
        return None
예제 #3
0
def get_fish_or_rabbits():
    """Return all animals whose species is 'fish' OR 'rabbit'."""

    return print(
        db.session.query(Animal).filter(
            db.or_(Animal.animal_species.like('%fish%'),
                   Animal.animal_species.like('%rabbit%'))).all())
예제 #4
0
파일: crud.py 프로젝트: NicoleDreon/me
def get_entries(user_id):
    """Create relationship between morning_entries and evening_entries tables for a speific user_id."""

    q = db.session.query(Morning_Entry, Evening_Entry)
    q = q.outerjoin(Evening_Entry,
                    db.and_(Morning_Entry.date == Evening_Entry.date,
                            Morning_Entry.user_id == Evening_Entry.user_id),
                    full=True)
    q = q.filter(
        db.or_(Morning_Entry.user_id == user_id,
               Evening_Entry.user_id == user_id))
    q = q.order_by(Morning_Entry.date.desc(), Evening_Entry.date.desc())
    entries = q.all()

    return entries
예제 #5
0
def autocomplete():
	"""From airport codes database, provide autocomplete in user's arrival input using AJAX."""

	search_value = request.args.get('term')

	query = AirportCode.query.filter(db.or_(AirportCode.code.ilike("%%%s%%" % (search_value)), 
											AirportCode.location.ilike("%%%s%%" % (search_value)))).all()
	
	suggestion_list = []

	for item in query:
		code = item.code
		location = item.location
		suggestion_string = "(%s) %s" %(code, location)
		suggestion_list.append(suggestion_string)
	
	# print suggestion_list
	
	return jsonify(data=suggestion_list)
예제 #6
0
def process_login():


    name = request.form["name"]
    password = request.form['password']

    user = User.query.filter(db.or_(User.email == name, 
        User.user_name == name)).first()

    if not user:
        flash("Incorrect email or username!")
        return redirect("/login")

    if user.password != password:
        flash("Incorrect password")
        return redirect("/login")


    session["user_id"] = user.user_id
    return redirect("/")
예제 #7
0
    def query_messages(self, *args, **kwargs):
        cur_user = kwargs['cur_user']
        form = kwargs['form']
        user_id = None
        if cur_user.user_group == 'root' or cur_user.user_group == 'admin':
            user_id = form['user_id']
        else:
            user_id = cur_user.id
        if not user_id:
            return {'success': 'false', 'message': 'missing user_id parameter'}

        messages = db.session.query(Message).filter(db.or_(Message.from_user == user_id, Message.to_user == user_id)).all()
        # messages.sort(lambda x: x.)
        res = [
            {
                'from_user_name': db.session.query(User).filter(User.id == message.from_user).first().username,
                'from_user': message.from_user,
                'to_user': message.to_user,
                'content': message.content,
                'date': message.send_date,
                'type': message.type
            } for message in messages
        ]
        return {'success': 'true', 'data': res, 'query_id': cur_user.id}
예제 #8
0
def commit_personality_load_movies():

    assessment_id = session.get('assessment',"")
    user_id = session.get('user_id',"")
    traitify = Traitify(traitify_secret)

    # Get an assessment's results (personality types)
    personality_types = traitify.get_personality_types(assessment_id)

    # Get an assessment's results (personality type traits)
    personality_type = personality_types["personality_types"][0].personality_type
    print "personality type:", personality_type.attributes['name'], "$$$$$$$$$"


    this_user = User.query.filter(User.user_id == user_id).first()

    if this_user:
        this_user.personality = personality_type.attributes['name']
        db.session.commit()


    # movies = session.get("movies",[])
    movies = db.session.query(Movie.movie_id, Movie.title, Movie.genre, Movie.length, Movie.image_link)

    if this_user.personality == "Beliver":
        by_genre = movies.filter(db.or_(Movie.genre.like('%Action%'),
                                    Movie.genre.like('%Adventure%'),
                                    Movie.genre.like('%Fantasy%'),
                                    Movie.genre.like('%Sci-Fi%')
                                    )).all() 

    elif this_user.personality == "Dramatic":
        by_genre = movies.filter(db.or_(Movie.genre.like('Biography%'),
                                    Movie.genre.like('%Crime%'),
                                    Movie.genre.like('%Drama%'),
                                    Movie.genre.like('%History%'),
                                    Movie.genre.like('%Mystery%'),
                                    Movie.genre.like('%Western%')
                                    )).all()

    elif this_user.personality == "Indie":
        by_genre = movies.filter(db.or_(Movie.genre.like('%Documentary%'),
                                    Movie.genre.like('%History%'),
                                    Movie.genre.like('%Mystery%')
                                    )).all()

    elif this_user.personality == "Laughaholic":
        by_genre = movies.filter(db.or_(Movie.genre.like('%Comedy%'),
                                    Movie.genre.like('%Family%')
                                    )).all()

    elif this_user.personality == "Romantic":
        by_genre = movies.filter(db.or_(Movie.genre.like('%Romance%'),
                                    Movie.genre.like('%Comedy%')
                                    )).all()

    elif this_user.personality == "Nail Biter":
        by_genre = movies.filter(db.or_(Movie.genre.like('%Horror%'),
                                    Movie.genre.like('%Crime%'),
                                    Movie.genre.like('%Mystery%'),
                                    Movie.genre.like('%Thriller%')
                                    )).all()

    elif this_user.personality == "Stunt Double":
        by_genre = movies.filter(db.or_(Movie.genre.like('%Action%'),
                                    Movie.genre.like('%War%'),
                                    Movie.genre.like('%Adventure%'),
                                    Movie.genre.like('%Western%')
                                    )).all()

    print "by_genre is", by_genre
    return render_template("results.html", session=session, movies=by_genre)
예제 #9
0
def get_fish_or_rabbits():
    """Return all animals whose species is 'fish' OR 'rabbit'."""

    return Animal.query.filter(
        db.or_(Animal.animal_species == "fish",
               Animal.animal_species == "rabbit")).all()
예제 #10
0
def get_images_ajax():
    """Used for React views"""

    ajax = request.get_json()
    limit = ajax.get('limit')
    offset = ajax.get('offset')
    order_by_date = ajax.get('orderByDate')
    user_id = ajax.get('userId')
    this_user = ajax.get('loggedInAs')
    print ajax

    images = Image.query.filter(
        db.or_(Image.source_image != None, Image.styled_image != None))

    if user_id:
        images = images.filter(Image.user_id == user_id)
    if order_by_date:
        if order_by_date == 'desc':
            images = images.order_by(Image.created_at.desc())
        else:
            images = images.order_by(Image.created_at)
    if limit:
        images = images.limit(int(limit))
    if offset:
        images = images.offset(int(offset))

    images = images.all()

    result = {
        'count': 0,
        'images': [],
    }

    for image in images:
        result['count'] += 1
        result['images'].append({
            'createdAt':
            image.created_at.strftime('%b %d, %Y'),
            'imageId':
            image.image_id,
            'isLiked':
            False,
            'likeCount':
            len(image.likes),
            'path':
            image.get_path(),
            'user': {
                'userId': image.user.user_id,
                'username': image.user.username,
                'createdAt': image.user.created_at.strftime('%b %d, %Y'),
            },
        })
        if image.source_image:
            result['images'][-1]['sourceImage'] = {
                'title': image.source_image.title,
                'description': image.source_image.description,
            }
        if image.styled_image:
            result['images'][-1]['styledImage'] = {
                'artist': image.styled_image.style.artist,
                'path': image.styled_image.style.image.get_path(),
                'sourceImage': {
                    'description': image.styled_image.source_image.description,
                    'imageId': image.styled_image.source_image.image_id,
                    'title': image.styled_image.source_image.title,
                },
                'title': image.styled_image.style.title,
            }
        if this_user:
            is_liked = int(this_user) in [like.user_id for like in image.likes]
            result['images'][-1]['isLiked'] = is_liked

    # pprint(result)
    return jsonify(result)
예제 #11
0
    def query_message_list(self, *args, **kwargs):
        cur_user = kwargs['cur_user']

        if cur_user.user_group != 'root' and cur_user.user_group != 'admin':
            return { 'success' : 'false', 'message' : 'invalid request', 'Unauthorized': 'True'}

        messages = db.session.query(Message.from_user, db.func.max(Message.send_date).label('last_message_date')).filter(Message.type == 'question').group_by(Message.from_user).all()
        #messages = Message.query.filter_by(from_user = cur_user.id).all()
        res = {
            'success' : 'true',
            'data' : [ {
                            'to_person_name' : db.session.query(User).filter(User.id == message.from_user).first().username,
                            'to_person_id' : message.from_user,
                            'last_message_date' : message.last_message_date,
                            'last_message' : db.session.query(Message).filter(Message.id == db.session.query(db.func.max(Message.id).label('tmp_ans')).filter(db.or_(Message.from_user == message.from_user, Message.to_user == message.from_user)).first().tmp_ans).first().content
                       }  for message in messages ]
        }
        return res