mirror of
https://git.wownero.com/wownero/wownero-funding-system.git
synced 2024-08-15 00:53:45 +00:00
Removed titled proposal table and better peformance on comment queries
This commit is contained in:
parent
eb03b8a7cb
commit
c5ef1699ad
4 changed files with 45 additions and 32 deletions
|
@ -143,20 +143,26 @@ class Proposal(base):
|
|||
if not result.addr_donation:
|
||||
Proposal.generate_donation_addr(result)
|
||||
|
||||
comment_count = db_session.query(sa.func.count(Comment.id)).filter(Comment.proposal_id == result.id).scalar()
|
||||
setattr(result, 'comment_count', comment_count)
|
||||
return result
|
||||
|
||||
def get_comments(self):
|
||||
from wowfunding.factory import db_session
|
||||
q = db_session.query(Comment)
|
||||
q = q.filter(Comment.proposal_id == result.id)
|
||||
q = q.filter(Comment.proposal_id == self.id)
|
||||
q = q.filter(Comment.replied_to == None)
|
||||
comments = q.all()
|
||||
|
||||
for c in comments:
|
||||
q = db_session.query(Comment)
|
||||
q = q.filter(Comment.proposal_id == result.id)
|
||||
q = q.filter(Comment.proposal_id == self.id)
|
||||
q = q.filter(Comment.replied_to == c.id)
|
||||
_c = q.all()
|
||||
setattr(c, 'comments', _c)
|
||||
|
||||
setattr(result, '_comments', comments)
|
||||
return result
|
||||
setattr(self, '_comments', comments)
|
||||
return self
|
||||
|
||||
@property
|
||||
def balance(self):
|
||||
|
@ -226,6 +232,7 @@ class Proposal(base):
|
|||
|
||||
@classmethod
|
||||
def find_by_args(cls, status:int = None, cat: str = None, limit: int = 20, offset=0):
|
||||
from wowfunding.factory import db_session
|
||||
if status is None or not status >= 0 or not status <= 2:
|
||||
raise NotImplementedError('missing status')
|
||||
|
||||
|
@ -238,7 +245,12 @@ class Proposal(base):
|
|||
if isinstance(offset, int):
|
||||
q = q.offset(offset)
|
||||
|
||||
return q.all()
|
||||
results = q.all()
|
||||
for result in results:
|
||||
comment_count = db_session.query(sa.func.count(Comment.id)).filter(
|
||||
Comment.proposal_id == result.id).scalar()
|
||||
setattr(result, 'comment_count', comment_count)
|
||||
return results
|
||||
|
||||
@classmethod
|
||||
def search(cls, key: str):
|
||||
|
|
|
@ -66,6 +66,7 @@ def propsal_comment_reply(cid, pid):
|
|||
@app.route('/proposal/<int:pid>')
|
||||
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.html'), proposal=p))
|
||||
|
|
BIN
wowfunding/static/msg.png
Normal file
BIN
wowfunding/static/msg.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
|
@ -36,9 +36,7 @@
|
|||
<div class="row">
|
||||
<div class="col-lg-8">
|
||||
{% if proposals %}
|
||||
{% for p in proposals %}
|
||||
{% if loop.index == 1 %}
|
||||
<table class="table table-proposal table-hover table-tilted" style="margin-bottom:6px;">
|
||||
<table class="table table-proposal table-hover" style="margin-bottom:6px;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="font-size: x-large;">Proposal</th>
|
||||
|
@ -49,33 +47,35 @@
|
|||
{% else %}
|
||||
<th></th>
|
||||
{% endif %}
|
||||
<th style="display: table-cell;text-align: center;">
|
||||
<img width="24" src="/static/msg.png">
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% else %}
|
||||
{% if loop.index % 3 == 0 %}
|
||||
</tbody>
|
||||
</table>
|
||||
<table class="table table-proposal table-hover {% if (loop.index/3) % 2 == 0 %}table-tilted{% else %}table-tilted-v{% endif %}">
|
||||
<tbody>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
<tr>
|
||||
<td><b><a href="/proposal/{{ p.id }}">{{ p.headline }}</a></b></td>
|
||||
<td><a href="/user/{{ p.user.username }}">{{ p.user.username }}</a></td>
|
||||
<td id="date"><small>{{ p.date_added.strftime('%Y-%m-%d %H:%M') }}</small></td>
|
||||
<td>
|
||||
<span style="float:right;">
|
||||
{% if p.funds_progress >= 0.1 and status == 0 %}
|
||||
{{p.funds_progress|int}}%
|
||||
{% else %}
|
||||
-
|
||||
{% endif %}
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
{% endfor %}
|
||||
{% for p in proposals %}
|
||||
<tr>
|
||||
<td><b><a href="/proposal/{{ p.id }}">{{ p.headline }}</a></b></td>
|
||||
<td><a href="/user/{{ p.user.username }}">{{ p.user.username }}</a></td>
|
||||
<td id="date"><small>{{ p.date_added.strftime('%Y-%m-%d %H:%M') }}</small></td>
|
||||
<td>
|
||||
<span style="float:right;">
|
||||
{% if p.funds_progress >= 0.1 and status == 0 %}
|
||||
{{p.funds_progress|int}}%
|
||||
{% else %}
|
||||
-
|
||||
{% endif %}
|
||||
</span>
|
||||
</td>
|
||||
<td style="text-align:center;">
|
||||
{% if p.comment_count %}
|
||||
{{p.comment_count}}
|
||||
{% else %}
|
||||
-
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
|
|
Loading…
Reference in a new issue