def proposal(request, proposal_id): try: proposal = Proposal.load(request.session, id=proposal_id) except NoResultFound: return {}, 'notfound.phtml', 404 problem = proposal.problem img64 = proposal.img model = proposal.model if model is not None: model = model.decode('base64') user = request.logged_user() if user is None: vote = None else: try: vote = Vote.load(request.session, proposal_id=proposal.id, user_id=user.id) except NoResultFound: vote = None view = {'problem': problem, 'proposal': proposal, 'vote': vote, 'img64': img64, 'model': model} return view, 'proposal.phtml'
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}})
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({})