Exemplo n.º 1
0
def jam_toggle_show_in_finder(jam_slug):
    jam = Jam.query.filter_by(slug = jam_slug).first_or_404()
    r = current_user.getRegistration(jam)
    if not r: abort(404)
    r.show_in_finder = not r.show_in_finder
    db.session.commit()
    flash("You are now %s in the team finder for the jam \"%s\"." % ("shown" if r.show_in_finder else "hidden", jam.title), "success")
    return redirect(jam.url())
Exemplo n.º 2
0
def team_settings(jam_slug):
    jam = Jam.query.filter_by(slug = jam_slug).first_or_404()
    if jam.getStatus().code >= JamStatusCode.RATING:
        flash("The jam rating has started, so changes to the team are locked.", "error")
        return redirect(jam.url())

    r = current_user.getRegistration(jam)
    if not r or not r.team: abort(404)
    team = r.team

    settings_form = TeamSettingsForm(obj=team)
    invite_form = InviteForm()
    invite_username = None

    if settings_form.validate_on_submit():
        settings_form.populate_obj(team)
        team.livestreams.strip()
        db.session.commit()
        flash("The team settings were saved.", "success")
        return redirect(team.url())
    elif invite_form.validate_on_submit():
        invite_username = invite_form.username.data

    if "invite" in request.args:
        invite_username = request.args["invite"]

    if invite_username:
        if not team.canInvite(current_user):
            flash("You cannot invite someone right now.", "error")
            abort(403)

        user = User.query.filter_by(username = invite_username, is_deleted = False).first()
        if not user:
            flash("Could not find user: %s" % invite_username, "error")
        elif user.inTeam(team):
            flash("User %s is already in this team." % invite_username, "warning")
        elif team.getInvitation(user):
            flash("User %s is already invited." % user.username, "warning")
        else:
            i = team.inviteUser(user, current_user)
            flash("Invited user %s." % invite_username, "success")

        return redirect(url_for("team_settings", jam_slug = team.jam.slug))

    return render_template('jam/team/edit.html', team = team, invite_form = invite_form, settings_form = settings_form)
Exemplo n.º 3
0
def create_game(jam_slug):
    jam = Jam.query.filter_by(slug = jam_slug).first_or_404()

    r = current_user.getRegistration(jam)
    if not r or not r.team:
        flash("You cannot create a game without being registered for the jam.", category = "error")
        return redirect(jam.url())
    if r.team.game:
        flash("You already have a game.")
        return redirect(r.team.game.url())

    enabled = (JamStatusCode.RUNNING <= jam.getStatus().code <= JamStatusCode.PACKAGING)

    form = GameCreateForm(request.form, obj = None)
    if enabled and form.validate_on_submit():
        game = Game(r.team, form.title.data)
        db.session.add(game)
        db.session.commit()
        return redirect(url_for("edit_game", jam_slug = jam_slug, game_id = game.id))

    return render_template("jam/game/create.html", jam = jam, enabled = enabled, form = form)