Ejemplo n.º 1
0
def index(path):

    if not current_user.is_authenticated:
        return redirect(url_for('login'))

    content = None
    try:
        # get graphs
        overview_graph = [
            str(api.get("graph/monthly/received").json()).replace("'", '"'),
            str(api.get("graph/monthly/dialed").json()).replace("'", '"'),
            str(api.get("graph/monthly/missed").json()).replace("'", '"'),
            str(api.get("graph/daily/received").json()).replace("'", '"'),
            str(api.get("graph/daily/dialed").json()).replace("'", '"'),
            str(api.get("graph/daily/missed").json()).replace("'", '"')
        ]
        print(overview_graph)
        # get phone top lists
        phone_tops = {
            "received": api.get("stats/phone/top/received").json()["top"],
            "missed": api.get("stats/phone/top/missed").json()["top"],
            "dialed": api.get("stats/phone/top/dialed").json()["top"],
        }
        # try to match the pages defined in -> pages/<input file>
        return render_template(
            'layouts/default.html',
            content=render_template(
                'pages/' + path,
                phone_tops=phone_tops,
                top_monthly=api.get("stats/monthly/-0").json(),
                overview_graph=overview_graph))
    except Exception as e:

        return render_template('layouts/auth-default.html',
                               content=render_template('pages/404.html'))
Ejemplo n.º 2
0
def update_charge_type(id):
    data = {
        "name": querystring_get("name"),
        "description": querystring_get("description")
    }

    if not data["name"]:
        Alert.bad("The <strong>name</strong> field is required")
        return render_template("charge_type/view.html", **data)

    create = str(id).lower() == "create"

    item = None
    if create:
        item = ChargeType()
    else:   
        item = api.get(ChargeType, id)
        if not item:
            Alert.bad("Could not find <strong>Charge Type</strong> {}; {}".format(id, api.error))
            return render_template("charge_type/view.html", **data)

    item.name = data["name"]
    item.description = data["description"]
    item = api.update(ChargeType, item)
    
    if not item:
        Alert.bad(api.error)
        return render_template("charge_type/view.html", **data)
    
    Alert.good("Charge Type <strong>{}</strong> {}".format(item.name, "created" if create else "updated"))
    return redirect("/chargetypes/{}".format(item.id))
Ejemplo n.º 3
0
def get_set(import_id):
    response, code = api.get(import_id)
    if code == 200:
        json_ = dict(data=response)
        return jsonify(json_), 200
    else:
        abort(code)
Ejemplo n.º 4
0
def view_event(id):
    item = api.get(Event, id)

    if not item:
        Alert.bad("Could not find <strong>Event</strong> {}".format(id))
        return redirect("/events/")

    data = {"id": id, "name": item.name, "description": item.description}

    return render_template("event/view.html", **data)
Ejemplo n.º 5
0
def delete_event_role(id):
    item = api.get(EventRole, id)

    if not item:
        Alert.bad("Could not find <strong>Event Role</strong> {}".format(id))
        return redirect("/eventroles/")

    data = {"id": id, "name": item.name, "description": item.description}

    return render_template("event_role/delete.html", **data)
Ejemplo n.º 6
0
def delete_location(id):
    item = api.get(EventLocation, id)

    if not item:
        Alert.bad("Could not find <strong>Location</strong> {}".format(id))
        return redirect("/locations/")

    data = {"id": id, "name": item.name, "description": item.description}

    return render_template("location/delete.html", **data)
Ejemplo n.º 7
0
def delete_weather(id):
    item = api.get(WeatherCondition, id)

    if not item:
        Alert.bad(
            "Could not find <strong>Weather Condition</strong> {}".format(id))
        return redirect("/weather/")

    data = {"id": id, "name": item.name, "description": item.description}

    return render_template("weather/delete.html", **data)
Ejemplo n.º 8
0
def delete_charge_type(id):
    item = api.get(ChargeType, id)
    
    if not item:
        Alert.bad("Could not find <strong>Charge Type</strong> {}".format(id))
        return redirect("/chargetypes/")
    
    data = {
        "id": id,
        "name": item.name,
        "description": item.description
    }

    return render_template("charge_type/delete.html", **data) 
Ejemplo n.º 9
0
def delete_partnership(id):
    item = api.get(Partnership, id)
    
    if not item:
        Alert.bad("Could not find <strong>Partnership</strong> {}".format(id))
        return redirect("/partnerships/")
    
    data = {
        "id": id,
        "name": item.name,
        "description": item.description
    }

    return render_template("partnership/delete.html", **data) 
