Exemple #1
0
def sign_up():
    form = PlayerInsertForm.PlayerInsertForm()
    if form.validate_on_submit():
        model.insert(
            "player", {
                "name":
                form.username.data,
                "password":
                bcrypt.generate_password_hash(
                    form.password.data).decode("utf-8"),
                "email":
                form.email.data
            })
        return redirect(url_for('index'))
    return render_template("sign_up.html", form=form)
Exemple #2
0
def session_add():
    form = SessionInsertForm.SessionInsertForm()
    #  setting default values for from elements
    form.adventures.choices = model.get_pairs("adventure")
    form.moderator.choices = model.get_pairs("player")
    form.moderator.process_data(current_user.get_id())

    if form.validate_on_submit():  # on form submit
        adventure_insert = {
            "date": form.date.data,
            "place": form.place.data,
            "moderator": form.moderator.data
        }
        model.insert("sessions", adventure_insert)
        session_id = model.get_last_id("sessions")
        for adv in form.adventures.data:
            model.insert("adventure_session", {
                "adventure_id": adv,
                "session_id": session_id
            })
        return redirect(url_for('adventures'))
    return render_template("session_add.html", form=form)
Exemple #3
0
def character_add(player_id=None):
    user_id = current_user.get_id()

    if current_user.get_role() == "admin" or user_id == player_id:
        form = CharacterInsertForm.CharacterInsertForm()
        form.player.choices = model.get_pairs('player')
        form.race.choices = model.get_pairs('race')
        form.player.process_data(player_id)
        if form.validate_on_submit():
            model.insert(
                "character", {
                    "name": form.name.data,
                    "race": form.race.data,
                    "class": form.c_class.data,
                    "level": form.level.data,
                    "player_id": form.player.data
                })
            return redirect(url_for('players'))
        return render_template("character_add.html", form=form)

    elif user_id != player_id:
        flash("Sem nesmíte", "danger")
        return redirect(url_for('index'))
Exemple #4
0
def adventure_add():
    form = AdventureInsertForm.AdventureInsertForm()
    #  setting default values for form elements
    form.authors.choices = model.get_pairs("author")
    form.pj.choices = model.get_pairs("player")
    form.location.choices = model.get_pairs("location")
    form.game_elements.choices = model.get_pairs("game_element")
    form.characters.choices = model.get_pairs("character")
    form.pj.process_data(current_user.get_id())

    if form.validate_on_submit():  # on form submit
        adventure_insert = {
            "objective": form.objective.data,
            "difficulty": form.difficulty.data,
            "PJ_ID": form.pj.data,
            "location_id": form.location.data
        }
        model.insert("adventure", adventure_insert)
        adventure_id = model.get_last_id("adventure")
        for author in form.authors.data:
            model.insert("adventure_author", {
                "adventure_id": adventure_id,
                "author_id": author
            })
        for char in form.characters.data:
            model.insert("character_adventure", {
                "adventure_id": adventure_id,
                "character_id": char
            })
        for game_element in form.game_elements.data:
            model.insert("adventure_game_element", {
                "adventure_id": adventure_id,
                "game_element": game_element
            })
        return redirect(url_for('adventures'))
    return render_template("adventure_add.html", form=form)
Exemple #5
0
def admin():
    if current_user.get_role() != "admin":
        flash("Sem nesmíte", "danger")
        return redirect(url_for('index'))

    forms = {}

    forms["author"] = AuthorInsertForm.AuthorInsertForm()
    if forms["author"].validate_on_submit():
        model.insert("author", {"name": forms["author"].name.data})
        return redirect(url_for('admin'))

    forms["equipment"] = EquipmentInsertForm.EquipmentInsertForm()
    if forms["equipment"].validate_on_submit():
        model.insert("equipment", {"type": forms["equipment"].type.data})
        return redirect(url_for('admin'))

    forms["enemy"] = EnemyInsertForm.EnemyInsertForm()
    forms["enemy"].race.choices = model.get_pairs('race')
    if forms["enemy"].validate_on_submit():
        model.insert("game_element", {"name": forms["enemy"].name.data})
        element_id = model.get_last_element_id()
        model.insert(
            "enemy", {
                "element_id": element_id,
                "level": forms["enemy"].level.data,
                "race_id": forms["enemy"].race.data
            })
        return redirect(url_for('admin'))

    forms["maps"] = MapInsertForm.MapInsertForm()
    if forms["maps"].validate_on_submit():
        model.insert("game_element", {"name": forms["maps"].name.data})
        element_id = model.get_last_element_id()
        model.insert("map", {
            "scale": forms["maps"].scale.data,
            "element_id": element_id
        })
        return redirect(url_for('admin'))

    return render_template("admin.html", forms=forms)