def login(): # retrieves the next field that may be used latter # to re-direct the user back to the original place next = quorum.get_field("next") # retrieves the username and the password fields # and uses them to run the login logic raising an # error in case an invalid authentication occurs 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, next = next, 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["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( next or 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, multiple = quorum.resolve() ) 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 new_log(): return flask.render_template( "log/new.html.tpl", link = "logs", sub_link = "create", log = {}, errors = {} )
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 video_event(): return flask.render_template( "event/video.html.tpl", link = "events", sub_link = "video", video = {}, 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 mail_config(): config = models.MailConfig.get(raise_e = False) or {} return flask.render_template( "config/mail.html.tpl", link = "config", sub_link = "mail", config = config, errors = {} )
def basic_config(): config = models.BasicConfig.get(raise_e = False) or {} return flask.render_template( "config/basic.html.tpl", link = "config", sub_link = "basic", config = config, errors = {} )
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 pending_config(): config = models.PendingConfig.get(raise_e = False) or {} return flask.render_template( "config/pending.html.tpl", link = "config", sub_link = "pending", config = config, errors = {} )
def omni_config(): config = models.OmniConfig.get(raise_e = False) or {} return flask.render_template( "config/omni.html.tpl", link = "config", sub_link = "omni", config = config, errors = {} )
def new_account(): return flask.render_template( "account/new.html.tpl", link = "accounts", sub_link = "create", account = { "cameras" : {} }, errors = {} )
def github_config(): config = models.GithubConfig.get(raise_e = False) or {} if config: api = config.get_api() repos = api.self_repos() else: repos = [] return flask.render_template( "config/github.html.tpl", link = "config", sub_link = "github", config = config, repos = repos, errors = {} )
def do_basic_config(): config = models.BasicConfig.singleton() try: config.save() except quorum.ValidationError as error: return flask.render_template( "config/basic.html.tpl", link = "config", sub_link = "basic", config = error.model, errors = error.errors ) # redirects the user to the overall configuration # selection, as this is the default behavior return flask.redirect( flask.url_for("base_config") )
def create_log(): # creates the new log, using the provided arguments and # then saves it into the data source, all the validations # should be ran upon the save operation log = models.Log.new() try: log.save() except quorum.ValidationError as error: return flask.render_template( "log/new.html.tpl", link = "logs", sub_link = "create", log = error.model, errors = error.errors ) # redirects the user to the page that displays the list # of logs for the current account in session return flask.redirect( flask.url_for("list_logs") )
def create_account(): # creates the new account, using the provided arguments and # then saves it into the data source, all the validations # should be ran upon the save operation account = models.Account.new() try: account.save() except quorum.ValidationError as error: return flask.render_template( "account/new.html.tpl", link = "accounts", sub_link = "create", account = 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_account", username = account.username) )
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 github_oauth(): code = quorum.get_field("code") next = quorum.get_field("state") error = quorum.get_field("error") error_description = quorum.get_field("error_description") if error: return flask.render_template( "error.html.tpl", error = error, description = error_description ) api = models.GithubConfig.get_api() access_token = api.oauth_access(code) user = api.self_user() config = models.GithubConfig.singleton() config.access_token = access_token config.username = user["login"] config.save() flask.session["gh.access_token"] = access_token return flask.redirect( next or flask.url_for("index") )
def index(): return flask.render_template( "index.html.tpl", link = "home" )
def list_accounts(): return flask.render_template( "account/list.html.tpl", link = "accounts", sub_link = "list" )
def base_config(): return flask.render_template( "config/base.html.tpl", link = "config", sub_link = "base" )
def show_debug(id): debug = models.Debug.get(id=id) return flask.render_template("debug/show.html.tpl", link="debug", sub_link="show", debug=debug)
def list_logs(): return flask.render_template( "log/list.html.tpl", link = "logs", sub_link = "list" )
def board(): variant = quorum.get_field("variant", "sales") return flask.render_template( "board.html.tpl", variant = variant )
def list_debug(): return flask.render_template("debug/list.html.tpl", link="debug")
def base_events(): return flask.render_template( "event/base.html.tpl", link = "events", sub_link = "base" )
def about(): return flask.render_template( "about.html.tpl", link = "about" )
def import_a(): return flask.render_template( "settings/import.html.tpl", link = "settings", sub_link = "import" )
def settings(): return flask.render_template( "settings/show.html.tpl", link = "settings", sub_link = "show" )
def signin(): next = quorum.get_field("next") return flask.render_template( "signin.html.tpl", next = next )