Ejemplo n.º 1
0
def homepage():
    """renders homepage information"""
	
    share = db.session.query(Post, User).join(User).filter(db.and_(
    	Post.post_types == "Share", Post.active == True)).all()
    wish = db.session.query(Post, User).join(User).filter(db.and_(
    	Post.post_types == "Wish", Post.active == True)).all()

    return render_template("homepage.html", share=share, wish=wish)
Ejemplo n.º 2
0
def posts_for_feed():
    """ return the posts for logged in user's feed"""
    user_id = session.get('user_id')
    friend_posts = Post.query.join(Friend, db.and_(Post.user_id == Friend.user_2,
                                Friend.active == True)).outerjoin(Comment, db.and_(Comment.post_id == Post.post_id,
                                Comment.active == True)).filter(Friend.user_1 == user_id,
                                Post.active == True).order_by(Post.post_id.desc()).all()

    post_list = []
    for post in friend_posts:
        post_list.append(post.to_dict_for_json())

    resp = make_response(jsonify(post_list), 200)
    return resp
Ejemplo n.º 3
0
def user_page():
    """displays relevent user information"""

    current_user = session.get("user_id")
    user = User.query.filter(User.user_id == current_user).first()

    share = Post.query.filter(db.and_(Post.user_email == user.email,
    	Post.active == True, Post.post_types == "Share")).all()
    wish = Post.query.filter(db.and_(Post.user_email == user.email,
    	Post.active == True, Post.post_types == "Wish")).all()


    return render_template('user_page.html', user=user, 
    	share=share, wish=wish)
Ejemplo n.º 4
0
    def current(self):
        now = datetime.now(tz=tzlocal.get_localzone())
        timeframe = Timeframe.query.filter(
            db.and_(Timeframe.begin_timestamp <= now, Timeframe.end_timestamp
                    >= now)).first_or_404("No active timeframe")

        return jsonify(self.timeframe_schema_noid.dump(timeframe)), 200
Ejemplo n.º 5
0
    def get(self, hugid: int):
        # only hugs by the current player is allowed
        hug = Hug.query.filter(
            db.and_(Hug.player == this_player(),
                    Hug.id == hugid)).first_or_404()

        return jsonify(self.hug_schema.dump(hug)), 200
Ejemplo n.º 6
0
 def get_times(self, datetime_start, datetime_stop, sensor_url):
     rm = Measurement.query.filter(
         db.and_((Measurement.datetime >= datetime_start),
                 (Measurement.datetime <= datetime_stop),
                 (Measurement.sensor_url == sensor_url)))
     values = []
     for elem in rm:
         values.append(elem.datetime.strftime("%Y-%m-%d %H:%M"))
     return values
Ejemplo n.º 7
0
    def get(self, ponyid: int): # TODO: this can be solved using a single query
        pony = Pony.query.get_or_404(ponyid, "Undiscovered or non-existent pony")

        # should replace to exists()
        Hug.query.filter(
            db.and_(Hug.player == this_player(), Hug.pony == pony)
        ).first_or_404("Undiscovered or non-existent pony")

        return jsonify(self.pony_schema.dump(pony)), 200
Ejemplo n.º 8
0
def delete_posting():
	"""renders the template for deativating postings"""

	current_user = session.get("user_id")
	user = User.query.filter(User.user_id == current_user).first()
	post = Post.query.filter(db.and_(Post.user_email == user.email,
		Post.active == True)).all()

	return render_template('delete_posting.html', post=post)
Ejemplo n.º 9
0
 def read_hour(self, date_time, url):
     m = db.session.query(func.extract(
         'hour', Measurement.datetime)).distinct(
             func.extract('hour', Measurement.datetime)).filter(
                 db.and_(Measurement.datetime.startswith(date_time),
                         Measurement.sensor_url == url)).all()
     values = []
     for e in m:
         values.append(e[0])
     return values
Ejemplo n.º 10
0
    def call(*args, **kwargs):
        now = datetime.now(tz=tzlocal.get_localzone())
        timeframe = Timeframe.query.filter(
            db.and_(Timeframe.begin_timestamp <= now, Timeframe.end_timestamp >= now)
        ).first()

        if timeframe:
            return f(*args, **kwargs)
        else:
            return abort(423, "No active timeframe")
