Exemplo n.º 1
0
def sorted_alerts(city_code=0, value='time', order='desc', start=0, type=None):
    title = "Recent alerts"
    columns = {"id": models.Alert.id, "alert_type_id": models.Alert.alert_type_id, "city_id": models.Alert.city_id,\
"controller_id": models.Alert.controller_id, "time": models.Alert.time, "recurrence": models.Alert.recurrence,\
"handled": models.Alert.handled, "info": models.Alert.info}

    q = queries.get_alerts_with_count()
    #q = models.Alert.query
    if city_code != 0:
        q = q.filter(models.Alert.city_id==city_code)
    # Sort part for count column
    if value == "count":
        print "hehe"
    # End Sort part for count column

    if type:
        q = q.filter(models.Alert.alert_type_id==type)
    if value not in columns:
        value = "time" #Default
    if order == "desc":
        a = q.order_by(columns[value].desc()).slice(start,start+20).all()
        notorder = "asc"
    else:
        order = "asc"
        a = q.order_by(columns[value].asc()).slice(start,start+20).all()
        notorder = "desc"
    urls = []
    values = ["id", "alert_type_id", "city_id", "controller_id", "time", "recurrence", "handled", "info", "count"]
    for i,v in enumerate(values):
        #Get the proper links
        urls.append(url_for("sorted_alerts", value=v, order=notorder, city_code=city_code))
    start_next = start+20
    start_prev = start-20
    if start_prev < 0:
        start_prev = 0
    return render_template('alerts.html', title=title, navlinks=navlinks, city = "some city", alerts=a, urls=urls, start_next=start_next, start_prev=start_prev, column=value, order=order, city_code=city_code)
Exemplo n.º 2
0
def showcontroller(city_id, num):
    c = queries.get_controller(city_id, num)
    a = queries.get_alerts_with_count().filter(models.Alert.city_id==city_id).filter(models.Alert.controller_id==num).order_by(models.Alert.time.desc()).limit(200)
    return render_template('controllers.html', controller=c, title='Controller %d' % c.id, navlinks=navlinks, city=city_id, alerts=a)