Ejemplo n.º 10
0
def delete_user_post(id):
    item = api.get(User, id)

    if not item:
        Alert.bad(api.error)
        return redirect("/users/")

    deleted = api.delete(User, item)

    if not deleted:
        Alert.bad(api.error)
        return redirect("/users/{}/".format(id))

    Alert.good("Deleted <strong>User</strong> '{}'".format(item.name))
    return redirect("/users/")
Ejemplo n.º 11
0
def delete_location_post(id):
    item = api.get(EventLocation, id)

    if not item:
        Alert.bad(api.error)
        return redirect("/locations/")

    deleted = api.delete(EventLocation, item)

    if not deleted:
        Alert.bad(api.error)
        return redirect("/locations/{}/".format(id))

    Alert.good("Deleted <strong>Location</strong> '{}'".format(item.name))
    return redirect("/locations/")
Ejemplo n.º 12
0
def delete_charge_type_post(id):
    item = api.get(ChargeType, id)

    if not item:
        Alert.bad(api.error)
        return redirect("/chargetypes/")

    deleted = api.delete(ChargeType, item)

    if not deleted:
        Alert.bad(api.error)
        return redirect("/chargetypes/{}/".format(id))

    Alert.good("Deleted <strong>Charge Type</strong> '{}'".format(item.name))
    return redirect("/chargetypes/")
Ejemplo n.º 13
0
def restore_partnership(id):
    item = api.get(Partnership, id)

    if not item:
        Alert.bad(api.error)
        return redirect("/partnerships/")

    restored = api.restore(Partnership, item)

    if not restored:
        Alert.bad(api.error)
        return redirect("/partnerships/")

    Alert.good("Restored <strong>Partnership</strong> with name <strong>{}</strong>".format(item.name))
    return redirect("/partnerships/")
Ejemplo n.º 14
0
def restore_event(id):
    item = api.get(Event, id)

    if not item:
        Alert.bad(api.error)
        return redirect("/events/")

    restored = api.restore(Event, item)

    if not restored:
        Alert.bad(api.error)
        return redirect("/events/")

    Alert.good("Restored <strong>Event</strong> with name <strong>{}</strong>".format(item.name))
    return redirect("/events/")
Ejemplo n.º 15
0
def restore_charge_type(id):
    item = api.get(ChargeType, id)

    if not item:
        Alert.bad(api.error)
        return redirect("/chargetypes/")

    restored = api.restore(ChargeType, item)

    if not restored:
        Alert.bad(api.error)
        return redirect("/chargetypes/")

    Alert.good("Restored <strong>Charge Type</strong> with name <strong>{}</strong>".format(item.name))
    return redirect("/chargetypes/")
Ejemplo n.º 16
0
def restore_location(id):
    item = api.get(EventLocation, id)

    if not item:
        Alert.bad(api.error)
        return redirect("/locations/")

    restored = api.restore(EventLocation, item)

    if not restored:
        Alert.bad(api.error)
        return redirect("/locations/")

    Alert.good("Restored <strong>Location</strong> with name <strong>{}</strong>".format(item.name))
    return redirect("/locations/")
Ejemplo n.º 17
0
def delete_event_role_post(id):
    item = api.get(EventRole, id)

    if not item:
        Alert.bad(api.error)
        return redirect("/eventroles/")

    deleted = api.delete(EventRole, item)

    if not deleted:
        Alert.bad(api.error)
        return redirect("/eventroles/{}/".format(id))

    Alert.good("Deleted <strong>Event Role</strong> '{}'".format(item.name))
    return redirect("/eventroles/")
Ejemplo n.º 18
0
def delete_partnership_post(id):
    item = api.get(Partnership, id)

    if not item:
        Alert.bad(api.error)
        return redirect("/partnerships/")

    deleted = api.delete(Partnership, item)

    if not deleted:
        Alert.bad(api.error)
        return redirect("/partnerships/{}/".format(id))

    Alert.good("Deleted <strong>Partnership</strong> '{}'".format(item.name))
    return redirect("/partnerships/")
Ejemplo n.º 19
0
def delete_weather_post(id):
    item = api.get(WeatherCondition, id)

    if not item:
        Alert.bad(api.error)
        return redirect("/weather/")

    deleted = api.delete(WeatherCondition, item)

    if not deleted:
        Alert.bad(api.error)
        return redirect("/weather/{}/".format(id))

    Alert.good("Deleted <strong>Weather Condition</strong> '{}'".format(
        item.name))
    return redirect("/weather/")
Ejemplo n.º 20
0
def restore_user(id):
    item = api.get(User, id)

    if not item:
        Alert.bad(api.error)
        return redirect("/users/")

    restored = api.restore(User, item)

    if not restored:
        Alert.bad(api.error)
        return redirect("/users/")

    Alert.good(
        "Restored <strong>User</strong> with name <strong>{}</strong>".format(
            item.name))
    return redirect("/users/")
