Merge pull request #11 from skftn/refactor

Refactor some code
devfund_page
xmrdsc 6 years ago committed by GitHub
commit 8cfa556c04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -102,7 +102,8 @@ class Daemon:
}
data = self._make_request(data)
data = data['result'].get('in', [])
data = data['result']
data = data.get('in', []) + data.get('pool', [])
# filter by current proposal
txs = [tx for tx in data if tx.get('address') == address['address']]
@ -130,13 +131,14 @@ class Daemon:
data = {
"method": "get_transfers",
"params": {"pool": True, "out": True, "account_index": index},
"params": {"pool": False, "out": True, "account_index": index},
"jsonrpc": "2.0",
"id": "0",
}
data = self._make_request(data)
data = data['result'].get('out', [])
data = data['result']
data = data.get('out', []) + data.get('pool', [])
# filter by current proposal
txs = [tx for tx in data if tx.get('address') == address['address']]
@ -150,10 +152,10 @@ class Daemon:
}
def _make_request(self, data):
if self.username:
if self.password:
r = requests.post(self.url, auth=HTTPDigestAuth(settings.RPC_USERNAME, settings.RPC_PASSWORD), json=data, headers=self.headers)
else:
r = requests.post(self.url, json=data, headers=self.headers)
options = {'json': data, 'headers': self.headers}
if self.username and self.password:
options['auth'] = HTTPDigestAuth(settings.RPC_USERNAME, settings.RPC_PASSWORD)
r = requests.post(self.url, **options)
r.raise_for_status()
return r.json()
return r.json()

@ -30,7 +30,7 @@ class Summary:
'coin-btc': coin_btc_value(),
'btc-usd': price_cmc_btc_usd()
}
cache.set(cache_key, data=data, expiry=7200)
cache.set(cache_key, data=data, expiry=1200)
g.coin_prices = data
return data

@ -57,5 +57,5 @@ class WowCache:
except:
return {}
def set(self, key: str, data: dict, expiry = 300):
def set(self, key: str, data: dict, expiry=300):
self._cache.set(key, json.dumps(data, default=json_encoder), ex=expiry)

@ -196,7 +196,7 @@ class Proposal(base):
if not isinstance(data, dict):
print('error; get_transfers_in; %d' % self.id)
return rtn
cache.set(cache_key, data=data, expiry=300)
cache.set(cache_key, data=data, expiry=60)
except Exception as ex:
print('error; get_transfers_in; %d' % self.id)
return rtn
@ -241,12 +241,14 @@ class Proposal(base):
if not isinstance(data, dict):
print('error; get_transfers_out; %d' % self.id)
return rtn
cache.set(cache_key, data=data, expiry=300)
cache.set(cache_key, data=data, expiry=60)
except:
print('error; get_transfers_out; %d' % self.id)
return rtn
data['remaining_pct'] = 0.0
prices = Summary.fetch_prices()
for tx in data['txs']:
if prices:
tx['amount_usd'] = coin_to_usd(amt=tx['amount_human'], btc_per_coin=prices['coin-btc'], usd_per_btc=prices['btc-usd'])
@ -259,10 +261,10 @@ class Proposal(base):
data['pct'] = 0.0
data['spent'] = 0.0
if data['spent']:
data['remaining_pct'] = 100 / float(data['sum'] / data['spent'])
else:
data['remaining_pct'] = 0.0
cache_key_in = 'coin_balance_pid_%d' % self.id
data_in = cache.get(cache_key_in)
if data_in and data['spent']:
data['remaining_pct'] = 100 / float(data_in['sum'] / data['spent'])
return data

