def daemonstatus(): try: daemon_height = Proposal.get_daemon_height() wallet_height = Proposal.get_wallet_height() return dict(walletheight=wallet_height, daemonheight=daemon_height) except: return None
def search(key=None): if not key: return make_response( render_template('search.html', results=None, key='Empty!')) results = Proposal.search(key=key) return make_response( render_template('search.html', results=results, key=key))
def proposal(pid): p = Proposal.find_by_id(pid=pid) p.get_comments() if not p: return make_response(redirect(url_for('proposals'))) return make_response( render_template(('proposal/proposal.html'), proposal=p))
def proposals(status, page, cat): if not isinstance(status, int) and not isinstance(page, int) and not cat: # no args, render overview proposals = { 'proposed': Proposal.find_by_args(status=1, limit=10), 'funding': Proposal.find_by_args(status=2, limit=10), 'wip': Proposal.find_by_args(status=3, limit=10), 'completed': Proposal.find_by_args(status=4, limit=10)} return make_response(render_template('proposal/overview.html', proposals=proposals)) try: if not isinstance(status, int): status = 1 proposals = Proposal.find_by_args(status=status, cat=cat) except: return make_response(redirect(url_for('proposals'))) return make_response(render_template('proposal/proposals.html', proposals=proposals, status=status, cat=cat))
def api_proposals_get(status, cat, limit, offset): try: proposals = Proposal.find_by_args(status=status, cat=cat, limit=limit, offset=offset) except Exception as ex: print(ex) return 'error', 500 return [p.json for p in proposals]
def propsal_comment_reply(cid, pid): from funding.orm.orm import Comment c = Comment.find_by_id(cid) if not c or c.replied_to: return redirect(url_for('proposal', pid=pid)) p = Proposal.find_by_id(pid) if not p: return redirect(url_for('proposals')) if c.proposal_id != p.id: return redirect(url_for('proposals')) return make_response(render_template('comment_reply.html', c=c, pid=pid, cid=cid))
def proposal_comment_edit(cid, pid): from funding.orm.orm import Comment c = Comment.find_by_id(cid) if c.locked: raise Exception('comment is locked, cannot edit or delete') p = Proposal.find_by_id(pid) if not p: return redirect(url_for('proposals')) if c.proposal_id != p.id: return redirect(url_for('proposals')) return make_response( render_template('comment_edit.html', c=c, pid=pid, cid=cid))
def proposal_api_add(title, content, pid, funds_target, addr_receiving, category, status): import markdown2 if current_user.is_anonymous: return make_response(jsonify('err'), 500) if len(title) <= 8: return make_response(jsonify('title too short'), 500) if len(content) <= 20: return make_response(jsonify('content too short'), 500) if category and category not in settings.FUNDING_CATEGORIES: return make_response(jsonify('unknown category'), 500) if status not in settings.FUNDING_STATUSES.keys(): make_response(jsonify('unknown status'), 500) if status != 1 and not current_user.admin: return make_response(jsonify('no rights to change status'), 500) try: from funding.bin.anti_xss import such_xss content_escaped = such_xss(content) html = markdown2.markdown(content_escaped, safe_mode=True) except Exception as ex: return make_response(jsonify('markdown error'), 500) if pid: p = Proposal.find_by_id(pid=pid) if not p: return make_response(jsonify('proposal not found'), 500) if p.user.id != current_user.id and not current_user.admin: return make_response(jsonify('no rights to edit this proposal'), 500) p.headline = title p.content = content p.html = html if addr_receiving: p.addr_receiving = addr_receiving if category: p.category = category # detect if an admin moved a proposal to a new status and auto-comment if p.status != status and current_user.admin: msg = "Moved to status \"%s\"." % settings.FUNDING_STATUSES[status].capitalize() try: Comment.add_comment(user_id=current_user.id, message=msg, pid=pid, automated=True) except: pass p.status = status p.last_edited = datetime.now() else: try: funds_target = float(funds_target) except Exception as ex: return make_response(jsonify('letters detected'),500) if funds_target < 1: return make_response(jsonify('Proposal asking less than 1 error :)'), 500) if len(addr_receiving) != 95: return make_response(jsonify('Faulty address, should be of length 95'), 500) p = Proposal(headline=title, content=content, category='misc', user=current_user) proposalID = current_user addr_donation = Proposal.generate_proposal_subaccount(proposalID) p.addr_donation = addr_donation p.html = html p.last_edited = datetime.now() p.funds_target = funds_target p.addr_receiving = addr_receiving p.category = category p.status = status db_session.add(p) db_session.commit() db_session.flush() # reset cached statistics from funding.bin.utils import Summary Summary.fetch_stats(purge=True) return make_response(jsonify({'url': url_for('proposal', pid=p.id)}))
def proposal_edit(pid): p = Proposal.find_by_id(pid=pid) if not p: return make_response(redirect(url_for('proposals'))) return make_response(render_template(('proposal/edit.html'), proposal=p))