when u visit someone's profile, see who chudded them

pull/165/head
Aevann 2023-07-02 20:40:39 +03:00
parent 1cd13cf4da
commit fb153e9a14
4 changed files with 59 additions and 22 deletions

View File

@ -587,12 +587,6 @@ class User(Base):
def fullname(self):
return f"u_{self.id}"
@property
@lazy
def banned_by(self):
if not self.is_suspended: return None
return g.db.get(User, self.is_banned)
@lazy
def has_badge(self, badge_id):
return g.db.query(Badge).filter_by(user_id=self.id, badge_id=badge_id).one_or_none()
@ -631,6 +625,28 @@ class User(Base):
return f"Unban in {text}"
@property
@lazy
def unchud_string(self):
if self.chud == 1:
return "permanently chudded"
wait = self.chud - int(time.time())
if wait < 60:
text = f"{wait}s"
else:
days = wait//(24*60*60)
wait -= days*24*60*60
hours = wait//(60*60)
wait -= hours*60*60
mins = wait//60
text = f"{days}d {hours:02d}h {mins:02d}m"
return f"Unchud in {text}"
@property
@lazy
@ -1235,6 +1251,19 @@ class User(Base):
def shadowbanner(self):
return g.db.query(User.username).filter_by(id=self.shadowbanned).one()[0]
@property
@lazy
def banned_by(self):
username = g.db.query(User.username).filter_by(id=self.is_banned).one()[0]
return f'<a href="/@{username}">@{username}</a>'
@property
@lazy
def chudder(self):
if not self.chudded_by: return 'award'
username = g.db.query(User.username).filter_by(id=self.chudded_by).one()[0]
return f'<a href="/@{username}">@{username}</a>'
@property
@lazy
def alts(self):

View File

@ -26,11 +26,7 @@
{%- endif %}
<td>{{user.truescore}}</td>
<td>{% if user.ban_reason %}{{user.ban_reason | safe}}{% else %}<span class="text-muted" style="font-style:italic;">No reason</span>{% endif %}</td>
{% with user=user.banned_by %}
<td data-sort-key="{{user.username.lower() if user else ''}}">
{% include "user_in_table.html" %}
</td>
{% endwith %}
<td>{{user.banned_by | safe}}</td>
<td {% if user.unban_utc %}data-time="{{user.unban_utc}}"{% endif %}></td>
</tr>
{% endfor %}

View File

@ -12,6 +12,7 @@
<th>Last Active</th>
{%- endif %}
<th>Truescore</th>
<th>Chudded by</th>
<th>Unchud in</th>
</tr>
</thead>
@ -23,6 +24,7 @@
<td {% if user.last_active %}data-time="{{user.last_active}}"{% endif %}></td>
{%- endif %}
<td>{{user.truescore}}</td>
<td>{{user.chudder | safe}}</td>
<td {% if user.chud != 1 %}data-time="{{user.chud}}"{% endif %}></td>
</tr>
{% endfor %}

View File

@ -1,21 +1,31 @@
{% macro userBanBlock(deviceType) %}
{% if u.chud %}
<h5 class="text-primary" id="profile-{{deviceType}}--chudded">CHUDDED USER:
(by {{u.chudder | safe}})
{% if u.chud > 1 %}
- {{u.unchud_string}}
{% endif %}
</h5>
{% endif %}
{% if u.is_suspended %}
<h5 class="text-primary" id="profile-{{deviceType}}--banned">BANNED USER
{% if u.ban_reason %}:
<h5 class="text-primary" id="profile-{{deviceType}}--banned">BANNED USER:
{{u.ban_reason | safe}}
{% endif %}
(by <a href="{{u.banned_by.url}}">@{{u.banned_by.username}}</a>)
{% if not u.ban_reason.startswith('1-Day ban award used by') %}
(by {{u.banned_by | safe}})
{% endif %}
{% if u.unban_utc %}
- {{u.unban_string}}
{% endif %}
</h5>
{% if u.unban_utc %}
<h5 class="text-primary" id="profile--unban">{{u.unban_string}}</h5>
{% endif %}
{% endif %}
{% if v and v.admin_level >= PERMS['USER_SHADOWBAN'] and u.shadowbanned %}
<h5 class="text-primary" id="profile-{{deviceType}}--shadowbanned">SHADOWBANNED USER
{% if u.ban_reason %}:
<h5 class="text-primary" id="profile-{{deviceType}}--shadowbanned">SHADOWBANNED USER:
{{u.ban_reason | safe}}
{% endif %}
(by <a href="/@{{u.shadowbanner}}">@{{u.shadowbanner}}</a>)
(by <a href="/@{{u.shadowbanner}}">@{{u.shadowbanner}}</a>)
</h5>
{% endif %}
{% endmacro %}