예제 #1
0
파일: routes.py 프로젝트: ubergeek42/gjms
def gjms_config():
    """ Setup backend config """
    form = gjms.backend.forms.config(flask.request.form)

    if flask.request.method == "POST":
        if form.validate_on_submit():
            parser.set("gjms", "label", form.label.data)
            parser.set("gjms", "manager", form.manager.data)
            parser.set("gjms", "manager_email", form.m_email.data)
            parser.set("gjms", "theme_voting", form.v_theme.data)
            parser.set("gjms", "game_ratings", form.ratings.data)
            parser.set("gjms", "game_comments", form.comments.data)

            parser.set("gjms", "database_engine", form.engine.data)
            parser.set("gjms", "database_host", form.host.data)
            parser.set("gjms", "database_port", form.port.data)
            parser.set("gjms", "database_user", form.user.data)
            parser.set("gjms", "database_password", form.password.data)
            parser.set("gjms", "database", form.db.data)

            if form.engine.data == "sqlite":
                db_url = "sqlite:///%s?check_same_thread=False" % form.host.data
            elif form.engine.data != "sqlite" and form.port.data == "":
                db_url = "%s://%s:%s@%s/%s" % (form.engine.data, form.user.data, form.password.data, form.host.data, form.db.data)
            else:
                db_url = "%s://%s:%s@%s:%s/%s" % (form.engine.data, form.user.data, form.password.data, form.host.data, form.port.data, form.db.data)

            gjms.util.database.setup(db_url)
            elixir.setup_all()
            elixir.create_all()

            parser.set("gjms", "db_url", db_url)
            parser.set("gjms", "database_setup", True)

            cfgfile = open(os.path.abspath(os.path.dirname(__file__)+"/../gjms.cfg"), "w")
            gjms.config.parser.write(cfgfile)

            flask.flash(u"Settings saved!", "success")
        else:
            flask.flash(u"Woops! That didn't work. Check below for details.", "error")
    else:
        form.label.data = parser.get("gjms", "label")
        form.manager.data = parser.get("gjms", "manager")
        form.m_email.data = parser.get("gjms", "manager_email")
        form.v_theme.data = parser.getboolean("gjms", "theme_voting")
        form.ratings.data = parser.getboolean("gjms", "game_ratings")
        form.comments.data = parser.getboolean("gjms", "game_comments")

        form.engine.data = parser.get("gjms", "database_engine")
        form.host.data = parser.get("gjms", "database_host")
        form.port.data = parser.get("gjms", "database_port")
        form.user.data = parser.get("gjms", "database_user")
        form.password.data = parser.get("gjms", "database_password")
        form.db.data = parser.get("gjms", "database")

    system = gjms.core.system.get(1)
    return flask.render_template("backend/config.html", form=form, time=datetime, system=system, config=parser, users=gjms.core.users, events=gjms.core.events, games=gjms.core.games, platforms=gjms.core.platforms, ratings=gjms.core.ratings)
예제 #2
0
def gjms_config():
    """ Setup backend config """
    form = gjms.backend.forms.config(flask.request.form)

    if flask.request.method == "POST":
        if form.validate_on_submit():
            parser.set("gjms", "label", form.label.data)
            parser.set("gjms", "manager", form.manager.data)
            parser.set("gjms", "manager_email", form.m_email.data)
            parser.set("gjms", "theme_voting", form.v_theme.data)
            parser.set("gjms", "game_ratings", form.ratings.data)
            parser.set("gjms", "game_comments", form.comments.data)

            parser.set("gjms", "database_engine", form.engine.data)
            parser.set("gjms", "database_host", form.host.data)
            parser.set("gjms", "database_port", form.port.data)
            parser.set("gjms", "database_user", form.user.data)
            parser.set("gjms", "database_password", form.password.data)
            parser.set("gjms", "database", form.db.data)

            if form.engine.data == "sqlite":
                db_url = "sqlite:///%s?check_same_thread=False" % form.host.data
            elif form.engine.data != "sqlite" and form.port.data == "":
                db_url = "%s://%s:%s@%s/%s" % (
                    form.engine.data, form.user.data, form.password.data,
                    form.host.data, form.db.data)
            else:
                db_url = "%s://%s:%s@%s:%s/%s" % (
                    form.engine.data, form.user.data, form.password.data,
                    form.host.data, form.port.data, form.db.data)

            gjms.util.database.setup(db_url)
            elixir.setup_all()
            elixir.create_all()

            parser.set("gjms", "db_url", db_url)
            parser.set("gjms", "database_setup", True)

            cfgfile = open(
                os.path.abspath(os.path.dirname(__file__) + "/../gjms.cfg"),
                "w")
            gjms.config.parser.write(cfgfile)

            flask.flash(u"Your settings have been saved!", "success")
        else:
            flask.flash(u"Woops! That didn't work! Check below for details.",
                        "error")
    else:
        form.label.data = parser.get("gjms", "label")
        form.manager.data = parser.get("gjms", "manager")
        form.m_email.data = parser.get("gjms", "manager_email")
        form.v_theme.data = parser.getboolean("gjms", "theme_voting")
        form.ratings.data = parser.getboolean("gjms", "game_ratings")
        form.comments.data = parser.getboolean("gjms", "game_comments")

        form.engine.data = parser.get("gjms", "database_engine")
        form.host.data = parser.get("gjms", "database_host")
        form.port.data = parser.get("gjms", "database_port")
        form.user.data = parser.get("gjms", "database_user")
        form.password.data = parser.get("gjms", "database_password")
        form.db.data = parser.get("gjms", "database")

    if parser.getboolean("gjms", "database_setup") is False:
        flask.flash(u"Welcome to the Game Jam Management System!", "success")
        flask.flash(
            u"To get you started, we need to set up a database for the system to use.",
            "note")
        flask.flash(
            u"""
            If you want to get started quickly, just hit the Save button and
            be done with it. The system is pre-configured to use SQLite.
            You can use MySQL or Postgres too, though! It's up to you, really.
        """, "note")

    system = gjms.core.system.get(1)
    return flask.render_template("backend/config.haml",
                                 form=form,
                                 time=datetime,
                                 system=system,
                                 config=parser,
                                 users=gjms.core.users,
                                 events=gjms.core.events,
                                 games=gjms.core.games,
                                 platforms=gjms.core.platforms,
                                 ratings=gjms.core.ratings)
