Пример #1
0
def post_comment(request, user):
    proposal_id = int(request.form['proposal_id'])
    try:
        proposal = Proposal.load(request.session, id=proposal_id)
    except NoResultFound:
        return return_json({})

    content = request.form['content']
    content = fromstring(content).text.replace('\n', ' ')
    page_id = 'proposal/%d' % proposal.id

    comment = Comment(time=datetime.utcnow(), user=user,
                      page_id=page_id, content=content)
    request.session.add(comment)
    return return_json({'status': 'ok',
                        'content': content,
                        'user': {'id': user.id,
                                 'alias': user.alias}})
Пример #2
0
def vote(request, user, proposal_id, vote_value):
    try:
        proposal = Proposal.load(request.session, id=proposal_id)
    except NoResultFound:
        return return_json({})

    if proposal.user_id == user.id:
        return return_json({})
        
    
    try:
        vote = Vote.load(request.session, user_id=user.id, proposal_id=proposal.id)
    except NoResultFound:
        vote = Vote(voter=user, proposal=proposal)
        request.session.add(vote)

    vote.is_plus = (not vote_value == 0)

    return return_json({})