@ -135,12 +135,12 @@ body {
}
.table-hover tbody tr:hover {
background-color: rgba(0,0,0,.075);
background-color: rgba(0,0,0,.055);
}
.table th, .table td {
border-top: 1px solid #008926;
padding-top: .3rem;
border-top: 1px solid #00000029;
padding-top: .65rem;
}
.table-tilted{
@ -169,7 +169,7 @@ body {
}
.table thead th {
border-bottom: 1px solid #008926 !important;
border-bottom: 1px solid #00000029 !important;
border-top: none;
font-size: 14px;
}
@ -612,4 +612,8 @@ ul.b {
.proposal_qr{
margin-top:8px;
margin-bottom:8px;
}
.table-proposal tr {
background: #00000005;
}

@ -1,3 +1,5 @@
{% from 'proposal/macros/comment.html' import comment_entry %}
<div class="row">
<div class="col-md-12">
<div class="card my-6" id="incoming_txs">
@ -18,69 +20,14 @@
<input type="submit" value="add comment">
</form>
{% else %}
You need to be logged in to comment.
You need to be <a href="{{ url_for('login') }}">logged in</a> to comment.
<br>
{% endif %}
<br>
{% for c in proposal._comments %}
<!-- Single Comment -->
<div class="media mb-4 comment-container" id="comment-{{c.id}}">
<div class="votearrow" title="upvote"></div>
<div class="media-body">
<span class="username">
<a href="/user/{{ c.user.username }}">
{{c.user.username}}
{% if c.user.username == proposal.user.username %}
<small>[op]</small>
{% endif %}
{% if c.user.admin %}
<small>[admin]</small>
{% endif %}
</a>
</span>
<span class="date_posted">
<a href="/proposal/{{proposal.id}}#comment-{{c.id}}">
{{c.date_added.strftime('%Y-%m-%d %H:%M')}}
</a>
</span><br>
<span data-id="{{c.id}}" class="body" style="{% if c.automated %}color:blue;{% endif %};word-break: break-all;">{{c.message}}</span>
<br>
{% if not c.automated %}
<a class="reply" href="{{url_for('propsal_comment_reply', cid=c.id, pid=proposal.id)}}">reply</a>
{% endif %}
{% for _c in c.comments %}
<div class="media mt-4 comment-container" id="comment-{{_c.id}}">
<div class="votearrow" title="upvote"></div>
<div class="media-body" id="comment">
<span class="username">
<a href="/user/{{ _c.user.username }}">
{{_c.user.username}}
{% if _c.user.username == proposal.user.username %}
<small>[op]</small>
{% endif %}
{% if _c.user.admin %}
<small>[admin]</small>
{% endif %}
</a>
</span>
<span class="date_posted">
<a href="/proposal/{{proposal.id}}#comment-{{_c.id}}">
{{_c.date_added.strftime('%Y-%m-%d %H:%M')}}
</a>
</span>
<br>
<span data-id="{{_c.id}}" class="body" style="word-break: break-all;">
{{_c.message}}
</span>
</div>
</div>
{% endfor %}
</div>
</div>
{% for c in proposal._comments if not c.automated %}
{{ comment_entry(c, proposal) }}
{% endfor %}
</div>
</div>

@ -2,7 +2,7 @@
<table class="table table-proposal table-hover" data-status="{{ status }}" style="margin-bottom:6px;">
<thead>
<tr>
<th style="font-size: 20px;">{{title}}</th>
<th style="font-size: 18px;">{{title}}</th>
<th>Username</th>
<th id="date">Date</th>
{% if _proposals and _proposals[0].status >= 2 %}

@ -51,7 +51,6 @@
{% endif %}
</p>
<hr>
{% if proposal.status in [2,3] %}
<div class="row">
<div class="col-md-12">
@ -96,11 +95,14 @@
</div>
<div class="col-lg-8">
{{proposal.balance['available']|round(3) or 0 }} WOW Raised
{% if (proposal.funds_target-proposal.balance['available']|float|round(3)) > 0 %}
({{ (proposal.funds_target-proposal.balance['available']|float|round(3)|int) }} WOW until goal)
{% else %}
{% set remaining = proposal.funds_target - proposal.balance['available']|float|round(3) %}
{% if remaining > 0 %}
({{ (proposal.funds_target - proposal.balance['available']|float|round(3)|int) }} WOW until goal)
{% elif remaining < 0 %}
({{ (proposal.balance['available']-proposal.funds_target|float|round(3)|int) }} WOW past goal!)
{% endif %}
<div class="progress">
<div class="progress-bar progress-warning progress-bar" style="width: {{proposal.balance['pct']}}%;">
</div>
@ -113,7 +115,7 @@
<div class="col-lg-8">
{{proposal.spends['spent']|round(3) or 0}} WOW Paid out
<div class="progress">
<div class="progress-bar progress-warning progress-bar" style="width: {{proposal.spends['spent_remaining_pct']}}%;">
<div class="progress-bar progress-warning progress-bar" style="width: {{proposal.spends['remaining_pct']}}%;">
</div>
</div>
<hr>
@ -124,12 +126,11 @@
<div class="progress-bar progress-warning progress-bar" style="width: {{proposal.balance['remaining_pct']}}%;">
</div>
</div>
<hr>
</div>
<br/>
</div>
<div class="row" style="margin-top:16px;">
<div class="row" style="margin-top:32px;">
<div class="col-lg-12">
Donation address:
<pre class="proposal_address">{% if proposal.addr_donation %}{{ proposal.addr_donation }}{% else %}<small>None generated yet</small>{% endif %}</pre>
@ -203,36 +204,51 @@
{% endif %}
{% if proposal.spends['txs'] %}
{% if proposal.spends['txs'] %}
<div class="row">
<div class="col-md-12">
<div class="card my-6" id="incoming_txs">
<h5 class="card-header">Outgoing transactions <small>({{proposal.spends['txs']|length}})</small></h5>
<div class="card-body">
<ul class="list-group">
{% for tx in proposal.spends['txs'] %}
<li class="list-group-item">
{{tx['datetime'].strftime('%Y-%m-%d %H:%M')}}
<span style="float:right"><b>Blockheight</b>: {{tx['height']}}</span>
<br>
<a target="_blank" href="https://explore.wownero.com/tx/{{tx['txid']}}">{{tx['txid'][:32]}}...</a>
<span style="float:right;color:#890000;font-weight:bold;">
- {{tx['amount_human']|round(3)}} WOW
{% if 'amount_usd' in tx %}
<small style="color: black">
➞ $ {{tx['amount_usd']}}
</small>
{% endif %}
</span>
</li>
{% endfor %}
</ul>
</div>
</div>
</div>
</div>
<!-- /.row -->
{% endif %}
{% from 'proposal/macros/comment.html' import comment_entry %}
<div class="row">
<div class="col-md-12">
<div class="card my-6" id="incoming_txs">
<h5 class="card-header">Outgoing transactions <small>({{proposal.spends['txs']|length}})</small></h5>
<div class="card-body">
<ul class="list-group">
{% for tx in proposal.spends['txs'] %}
<li class="list-group-item">
{{tx['datetime'].strftime('%Y-%m-%d %H:%M')}}
<span style="float:right"><b>Blockheight</b>: {{tx['height']}}</span>
<br>
<a target="_blank" href="https://explore.wownero.com/tx/{{tx['txid']}}">{{tx['txid'][:32]}}...</a>
<span style="float:right;color:#890000;font-weight:bold;">
- {{tx['amount_human']|round(3)}} WOW
{% if 'amount_usd' in tx %}
<small style="color: black">
➞ $ {{tx['amount_usd']}}
</small>
{% endif %}
</span>
</li>
{% endfor %}
</ul>
<h5 id="comments" class="card-header">Events</h5>
<div class="card-body comments-panel">
{% for c in proposal._comments if c.automated %}
{{ comment_entry(c, proposal) }}
{% endfor %}
</div>
</div>
</div>
</div>
<!-- /.row -->
{% endif %}
</div>
<script>

Loading…
Cancel
Save