mirror of
https://git.wownero.com/wownero/wownero-funding-system.git
synced 2024-08-15 00:53:45 +00:00
Implement feature proposal categories
This commit is contained in:
parent
b8026511fa
commit
29e5a9eb95
4 changed files with 33 additions and 14 deletions
|
@ -7,14 +7,18 @@ from wowfunding.orm.orm import Proposal, User
|
|||
|
||||
|
||||
@app.context_processor
|
||||
def template_vars():
|
||||
def templating():
|
||||
global summary_data
|
||||
return dict(summary_data=summary_data[1])
|
||||
from flask.ext.login import current_user
|
||||
return dict(logged_in=current_user.is_authenticated,
|
||||
current_user=current_user,
|
||||
funding_categories=settings.FUNDING_CATEGORIES,
|
||||
summary_data=summary_data[1])
|
||||
|
||||
|
||||
def fetch_summary():
|
||||
def fetch_summary(purge=False):
|
||||
global summary_data
|
||||
if summary_data:
|
||||
if summary_data and not purge:
|
||||
if (datetime.now() - summary_data[0]).total_seconds() <= 120:
|
||||
return
|
||||
|
||||
|
|
|
@ -48,13 +48,6 @@ def create_app():
|
|||
app.session_interface = JsonRedis(key_prefix=app.config['SESSION_PREFIX'], use_signer=False)
|
||||
cache = WowCache()
|
||||
|
||||
# template vars
|
||||
@app.context_processor
|
||||
def _bootstrap_templating():
|
||||
from flask.ext.login import current_user
|
||||
return dict(logged_in=current_user.is_authenticated,
|
||||
current_user=current_user)
|
||||
|
||||
# import routes
|
||||
from wowfunding import routes
|
||||
from wowfunding import api
|
||||
|
|
|
@ -78,9 +78,10 @@ def proposal(pid):
|
|||
parameter('content', type=str, required=True, location='json'),
|
||||
parameter('pid', type=int, required=False, location='json'),
|
||||
parameter('funds_target', type=float, required=True, location='json'),
|
||||
parameter('addr_receiving', type=str, required=True, location='json')
|
||||
parameter('addr_receiving', type=str, required=True, location='json'),
|
||||
parameter('category', type=str, required=True, location='json')
|
||||
)
|
||||
def proposal_api_add(title, content, pid, funds_target, addr_receiving):
|
||||
def proposal_api_add(title, content, pid, funds_target, addr_receiving, category):
|
||||
import markdown2
|
||||
|
||||
if current_user.is_anonymous:
|
||||
|
@ -91,6 +92,9 @@ def proposal_api_add(title, content, pid, funds_target, addr_receiving):
|
|||
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)
|
||||
|
||||
try:
|
||||
from wowfunding.bin.anti_xss import such_xss
|
||||
content_escaped = such_xss(content)
|
||||
|
@ -111,6 +115,8 @@ def proposal_api_add(title, content, pid, funds_target, addr_receiving):
|
|||
p.html = html
|
||||
if addr_receiving:
|
||||
p.addr_receiving = addr_receiving
|
||||
if category:
|
||||
p.category = category
|
||||
p.last_edited = datetime.now()
|
||||
else:
|
||||
if funds_target <= 1:
|
||||
|
@ -123,10 +129,16 @@ def proposal_api_add(title, content, pid, funds_target, addr_receiving):
|
|||
p.last_edited = datetime.now()
|
||||
p.funds_target = funds_target
|
||||
p.addr_receiving = addr_receiving
|
||||
p.category = category
|
||||
db_session.add(p)
|
||||
|
||||
db_session.commit()
|
||||
db_session.flush()
|
||||
|
||||
# reset cached statistics
|
||||
from wowfunding.bin import utils_request
|
||||
utils_request.fetch_summary(purge=True)
|
||||
|
||||
return make_response(jsonify({'url': url_for('proposal', pid=p.id)}))
|
||||
|
||||
|
||||
|
|
|
@ -65,6 +65,15 @@
|
|||
<input {% if addr_receiving %}disabled{% endif %} id="addr_receiving" type="text" name="addr_receiving" class="form-control" placeholder="WOW..." value="{{ addr_receiving }}">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="category">Category</label>
|
||||
<select class="form-control" id="category" name="category">
|
||||
{% for cat in funding_categories %}
|
||||
<option value="{{cat}}"{% if cat == proposal.category %} selected{% endif %}>{{cat}}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Content</label>
|
||||
<textarea id="content" class="textarea" name="content" placeholder="Place some text here" style="width: 100%; height: 600px; font-size: 14px; line-height: 18px; border: 1px solid #dddddd; padding: 10px;">{{ content }}</textarea>
|
||||
|
@ -118,7 +127,8 @@
|
|||
'title': document.getElementById('title').value,
|
||||
'content': simplemde.value(),
|
||||
'funds_target': parseFloat(document.getElementById('funds_target').value),
|
||||
'addr_receiving': document.getElementById('addr_receiving').value
|
||||
'addr_receiving': document.getElementById('addr_receiving').value,
|
||||
'category': document.getElementById('category').value
|
||||
};
|
||||
|
||||
if (pid) {
|
||||
|
|
Loading…
Reference in a new issue