Exemple #1
0
def communities_update(community_id):
    c = Community.query.get(community_id)

    if not c:
        return render_template("404.html", res_type="community"), 404

    if c.id not in [c.id for c in Community.get_allowed()]:
        return login_manager.unauthorized()

    old_c = copy.deepcopy(c)
    form = CommunityFormUpdate(request.form)

    if not form.validate():
        return render_template("communities/update.html",
                               community=c, form=form)

    if form.address.data:
        c.address = form.address.data

    try:
        db.session().commit()
    except exc.SQLAlchemyError as e:
        db.session().rollback()
        msg = "This address is already taken, please choose another one."
        form.address.errors.append(msg)
        return render_template("communities/update.html",
                               community=old_c, form=form)

    return redirect(url_for("communities_single", community_id=c.id))
Exemple #2
0
def communities_delete_ask(community_id):
    c = Community.query.get(community_id)

    if not c:
        return render_template("404.html", res_type="community"), 404

    if c.id not in [c.id for c in Community.get_allowed()]:
        return login_manager.unauthorized()

    return render_template("communities/delete.html", community=c)
Exemple #3
0
def communities_form_update(community_id):
    c = Community.query.get(community_id)

    if not c:
        return render_template("404.html", res_type="community"), 404

    if c.id not in [c.id for c in Community.get_allowed()]:
        return login_manager.unauthorized()

    form = CommunityFormUpdate()
    return render_template("communities/update.html", community=c, form=form)
Exemple #4
0
def communities_single(community_id):
    c = Community.query.get(community_id)

    if not c:
        return render_template("404.html", res_type="community"), 404

    show_accounts = False
    if c.id in [c.id for c in Community.get_allowed()]:
        show_accounts = True

    return render_template("communities/single.html",
                           community=c, show_accounts=show_accounts)
Exemple #5
0
def communities_delete(community_id):
    c = Community.query.get(community_id)

    if not c:
        return render_template("404.html", res_type="community"), 404

    if c.id not in [c.id for c in Community.get_allowed()]:
        return login_manager.unauthorized()

    db.session.delete(c)
    db.session.commit()
    return redirect(url_for("communities_list"))
Exemple #6
0
def communities_create():
    form = CommunityFormCreate(request.form)

    if not form.validate():
        return render_template("communities/new.html", form=form)

    c = Community(form.address.data)

    try:
        db.session().add(c)
        db.session().commit()
    except exc.SQLAlchemyError as e:
        db.session().rollback()
        msg = "This address is already taken, please choose another one."
        form.address.errors.append(msg)
        return render_template("communities/new.html", form=form)

    if current_user.is_authenticated and ADMIN in current_user.roles():
        return redirect(url_for("communities_single", community_id=c.id))

    return redirect(url_for("communities_list"))
Exemple #7
0
def communities_list():
    return render_template("communities/list.html",
                           communities=Community.list_with_stats())