Ejemplo n.º 21
0
def restore_weather(id):
    item = api.get(WeatherCondition, id)

    if not item:
        Alert.bad(api.error)
        return redirect("/weather/")

    restored = api.restore(WeatherCondition, item)

    if not restored:
        Alert.bad(api.error)
        return redirect("/weather/")

    Alert.good(
        "Restored <strong>Weather Condition</strong> with name <strong>{}</strong>"
        .format(item.name))
    return redirect("/weather/")
Ejemplo n.º 22
0
def view_event_type(id):
    item = api.get(EventType, id)
    
    if not item:
        Alert.bad("Could not find <strong>Event Type</strong> {}".format(id))
        return redirect("/eventtypes/")
    
    charge_types = api.list(ChargeType)

    data = {
        "id": id,
        "name": item.name,
        "description": item.description,
        "charge_types": charge_types,
        "defaultchargetype": item.default_charge_type_id
    }

    return render_template("event_type/view.html", **data)
Ejemplo n.º 23
0
def view_event(id):
    item = api.get(Event, id)

    charge_types = api.list(ChargeType)
    locations = api.list(EventLocation)
    event_types = api.list(EventType)
    
    if not item:
        Alert.bad("Could not find <strong>Event</strong> {}".format(id))
        return redirect("/events/")
    
    data = {
        "id": id,
        "name": item.name,
        "description": item.description,
        "event_types": event_types,
        "charge_types": charge_types,
        "locations": locations
    }

    return render_template("event/view.html", **data)
Ejemplo n.º 24
0
def view_user(id):
    item = api.get(User, id)

    if not item:
        Alert.bad("Could not find <strong>User</strong> {}".format(id))
        return redirect("/users/")

    data = {
        "id": id,
        "username": item.username,
        "forename": item.forename,
        "surname": item.surname,
        "email": item.email_address,
        "dob": item.dob,
        "address1": item.address.line1,
        "address2": item.address.line2,
        "address3": item.address.line3,
        "county": item.address.county,
        "postcode": item.address.postcode
    }

    return render_template("user/view.html", **data)
Ejemplo n.º 25
0
def view_location(id):
    item = api.get(EventLocation, id)

    if not item:
        Alert.bad("Could not find <strong>Location</strong> {}".format(id))
        return redirect("/locations/")

    data = {
        "id": id,
        "name": item.name,
        "description": item.description,
        "address1": item.address.line1 if item.address else "",
        "address2": item.address.line2 if item.address else "",
        "address3": item.address.line3 if item.address else "",
        "county": item.address.county if item.address else "",
        "postcode": item.address.postcode if item.address else "",
        "contactname": item.contact_name,
        "contactemail": item.contact_email_address,
        "contactphone1": item.contact_telephone1,
        "contactphone2": item.contact_telephone2
    }

    return render_template("location/view.html", **data)
Ejemplo n.º 26
0
def phone(path, localid):

    if not current_user.is_authenticated:
        return redirect(url_for('login'))

    content = None
    try:
        # get graphs
        overview_graph = [
            str(api.get("graph/monthly/received/" + localid).json()).replace(
                "'", '"'),
            str(api.get("graph/monthly/dialed/" + localid).json()).replace(
                "'", '"'),
            str(api.get("graph/monthly/missed/" + localid).json()).replace(
                "'", '"'),
            str(api.get("graph/daily/received/" + localid).json()).replace(
                "'", '"'),
            str(api.get("graph/daily/dialed/" + localid).json()).replace(
                "'", '"'),
            str(api.get("graph/daily/missed/" + localid).json()).replace(
                "'", '"')
        ]
        print(overview_graph)

        # try to match the pages defined in -> pages/<input file>
        return render_template('layouts/default.html',
                               content=render_template(
                                   'pages/phone.html',
                                   localid=localid,
                                   top_monthly=api.get("stats/monthly/-0/" +
                                                       localid).json(),
                                   overview_graph=overview_graph))
    except Exception as e:
        print("Exception:", e)

        return render_template('layouts/auth-default.html',
                               content=render_template('pages/404.html'))
