Example #1
0
def community(community):
    community_ref = Community.get_or_none(Community.name == community)
    return object_list('community.html',
                       Proposal.from_community(community_ref).order_by(
                           Proposal.timestamp.desc()),
                       community=community_ref,
                       check_bounds=False)
Example #2
0
def post_revisions(community, slug):
    query = Proposal.public()
    community = Community.get_or_none(Community.name == community)
    entry = get_object_or_404(query, Proposal.slug == slug,
                              Proposal.community == community)
    return render_template('post_revisions.html',
                           entry=entry,
                           community=community)
Example #3
0
def post_submit(user=None, community=None):
    entry = Proposal(community='', title='', content='')

    if community is None:
        community = request.form.get('community') or None
        if community and community[0:2] == "c/":
            community = community[2:]

    if request.method == 'POST':
        try:
            entry.title = request.form.get('title') or ''
            entry.content = request.form.get('content') or ''
            entry.published = request.form.get('published') or True
            entry.vote_options = request.form.get('internalvote') or None
            entry.usepositions = (True if request.form.get('use-positions')
                                  == '' else False)
            entry.author = User.get(User.id == current_user.id)
            entry.community = Community.get(Community.name == community)

            if not (entry.title and entry.community and entry.author):
                flash('Community and Title are required.', 'error')

            else:
                entry.update_search_index()

                # Wrap the call to save in a transaction so we can roll it back
                # cleanly in the event of an integrity error.
                try:
                    with database.atomic():
                        entry.save()

                except peewee.IntegrityError:
                    flash('This title is already in use.', 'error')
                else:

                    if entry.published:
                        return redirect(
                            url_for('post_details',
                                    community=entry.community.name,
                                    slug=entry.slug))
                    else:
                        abort(404)

        except peewee.DoesNotExist:
            flash('Community and Title are required.', 'error')

    if community is not None:
        community = Community.get_or_none(Community.name == community)

    return render_template('submit.html', entry=entry, community=community)
Example #4
0
def community_rss(community):
    community_ref = Community.get_or_none(Community.name == community)
    response = make_response(community_ref.rss_feed)
    response.headers['Content-Type'] = 'application/rss+xml; charset=utf-8'
    return response