Esempio n. 1
0
def deletesession(name, slug):
    space = ProposalSpace.query.filter_by(name=name).first()
    if not space:
        abort(404)
    proposal_id = int(slug.split('-')[0])
    proposal = Proposal.query.get(proposal_id)
    if not proposal:
        abort(404)
    if not lastuser.has_permission('siteadmin') and proposal.user != g.user:
        abort(403)
    form = ConfirmDeleteForm()
    if form.validate_on_submit():
        if 'delete' in request.form:
            comments = Comment.query.filter_by(commentspace=proposal.comments).order_by('created_at').all()
            for comment in comments:
                db.session.delete(comment)
            db.session.delete(proposal.comments)
            votes = Vote.query.filter_by(votespace=proposal.votes).all()
            for vote in votes:
                db.session.delete(vote)
            db.session.delete(proposal.votes)
            db.session.delete(proposal)
            db.session.commit()
            flash("Your proposal has been deleted", "info")
            return redirect(url_for('viewspace', name=name))
        else:
            return redirect(url_for('viewsession', name=name, slug=slug))
    return render_template('delete.html', form=form, title=u"Confirm delete",
        message=u"Do you really wish to delete your proposal '%s'? "
                u"This will remove all votes and comments as well. This operation "
                u"is permanent and cannot be undone." % proposal.title)
Esempio n. 2
0
def deletesession(name, slug):
    space = ProposalSpace.query.filter_by(name=name).first()
    if not space:
        abort(404)
    proposal_id = int(slug.split('-')[0])
    proposal = Proposal.query.get(proposal_id)
    if not proposal:
        abort(404)
    if not lastuser.has_permission('siteadmin') and proposal.user != g.user:
        abort(403)
    form = ConfirmDeleteForm()
    if form.validate_on_submit():
        if 'delete' in request.form:
            comments = Comment.query.filter_by(
                commentspace=proposal.comments).order_by('created_at').all()
            for comment in comments:
                db.session.delete(comment)
            db.session.delete(proposal.comments)
            votes = Vote.query.filter_by(votespace=proposal.votes).all()
            for vote in votes:
                db.session.delete(vote)
            db.session.delete(proposal.votes)
            db.session.delete(proposal)
            db.session.commit()
            flash("Your proposal has been deleted", "info")
            return redirect(url_for('viewspace', name=name))
        else:
            return redirect(url_for('viewsession', name=name, slug=slug))
    return render_template(
        'delete.html',
        form=form,
        title=u"Confirm delete",
        message=u"Do you really wish to delete your proposal '%s'? "
        u"This will remove all votes and comments as well. This operation "
        u"is permanent and cannot be undone." % proposal.title)
Esempio n. 3
0
def proposal_data(proposal):
    """
    Return proposal data suitable for a JSON dump. Request helper, not to be used standalone.
    """
    votes_count = None
    votes_groups = None
    if lastuser.has_permission('siteadmin'):
        votes_count = len(proposal.votes.votes)
        votes_groups = dict([(g.name, 0) for g in proposal.proposal_space.usergroups])
        groupuserids = dict([(g.name, [u.userid for u in g.users]) for g in proposal.proposal_space.usergroups])
        for vote in proposal.votes.votes:
            for groupname, userids in groupuserids.items():
                if vote.user.userid in userids:
                    votes_groups[groupname] += -1 if vote.votedown else +1

    return {'id': proposal.id,
            'name': proposal.urlname,
            'title': proposal.title,
            'url': url_for('viewsession', name=proposal.proposal_space.name, slug=proposal.urlname, _external=True),
            'proposer': proposal.user.fullname,
            'speaker': proposal.speaker.fullname if proposal.speaker else None,
            'email': proposal.email if lastuser.has_permission('siteadmin') else None,
            'phone': proposal.phone if lastuser.has_permission('siteadmin') else None,
            'section': proposal.section.title if proposal.section else None,
            'type': proposal.session_type,
            'level': proposal.technical_level,
            'objective': proposal.objective_html,
            'description': proposal.description_html,
            'requirements': proposal.requirements_html,
            'slides': proposal.slides,
            'links': proposal.links,
            'bio': proposal.bio_html,
            'votes': proposal.votes.count,
            'votes_count': votes_count,
            'votes_groups': votes_groups,
            'comments': proposal.comments.count,
            'submitted': proposal.created_at.isoformat() + 'Z',
            'confirmed': proposal.confirmed,
            }
