예제 #1
0
def import_do():
    # retrieves the import file values (reference to the
    # uploaded file) and then validates if it has been
    # defined, in case it fails prints the template with
    # the appropriate error variable set
    import_file = quorum.get_field("import_file", None)
    if import_file == None or not import_file.filename:
        return flask.render_template(
            "settings/import.html.tpl", link="settings", sub_link="import", error="No file defined"
        )

    # creates a temporary file path for the storage of the file
    # and then saves it into that directory
    fd, file_path = tempfile.mkstemp()
    import_file.save(file_path)

    # retrieves the database and creates a new export manager for
    # the currently defined entities then imports the data defined
    # in the current temporary path
    adapter = quorum.get_adapter()
    manager = quorum.export.ExportManager(adapter, single=SINGLE_ENTITIES, multiple=MULTIPLE_ENTITIES)
    try:
        manager.import_data(file_path)
    finally:
        os.close(fd)
        os.remove(file_path)
    return flask.redirect(flask.url_for("import_a", message="Database file imported with success"))
예제 #2
0
def login():
    # retrieves both the username and the password from
    # the flask request form, these are the values that
    # are going to be used in the username validation
    username = quorum.get_field("username")
    password = quorum.get_field("password")
    try: account = models.Account.login(username, password)
    except quorum.OperationalError as error:
        return flask.render_template(
            "signin.html.tpl",
            username = username,
            error = error.message
        )

    # updates the current user (name) in session with
    # the username that has just be accepted in the login
    flask.session["username"] = account.username
    flask.session["cameras"] = account.cameras and account.cameras.list()
    flask.session["tokens"] = account.tokens

    # makes the current session permanent this will allow
    # the session to persist along multiple browser initialization
    flask.session.permanent = True

    return flask.redirect(
        flask.url_for("index")
    )
예제 #3
0
def settings_set(set_id):
    set = models.Set.get_a(set_id = set_id)
    return flask.render_template(
        "set/settings.html.tpl",
        link = "sets",
        sub_link = "settings",
        set = set
    )
예제 #4
0
def show_account(username):
    account = models.Account.get(username = username)
    return flask.render_template(
        "account/show.html.tpl",
        link = "accounts",
        sub_link = "show",
        account = account
    )
예제 #5
0
def handler_413(error):
    return flask.Response(
        flask.render_template(
            "error.html.tpl",
            error = "412 - Precondition failed"
        ),
        status = 413
    )
예제 #6
0
def handler_404(error):
    return flask.Response(
        flask.render_template(
            "error.html.tpl",
            error = "404 - Page not found"
        ),
        status = 404
    )
예제 #7
0
def new_device():
    return flask.render_template(
        "device/new.html.tpl",
        link = "devices",
        sub_link = "create",
        device = {},
        errors = {}
    )
예제 #8
0
def show_device(device_id):
    device = models.Device.get(device_id = device_id)
    return flask.render_template(
        "device/show.html.tpl",
        link = "devices",
        sub_link = "show",
        device = device
    )
예제 #9
0
def settings_camera(camera_id):
    camera = models.Camera.get_a(camera_id = camera_id)
    return flask.render_template(
        "camera/settings.html.tpl",
        link = "cameras",
        sub_link = "settings",
        camera = camera
    )
예제 #10
0
def edit_device(device_id):
    device = models.Device.get(device_id = device_id)
    return flask.render_template(
        "device/edit.html.tpl",
        link = "devices",
        sub_link = "edit",
        device = device,
        errors = {}
    )
예제 #11
0
def edit_set(set_id):
    set = models.Set.get_a(set_id = set_id)
    return flask.render_template(
        "set/edit.html.tpl",
        link = "sets",
        sub_link = "edit",
        set = set,
        errors = {}
    )
예제 #12
0
def edit_camera(camera_id):
    camera = models.Camera.get_a(camera_id = camera_id)
    return flask.render_template(
        "camera/edit.html.tpl",
        link = "cameras",
        sub_link = "edit",
        camera = camera,
        errors = {}
    )
예제 #13
0
def show_set(set_id):
    set = models.Set.get_a(set_id = set_id)
    set.merge_cameras()
    return flask.render_template(
        "set/show.html.tpl",
        link = "sets",
        sub_link = "show",
        set = set
    )
예제 #14
0
def edit_account(username):
    account = models.Account.get(username = username)
    return flask.render_template(
        "account/edit.html.tpl",
        link = "accounts",
        sub_link = "edit",
        account = account,
        errors = {}
    )
예제 #15
0
def show_account_s():
    username = flask.session["username"]
    account = models.Account.get(username = username)
    return flask.render_template(
        "account/show.html.tpl",
        link = "accounts",
        sub_link = "show",
        account = account
    )