Ejemplo n.º 27
0
def update_location(id):
    data = {
        "name": querystring_get("name"),
        "description": querystring_get("description"),
        "address1": querystring_get("address1"),
        "address2": querystring_get("address2"),
        "address3": querystring_get("address3"),
        "county": querystring_get("county"),
        "postcode": querystring_get("postcode"),
        "contactname": querystring_get("contactname"),
        "contactemail": querystring_get("contactemail"),
        "contactphone1": querystring_get("contactphone1"),
        "contactphone2": querystring_get("contactphone2"),
    }

    if not data["name"]:
        Alert.bad("The <strong>Name</strong> field is required")
        return render_template("location/view.html", **data)

    if not data["address1"]:
        Alert.bad("The <strong>Address 1</strong> field is required")
        return render_template("location/view.html", **data)

    if not data["postcode"]:
        Alert.bad("The <strong>Post Code</strong> field is required")
        return render_template("location/view.html", **data)

    create = str(id).lower() == "create"

    item = None
    if create:
        item = EventLocation()
    else:
        item = api.get(EventLocation, id)
        if not item:
            Alert.bad("Could not find <strong>Location</strong> {}; {}".format(
                id, api.error))
            return render_template("location/view.html", **data)

    address = None
    if create or not item.address:
        address = Address()
    else:
        address = item.address

    address.line1 = data["address1"]
    address.line2 = data["address2"]
    address.line3 = data["address3"]
    address.county = data["county"]
    address.postcode = data["postcode"]

    if create or not item.address:
        address = api.create(Address, address)
        if not address:
            Alert.bad("Failed to create <strong>Address</strong>; {}".format(
                api.error))
            return render_template("location/view.html", **data)
    else:
        address = api.update(Address, address)
        if not address:
            Alert.bad("Failed to update <strong>Address</strong>; {}".format(
                api.error))
            return render_template("location/view.html", **data)

    item.name = data["name"]
    item.description = data["description"]
    item.contact_name = data["contactname"]
    item.contact_email_address = data["contactemail"]
    item.contact_telephone1 = data["contactphone1"]
    item.contact_telephone2 = data["contactphone2"]
    item.address = address

    item = api.update(EventLocation, item)

    if not item:
        Alert.bad("Failed to create <strong>Address</strong>; {}".format(
            api.error))
        return render_template("location/view.html", **data)

    Alert.good("Location <strong>{}</strong> {}".format(
        item.name, "created" if create else "updated"))
    return redirect("/locations/{}".format(item.id))
Ejemplo n.º 28
0
def update_user(id):
    data = {
        "username": querystring_get("username"),
        "forename": querystring_get("forename"),
        "surname": querystring_get("surname"),
        "email": querystring_get("email"),
        "dob": querystring_get("dob"),
        "address1": querystring_get("address1"),
        "address2": querystring_get("address2"),
        "address3": querystring_get("address3"),
        "county": querystring_get("county"),
        "postcode": querystring_get("postcode")
    }

    if not data["username"]:
        Alert.bad("The <strong>username</strong> field is required")
        return render_template("user/view.html", **data)

    if not data["forename"]:
        Alert.bad("The <strong>forename</strong> field is required")
        return render_template("user/view.html", **data)

    if not data["surname"]:
        Alert.bad("The <strong>surname</strong> field is required")
        return render_template("user/view.html", **data)

    if not data["address1"]:
        Alert.bad("The <strong>Address 1</strong> field is required")
        return render_template("user/view.html", **data)

    if not data["postcode"]:
        Alert.bad("The <strong>Post Code</strong> field is required")
        return render_template("user/view.html", **data)

    create = str(id).lower() == "create"

    item = None
    if create:
        item = User()
    else:
        item = api.get(User, id)
        if not item:
            Alert.bad("Could not find <strong>User</strong> {}; {}".format(
                id, api.error))
            return render_template("user/view.html", **data)

    address = None
    if create or not item.address:
        address = Address()
    else:
        address = item.address

    address.line1 = data["address1"]
    address.line2 = data["address2"]
    address.line3 = data["address3"]
    address.county = data["county"]
    address.postcode = data["postcode"]

    if create or not item.address:
        address = api.create(Address, address)
        if not address:
            Alert.bad("Failed to create <strong>Address</strong>; {}".format(
                api.error))
            return render_template("user/view.html", **data)
    else:
        address = api.update(Address, address)
        if not address:
            Alert.bad("Failed to update <strong>Address</strong>; {}".format(
                api.error))
            return render_template("user/view.html", **data)

    item.username = data["username"]
    item.forename = data["forename"]
    item.surname = data["surname"]
    item.email_address = data["email"]
    item.dob = data["dob"]
    item.address = address
    item = api.update(User, item)

    if not item:
        Alert.bad(api.error)
        return render_template("user/view.html", **data)

    Alert.good("User <strong>{}</strong> {}".format(
        item.name, "created" if create else "updated"))
    return redirect("/users/{}".format(item.id))
Ejemplo n.º 29
0
'''
Created on 23 Aug 2017

@author: havannavar
'''
from app import app, api, parse_email, controller


@app.route(api.get('login'), methods=['POST'])
@parse_email.validate
def login():
    return controller.login()


def runserver():
    app.run(host='localhost', port=8081)


if __name__ == '__main__':
    runserver()