Esempio n. 4
0
def editsession(name, slug):
    space = ProposalSpace.query.filter_by(name=name).first()
    if not space:
        abort(404)
    proposal_id = int(slug.split('-')[0])
    proposal = Proposal.query.get(proposal_id)
    if not proposal:
        abort(404)
    if proposal.user != g.user and not lastuser.has_permission('siteadmin'):
        abort(403)
    form = ProposalForm(obj=proposal)
    if not proposal.session_type:
        del form.session_type  # Remove this if we're editing a proposal that had no session type
    form.section.query = ProposalSpaceSection.query.filter_by(proposal_space=space, public=True).order_by('title')
    if len(list(form.section.query.all())) == 0:
        # Don't bother with sections when there aren't any
        del form.section
    # Set markdown flag to True for fields that need markdown conversion
    markdown_attrs = ('description', 'objective', 'requirements', 'bio')
    for name in markdown_attrs:
        attr = getattr(form, name)
        attr.flags.markdown = True
    if proposal.user != g.user:
        del form.speaking
    elif request.method == 'GET':
        form.speaking.data = proposal.speaker == g.user
    if form.validate_on_submit():
        form.populate_obj(proposal)
        proposal.name = makename(proposal.title)
        if proposal.user == g.user:
            # Only allow the speaker to change this status
            if form.speaking.data:
                proposal.speaker = g.user
            else:
                if proposal.speaker == g.user:
                    proposal.speaker = None
        # Set *_html attributes after converting markdown text
        for name in markdown_attrs:
            attr = getattr(proposal, name)
            html_attr = name + '_html'
            setattr(proposal, html_attr, markdown(attr))
        proposal.edited_at = datetime.utcnow()
        db.session.commit()
        flash("Your changes have been saved", "info")
        return redirect(url_for('viewsession', name=space.name, slug=proposal.urlname), code=303)
    return render_template('autoform.html', form=form, title="Edit session proposal", submit="Save changes",
        breadcrumbs=[(url_for('viewspace', name=space.name), space.title),
                     (url_for('viewsession', name=space.name, slug=proposal.urlname), proposal.title)],
        message=Markup(
            'This form uses <a href="http://daringfireball.net/projects/markdown/">Markdown</a> for formatting.'))
Esempio n. 5
0
def viewspace_csv(name):
    space = ProposalSpace.query.filter_by(name=name).first_or_404()
    if lastuser.has_permission('siteadmin'):
        usergroups = [g.name for g in space.usergroups]
    else:
        usergroups = []
    proposals = Proposal.query.filter_by(proposal_space=space).order_by(db.desc('created_at')).all()
    outfile = StringIO()
    out = unicodecsv.writer(outfile, encoding='utf-8')
    out.writerow(proposal_headers + ['votes_' + group for group in usergroups])
    for proposal in proposals:
        out.writerow(proposal_data_flat(proposal, usergroups))
    outfile.seek(0)
    return Response(unicode(outfile.getvalue(), 'utf-8'), mimetype='text/plain')
Esempio n. 6
0
def viewspace_csv(name):
    space = ProposalSpace.query.filter_by(name=name).first_or_404()
    if lastuser.has_permission('siteadmin'):
        usergroups = [g.name for g in space.usergroups]
    else:
        usergroups = []
    proposals = Proposal.query.filter_by(proposal_space=space).order_by(
        db.desc('created_at')).all()
    outfile = StringIO()
    out = unicodecsv.writer(outfile, encoding='utf-8')
    out.writerow(proposal_headers + ['votes_' + group for group in usergroups])
    for proposal in proposals:
        out.writerow(proposal_data_flat(proposal, usergroups))
    outfile.seek(0)
    return Response(unicode(outfile.getvalue(), 'utf-8'),
                    mimetype='text/plain')