예제 #16
0
def new_camera():
    return flask.render_template(
        "camera/new.html.tpl",
        link = "cameras",
        sub_link = "create",
        camera = {
            "device" : {}
        },
        errors = {}
    )
예제 #17
0
def show_camera(camera_id):
    camera = models.Camera.get_a(camera_id = camera_id)
    camera.merge_device()
    camera.filter_device()
    return flask.render_template(
        "camera/show.html.tpl",
        link = "cameras",
        sub_link = "show",
        camera = camera
    )
예제 #18
0
def new_account():
    return flask.render_template(
        "account/new.html.tpl",
        link = "accounts",
        sub_link = "create",
        account = {
            "cameras" : {}
        },
        errors = {}
    )
예제 #19
0
def new_set():
    return flask.render_template(
        "set/new.html.tpl",
        link = "sets",
        sub_link = "create",
        set = {
            "cameras" : {}
        },
        errors = {}
    )
예제 #20
0
def handler_exception(error):
    formatted = traceback.format_exc()
    lines = formatted.splitlines()
    status = error.code if hasattr(error, "code") else 500

    return flask.Response(
        flask.render_template(
            "error.html.tpl",
            error = str(error),
            traceback = lines
        ),
        status = status
    )
예제 #21
0
def create_set():
    # creates the new set, using the provided arguments and
    # then saves it into the data source, all the validations
    # should be ran upon the save operation
    set = models.Set.new()
    try: set.save()
    except quorum.ValidationError as error:
        return flask.render_template(
            "set/new.html.tpl",
            link = "sets",
            sub_link = "create",
            set = error.model,
            errors = error.errors
        )

    # redirects the user to the show page of the set that
    # was just created (normal workflow)
    return flask.redirect(
        flask.url_for("show_set", set_id = set.set_id)
    )
예제 #22
0
def update_device(device_id):
    # finds the current device and applies the provided
    # arguments and then saves it into the data source,
    # all the validations should be ran upon the save operation
    device = models.Device.get(device_id = device_id)
    device.apply()
    try: device.save()
    except quorum.ValidationError as error:
        return flask.render_template(
            "device/edit.html.tpl",
            link = "devices",
            sub_link = "edit",
            device = error.model,
            errors = error.errors
        )

    # redirects the user to the show page of the device that
    # was just updated
    return flask.redirect(
        flask.url_for("show_device", device_id = device_id)
    )
예제 #23
0
def update_set(set_id):
    # finds the current set and applies the provided
    # arguments and then saves it into the data source,
    # all the validations should be ran upon the save operation
    set = models.Set.get_a(set_id = set_id)
    set.apply()
    try: set.save()
    except quorum.ValidationError as error:
        return flask.render_template(
            "set/edit.html.tpl",
            link = "sets",
            sub_link = "edit",
            set = error.model,
            errors = error.errors
        )

    # redirects the user to the show page of the set that
    # was just updated
    return flask.redirect(
        flask.url_for("show_set", set_id = set_id)
    )
예제 #24
0
def update_account(username):
    # finds the current account and applies the provided
    # arguments and then saves it into the data source,
    # all the validations should be ran upon the save operation
    account = models.Account.get(username = username)
    account.apply()
    try: account.save()
    except quorum.ValidationError as error:
        return flask.render_template(
            "account/edit.html.tpl",
            link = "accounts",
            sub_link = "edit",
            account = error.model,
            errors = error.errors
        )

    # redirects the user to the show page of the account that
    # was just updated
    return flask.redirect(
        flask.url_for("show_account", username = username)
    )
예제 #25
0
def update_camera(camera_id):
    # finds the current camera and applies the provided
    # arguments and then saves it into the data source,
    # all the validations should be ran upon the save operation
    camera = models.Camera.get_a(camera_id = camera_id)
    camera.apply()
    try: camera.save()
    except quorum.ValidationError as error:
        return flask.render_template(
            "camera/edit.html.tpl",
            link = "cameras",
            sub_link = "edit",
            camera = error.model,
            errors = error.errors
        )

    # redirects the user to the show page of the camera that
    # was just updated
    return flask.redirect(
        flask.url_for("show_camera", camera_id = camera_id)
    )
예제 #26
0
def list_accounts():
    return flask.render_template(
        "account/list.html.tpl",
        link = "accounts",
        sub_link = "list"
    )
예제 #27
0
def list_sets():
    return flask.render_template(
        "set/list.html.tpl",
        link = "sets",
        sub_link = "list"
    )
예제 #28
0
def settings():
    return flask.render_template(
        "settings/show.html.tpl",
        link = "settings",
        sub_link = "show"
    )
예제 #29
0
def import_a():
    return flask.render_template(
        "settings/import.html.tpl",
        link = "settings",
        sub_link = "import"
    )
예제 #30
0
def list_cameras():
    return flask.render_template(
        "camera/list.html.tpl",
        link = "cameras",
        sub_link = "list"
    )