예제 #3
0
def gjms_config():
    """ Setup backend config """
    form = gjms.backend.forms.config(flask.request.form)

    if flask.request.method == "POST":
        if form.validate_on_submit():
            parser.set("gjms", "label", form.label.data)
            parser.set("gjms", "manager", form.manager.data)
            parser.set("gjms", "manager_email", form.m_email.data)
            parser.set("gjms", "theme_voting", form.v_theme.data)
            parser.set("gjms", "game_ratings", form.ratings.data)
            parser.set("gjms", "game_comments", form.comments.data)

            parser.set("gjms", "database_engine", form.engine.data)
            parser.set("gjms", "database_host", form.host.data)
            parser.set("gjms", "database_port", form.port.data)
            parser.set("gjms", "database_user", form.user.data)
            parser.set("gjms", "database_password", form.password.data)
            parser.set("gjms", "database", form.db.data)

            if form.engine.data == "sqlite":
                db_url = "sqlite:///%s?check_same_thread=False" % form.host.data
            elif form.engine.data != "sqlite" and form.port.data == "":
                db_url = "%s://%s:%s@%s/%s" % (form.engine.data, form.user.data, form.password.data, form.host.data, form.db.data)
            else:
                db_url = "%s://%s:%s@%s:%s/%s" % (form.engine.data, form.user.data, form.password.data, form.host.data, form.port.data, form.db.data)

            gjms.util.database.setup(db_url)
            elixir.setup_all()
            elixir.create_all()

            parser.set("gjms", "db_url", db_url)
            parser.set("gjms", "database_setup", True)

            cfgfile = open(os.path.abspath(os.path.dirname(__file__)+"/../gjms.cfg"), "w")
            gjms.config.parser.write(cfgfile)

            flask.flash(u"Your settings have been saved!", "success")
        else:
            flask.flash(u"Woops! That didn't work! Check below for details.", "error")
    else:
        form.label.data = parser.get("gjms", "label")
        form.manager.data = parser.get("gjms", "manager")
        form.m_email.data = parser.get("gjms", "manager_email")
        form.v_theme.data = parser.getboolean("gjms", "theme_voting")
        form.ratings.data = parser.getboolean("gjms", "game_ratings")
        form.comments.data = parser.getboolean("gjms", "game_comments")

        form.engine.data = parser.get("gjms", "database_engine")
        form.host.data = parser.get("gjms", "database_host")
        form.port.data = parser.get("gjms", "database_port")
        form.user.data = parser.get("gjms", "database_user")
        form.password.data = parser.get("gjms", "database_password")
        form.db.data = parser.get("gjms", "database")

    if parser.getboolean("gjms", "database_setup") is False:
        flask.flash(u"Welcome to the Game Jam Management System!", "success")
        flask.flash(u"To get you started, we need to set up a database for the system to use.", "note")
        flask.flash(u"""
            If you want to get started quickly, just hit the Save button and
            be done with it. The system is pre-configured to use SQLite.
            You can use MySQL or Postgres too, though! It's up to you, really.
        """, "note")

    system = gjms.core.system.get(1)
    return flask.render_template("backend/config.haml", form=form, time=datetime, system=system, config=parser, users=gjms.core.users, events=gjms.core.events, games=gjms.core.games, platforms=gjms.core.platforms, ratings=gjms.core.ratings)