Esempio n. 7
0
def proposal_data(proposal):
    """
    Return proposal data suitable for a JSON dump. Request helper, not to be used standalone.
    """
    votes_count = None
    votes_groups = None
    if lastuser.has_permission('siteadmin'):
        votes_count = len(proposal.votes.votes)
        votes_groups = dict([(g.name, 0)
                             for g in proposal.proposal_space.usergroups])
        groupuserids = dict([(g.name, [u.userid for u in g.users])
                             for g in proposal.proposal_space.usergroups])
        for vote in proposal.votes.votes:
            for groupname, userids in groupuserids.items():
                if vote.user.userid in userids:
                    votes_groups[groupname] += -1 if vote.votedown else +1

    return {
        'id':
        proposal.id,
        'name':
        proposal.urlname,
        'title':
        proposal.title,
        'url':
        url_for('viewsession',
                name=proposal.proposal_space.name,
                slug=proposal.urlname,
                _external=True),
        'proposer':
        proposal.user.fullname,
        'speaker':
        proposal.speaker.fullname if proposal.speaker else None,
        'email':
        proposal.email if lastuser.has_permission('siteadmin') else None,
        'phone':
        proposal.phone if lastuser.has_permission('siteadmin') else None,
        'section':
        proposal.section.title if proposal.section else None,
        'type':
        proposal.session_type,
        'level':
        proposal.technical_level,
        'objective':
        proposal.objective_html,
        'description':
        proposal.description_html,
        'requirements':
        proposal.requirements_html,
        'slides':
        proposal.slides,
        'links':
        proposal.links,
        'bio':
        proposal.bio_html,
        'votes':
        proposal.votes.count,
        'votes_count':
        votes_count,
        'votes_groups':
        votes_groups,
        'comments':
        proposal.comments.count,
        'submitted':
        proposal.created_at.isoformat() + 'Z',
        'confirmed':
        proposal.confirmed,
    }
Esempio n. 8
0
def editsession(name, slug):
    space = ProposalSpace.query.filter_by(name=name).first()
    if not space:
        abort(404)
    proposal_id = int(slug.split('-')[0])
    proposal = Proposal.query.get(proposal_id)
    if not proposal:
        abort(404)
    if proposal.user != g.user and not lastuser.has_permission('siteadmin'):
        abort(403)
    form = ProposalForm(obj=proposal)
    if not proposal.session_type:
        del form.session_type  # Remove this if we're editing a proposal that had no session type
    form.section.query = ProposalSpaceSection.query.filter_by(
        proposal_space=space, public=True).order_by('title')
    if len(list(form.section.query.all())) == 0:
        # Don't bother with sections when there aren't any
        del form.section
    # Set markdown flag to True for fields that need markdown conversion
    markdown_attrs = ('description', 'objective', 'requirements', 'bio')
    for name in markdown_attrs:
        attr = getattr(form, name)
        attr.flags.markdown = True
    if proposal.user != g.user:
        del form.speaking
    elif request.method == 'GET':
        form.speaking.data = proposal.speaker == g.user
    if form.validate_on_submit():
        form.populate_obj(proposal)
        proposal.name = makename(proposal.title)
        if proposal.user == g.user:
            # Only allow the speaker to change this status
            if form.speaking.data:
                proposal.speaker = g.user
            else:
                if proposal.speaker == g.user:
                    proposal.speaker = None
        # Set *_html attributes after converting markdown text
        for name in markdown_attrs:
            attr = getattr(proposal, name)
            html_attr = name + '_html'
            setattr(proposal, html_attr, markdown(attr))
        proposal.edited_at = datetime.utcnow()
        db.session.commit()
        flash("Your changes have been saved", "info")
        return redirect(url_for('viewsession',
                                name=space.name,
                                slug=proposal.urlname),
                        code=303)
    return render_template(
        'autoform.html',
        form=form,
        title="Edit session proposal",
        submit="Save changes",
        breadcrumbs=[(url_for('viewspace', name=space.name), space.title),
                     (url_for('viewsession',
                              name=space.name,
                              slug=proposal.urlname), proposal.title)],
        message=Markup(
            'This form uses <a href="http://daringfireball.net/projects/markdown/">Markdown</a> for formatting.'
        ))