mirror of
https://git.wownero.com/wownero/wownero-funding-system.git
synced 2024-08-15 00:53:45 +00:00
Show 3 recent comments in sidebar
This commit is contained in:
parent
8e785b669e
commit
7905963e0f
5 changed files with 189 additions and 4 deletions
|
@ -3,18 +3,20 @@ from flask import session, g
|
|||
|
||||
import settings
|
||||
from wowfunding.factory import app, db_session, summary_data
|
||||
from wowfunding.orm.orm import Proposal, User
|
||||
from wowfunding.orm.orm import Proposal, User, Comment
|
||||
|
||||
|
||||
@app.context_processor
|
||||
def templating():
|
||||
global summary_data
|
||||
from flask.ext.login import current_user
|
||||
recent_comments = db_session.query(Comment).order_by(Comment.date_added.desc()).limit(3).all()
|
||||
return dict(logged_in=current_user.is_authenticated,
|
||||
current_user=current_user,
|
||||
funding_categories=settings.FUNDING_CATEGORIES,
|
||||
funding_statuses=settings.FUNDING_STATUSES,
|
||||
summary_data=summary_data[1])
|
||||
summary_data=summary_data[1],
|
||||
recent_comments=recent_comments)
|
||||
|
||||
|
||||
def fetch_summary(purge=False):
|
||||
|
|
163
wowfunding/bin/utils_time.py
Normal file
163
wowfunding/bin/utils_time.py
Normal file
|
@ -0,0 +1,163 @@
|
|||
from datetime import datetime, date
|
||||
from dateutil import parser
|
||||
import math
|
||||
import calendar
|
||||
|
||||
|
||||
class TimeMagic():
|
||||
def __init__(self):
|
||||
self.now = datetime.now()
|
||||
self.weekdays_en = {
|
||||
0: 'monday',
|
||||
1: 'tuesday',
|
||||
2: 'wednesday',
|
||||
3: 'thursday',
|
||||
4: 'friday',
|
||||
5: 'saturday',
|
||||
6: 'sunday'
|
||||
}
|
||||
self.months_en = {
|
||||
0: 'january',
|
||||
1: 'february',
|
||||
2: 'march',
|
||||
3: 'april',
|
||||
4: 'may',
|
||||
5: 'june',
|
||||
6: 'july',
|
||||
7: 'august',
|
||||
8: 'september',
|
||||
9: 'october',
|
||||
10: 'november',
|
||||
11: 'december'
|
||||
}
|
||||
|
||||
def get_weekday_from_datetime(self, dt):
|
||||
n = dt.today().weekday()
|
||||
return n
|
||||
|
||||
def week_number_get(self):
|
||||
now = datetime.now()
|
||||
return int(now.strftime("%V"))
|
||||
|
||||
def week_number_verify(self, week_nr):
|
||||
if week_nr > 0 or week_nr <= 53:
|
||||
return True
|
||||
|
||||
def get_weeknr_from_date(self, date):
|
||||
return date.strftime("%V")
|
||||
|
||||
def year_verify(self, year):
|
||||
if isinstance(year, str):
|
||||
try:
|
||||
year = int(year)
|
||||
except Exception as ex:
|
||||
return False
|
||||
|
||||
if 2000 <= year <= 2030:
|
||||
return True
|
||||
|
||||
def get_day_number(self):
|
||||
dt = datetime.now()
|
||||
return dt.today().weekday()
|
||||
|
||||
def get_month_nr(self):
|
||||
return datetime.now().strftime("%m")
|
||||
|
||||
def get_daynr_from_weekday(self, weekday):
|
||||
for k, v in self.weekdays_en.items():
|
||||
if v == weekday:
|
||||
return k
|
||||
|
||||
def get_day_from_daynr(self, nr):
|
||||
return self.weekdays_en[nr]
|
||||
|
||||
def get_month_from_weeknr(self, nr):
|
||||
nr = float(nr) / float(4)
|
||||
if nr.is_integer():
|
||||
nr -= 1
|
||||
else:
|
||||
nr = math.floor(nr)
|
||||
if nr < 0:
|
||||
nr = 0
|
||||
|
||||
return self.months_en[nr]
|
||||
|
||||
def get_month_nr_from_month(self, month):
|
||||
for k, v in self.months_en.items():
|
||||
if v == month:
|
||||
return k
|
||||
|
||||
def get_year(self):
|
||||
return date.today().year
|
||||
|
||||
def get_month(self):
|
||||
return date.today().month
|
||||
|
||||
def get_amount_of_days_from_month_nr(self, month_nr):
|
||||
try:
|
||||
max_days = calendar.monthrange(self.get_year(), int(month_nr))[1]
|
||||
return max_days
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
def from_till(self):
|
||||
m = self.get_month()
|
||||
d = self.get_amount_of_days_from_month_nr(m)
|
||||
y = self.get_year()
|
||||
|
||||
if len(str(d)) == 1:
|
||||
d = '0' + str(d)
|
||||
else:
|
||||
d = str(d)
|
||||
|
||||
if len(str(m)) == 1:
|
||||
m = '0' + str(m)
|
||||
else:
|
||||
m = str(m)
|
||||
|
||||
f = '%s/01/%s' % (m, y)
|
||||
t = '%s/%s/%s' % (m, d, y)
|
||||
|
||||
return {'date_from': f, 'date_till': t}
|
||||
|
||||
def ago_dt(self, datetime):
|
||||
return self.ago(datetime)
|
||||
|
||||
def ago_str(self, date_str):
|
||||
date = parser.parse(date_str)
|
||||
return self.ago(date)
|
||||
|
||||
def ago(self, datetime=None, epoch=None):
|
||||
import math
|
||||
|
||||
if epoch:
|
||||
td = int(epoch)
|
||||
else:
|
||||
if datetime:
|
||||
td = (self.now - datetime).total_seconds()
|
||||
else:
|
||||
return None
|
||||
|
||||
if td < 60:
|
||||
if td == 1:
|
||||
return '%s second ago'
|
||||
else:
|
||||
return 'Just now'
|
||||
elif 60 <= td < 3600:
|
||||
if 60 <= td < 120:
|
||||
return '1 minute ago'
|
||||
else:
|
||||
return '%s minutes ago' % str(int(math.floor(td / 60)))
|
||||
elif 3600 <= td < 86400:
|
||||
if 3600 <= td < 7200:
|
||||
return '1 hour ago'
|
||||
else:
|
||||
return '%s hours ago' % str(int(math.floor(td / 60 / 60)))
|
||||
elif td >= 86400:
|
||||
if td <= 86400 < 172800:
|
||||
return '1 day ago'
|
||||
else:
|
||||
x = int(math.floor(td / 24 / 60 / 60))
|
||||
if x == 1:
|
||||
return '1 day ago'
|
||||
return '%s days ago' % str(x)
|
|
@ -323,6 +323,11 @@ class Comment(base):
|
|||
ix_comment_replied_to = sa.Index("ix_comment_replied_to", replied_to)
|
||||
ix_comment_proposal_id = sa.Index("ix_comment_proposal_id", proposal_id)
|
||||
|
||||
@property
|
||||
def ago(self):
|
||||
from wowfunding.bin.utils_time import TimeMagic
|
||||
return TimeMagic().ago(self.date_added)
|
||||
|
||||
@staticmethod
|
||||
def find_by_id(cid: int):
|
||||
from wowfunding.factory import db_session
|
||||
|
|
|
@ -420,3 +420,8 @@ span.username a.author{
|
|||
.form-admin{
|
||||
border: 1px solid #b60000;
|
||||
}
|
||||
|
||||
ul.b {
|
||||
list-style-type: square;
|
||||
padding-left: 1.0rem;
|
||||
}
|
|
@ -54,9 +54,19 @@
|
|||
|
||||
<!-- Side Widget -->
|
||||
<div class="card my-4">
|
||||
<h5 class="card-header">Cool widget</h5>
|
||||
<h5 class="card-header">Recent comments</h5>
|
||||
<div class="card-body">
|
||||
Many widgets. Such sidebar. Wow.
|
||||
<ul class="b">
|
||||
{% for c in recent_comments %}
|
||||
<li>
|
||||
<a href="">{{c.user.username}}</a> in
|
||||
<a href="/proposal/{{c.proposal.id}}">#{{c.proposal.id}}</a>
|
||||
<small>
|
||||
<a href="/proposal/{{c.proposal.id}}#comment-{{c.id}}">({{c.ago}})</a>
|
||||
</small>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</li>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Reference in a new issue