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 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 logout(): if "username" in flask.session: del flask.session["username"] if "tokens" in flask.session: del flask.session["tokens"] if "cameras" in flask.session: del flask.session["cameras"] return flask.redirect( flask.url_for("signin") )
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_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_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 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_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 delete_set(set_id): set = models.Set.get_a(set_id = set_id) set.delete() return flask.redirect( flask.url_for("list_sets") )
def delete_camera(camera_id): camera = models.Camera.get_a(camera_id = camera_id) camera.delete() return flask.redirect( flask.url_for("list_cameras") )
def delete_account(username): account = models.Account.get(username = username) account.delete() return flask.redirect( flask.url_for("list_accounts") )
def reset_do(): quorum.drop_mongo_db() return flask.redirect( flask.url_for("settings") )
def delete_device(device_id): device = models.Device.get(device_id = device_id) device.delete() return flask.redirect( flask.url_for("list_devices") )