Пример #1
0
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")
    )
Пример #2
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,
        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"
        )
    )
Пример #3
0
def new_log():
    return flask.render_template(
        "log/new.html.tpl",
        link = "logs",
        sub_link = "create",
        log = {},
        errors = {}
    )
Пример #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 video_event():
    return flask.render_template(
        "event/video.html.tpl",
        link = "events",
        sub_link = "video",
        video = {},
        errors = {}
    )
Пример #6
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
    )
Пример #7
0
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 = {}
    )
Пример #8
0
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 = {}
    )
Пример #9
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 = {}
    )
Пример #10
0
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 = {}
    )
Пример #11
0
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 = {}
    )
Пример #12
0
def new_account():
    return flask.render_template(
        "account/new.html.tpl",
        link = "accounts",
        sub_link = "create",
        account = {
            "cameras" : {}
        },
        errors = {}
    )
Пример #13
0
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 = {}
    )
Пример #14
0
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")
    )
Пример #15
0
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")
    )
Пример #16
0
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)
    )
Пример #17
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)
    )
Пример #18
0
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")
    )
Пример #19
0
def index():
    return flask.render_template(
        "index.html.tpl",
        link = "home"
    )
Пример #20
0
def list_accounts():
    return flask.render_template(
        "account/list.html.tpl",
        link = "accounts",
        sub_link = "list"
    )
Пример #21
0
def base_config():
    return flask.render_template(
        "config/base.html.tpl",
        link = "config",
        sub_link = "base"
    )
Пример #22
0
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)
Пример #23
0
def list_logs():
    return flask.render_template(
        "log/list.html.tpl",
        link = "logs",
        sub_link = "list"
    )
Пример #24
0
def board():
    variant = quorum.get_field("variant", "sales")
    return flask.render_template(
        "board.html.tpl",
        variant = variant
    )
Пример #25
0
def list_debug():
    return flask.render_template("debug/list.html.tpl", link="debug")
Пример #26
0
def base_events():
    return flask.render_template(
        "event/base.html.tpl",
        link = "events",
        sub_link = "base"
    )
Пример #27
0
def about():
    return flask.render_template(
        "about.html.tpl",
        link = "about"
    )
Пример #28
0
def import_a():
    return flask.render_template(
        "settings/import.html.tpl",
        link = "settings",
        sub_link = "import"
    )
Пример #29
0
def settings():
    return flask.render_template(
        "settings/show.html.tpl",
        link = "settings",
        sub_link = "show"
    )
Пример #30
0
def signin():
    next = quorum.get_field("next")
    return flask.render_template(
        "signin.html.tpl",
        next = next
    )