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"))
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") )
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 )
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 )
def handler_413(error): return flask.Response( flask.render_template( "error.html.tpl", error = "412 - Precondition failed" ), status = 413 )
def handler_404(error): return flask.Response( flask.render_template( "error.html.tpl", error = "404 - Page not found" ), status = 404 )
def new_device(): return flask.render_template( "device/new.html.tpl", link = "devices", sub_link = "create", device = {}, errors = {} )
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 )
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 )
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 = {} )
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 = {} )
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 = {} )
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 )
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 = {} )
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 )
def new_camera(): return flask.render_template( "camera/new.html.tpl", link = "cameras", sub_link = "create", camera = { "device" : {} }, errors = {} )
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 )
def new_account(): return flask.render_template( "account/new.html.tpl", link = "accounts", sub_link = "create", account = { "cameras" : {} }, errors = {} )
def new_set(): return flask.render_template( "set/new.html.tpl", link = "sets", sub_link = "create", set = { "cameras" : {} }, errors = {} )
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 )
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) )
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) )
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) )
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) )
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) )
def list_accounts(): return flask.render_template( "account/list.html.tpl", link = "accounts", sub_link = "list" )
def list_sets(): return flask.render_template( "set/list.html.tpl", link = "sets", sub_link = "list" )
def settings(): return flask.render_template( "settings/show.html.tpl", link = "settings", sub_link = "show" )
def import_a(): return flask.render_template( "settings/import.html.tpl", link = "settings", sub_link = "import" )
def list_cameras(): return flask.render_template( "camera/list.html.tpl", link = "cameras", sub_link = "list" )