Ejemplo n.º 11
0
def select_post_update():
	"""renders post selection form"""

	current_user = session.get("user_id")
	user = User.query.filter(User.user_id == current_user).first()
	post = Post.query.filter(db.and_(Post.user_email == user.email,
		Post.active == True)).all()
	

	return render_template('select_post.html', post=post)
Ejemplo n.º 12
0
 def get_max_measurement(self, type, sensor_url):
     mM = Measurement.query.filter(
         db.and_((Measurement.sensor_url == sensor_url),
                 (Measurement.datetime.startswith(
                     datetime.datetime.now().strftime("%Y-%m-%d"))))).all()
     values = []
     for elem in mM:
         if type == 'humidity':
             values.append(elem.humidity)
         else:
             values.append(elem.temperature)
     maximum = max(values)
     return maximum
Ejemplo n.º 13
0
 def read_measurement(self, datetime_start, datetime_stop, type,
                      sensor_url):
     rm = Measurement.query.filter(
         db.and_((Measurement.datetime >= datetime_start),
                 (Measurement.datetime <= datetime_stop),
                 (Measurement.sensor_url == sensor_url)))
     values = []
     for elem in rm:
         if type == 'humidity':
             values.append(elem.humidity)
         else:
             values.append(elem.temperature)
     return values
Ejemplo n.º 14
0
def users_posts():
    """ return the users's posts"""

    user_id = session.get('user_id')
    posts = Post.query.outerjoin(Comment, db.and_(Comment.post_id == Post.post_id, 
                                Comment.active == True)).filter(Post.user_id == user_id,
                                Post.active == True).order_by(Post.post_id.desc()).all()
    post_list = []
    for post in posts:
        post_list.append(post.to_dict_for_json())

    resp = make_response(jsonify(post_list), 200)

    return resp
Ejemplo n.º 15
0
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
Ejemplo n.º 16
0
    def read_measurement_today(self, date_time, type, url):
        #r=Measurement.query.filter(db.and_(Measurement.datetime==datetime.startswith(date_time),Measurement.url==url)).
        #(func.avg(Measurement.humidity).label('average'))

        #hour_=['00:00', '01:00', '02:00', '03:00','04:00','05:00','06:00','07:00','08:00','09:00','10:00','11:00','12:00','13:00','14:00','15:00','16:00','17:00','18:00','19:00','20:00','21:00','22:00','23:00','24:00']

        value = []
        if type == 'humidity':
            r = db.session.query(func.avg(
                Measurement.humidity), Measurement.datetime).filter(
                    db.and_(Measurement.datetime.startswith(date_time),
                            Measurement.sensor_url == url)).group_by(
                                func.extract('hour',
                                             Measurement.datetime)).all()
        else:
            r = db.session.query(func.avg(
                Measurement.temperature), Measurement.datetime).filter(
                    db.and_(Measurement.datetime.startswith(date_time),
                            Measurement.sensor_url == url)).group_by(
                                func.extract('hour',
                                             Measurement.datetime)).all()
        for e in r:
            value.append(e[0])
        return value
Ejemplo n.º 17
0
 def get_min_measurement(self, type, sensor_url):
     mm = Measurement.query.filter(
         db.and_((Measurement.sensor_url == sensor_url),
                 (Measurement.datetime.startswith(
                     datetime.datetime.now().strftime("%Y-%m-%d"))))).all()
     values = []
     for elem in mm:
         if type == 'humidity':
             values.append(elem.humidity)
         else:
             values.append(elem.temperature)
     if not values:  #non sono state registrate misurazioni nella giornata
         return False
     minimum = min(values)
     return minimum
Ejemplo n.º 18
0
def search():

    search_term = request.args.get('term')
    user_id = session['user_id']

    results = db.session.query(User, 
                               Friend).outerjoin(Friend, db.and_(Friend.user_1 == user_id, 
                               Friend.active == True)).filter((User.user_id != user_id) & 
                               (User.public == True) & 
                               ((Friend.user_2 == None) |
                                (Friend.user_2 != User.user_id)) &
                               (((User.first_name.like(f'%{search_term}%')) | 
                               (User.last_name.like(f'%{search_term}%'))))).all()

    return render_template('search.html',results=results)