remotes/1693045480750635534/spooky-22
Aevann1 2021-11-26 21:56:20 +02:00
parent 1e699491f6
commit b1dee92e9d
7 changed files with 62 additions and 5 deletions

View File

@ -2,6 +2,7 @@ from sqlalchemy import *
from sqlalchemy.orm import relationship
from files.__main__ import Base
from files.helpers.lazy import lazy
from files.helpers.const import censor_slurs
import time
class Flag(Base):
@ -29,6 +30,10 @@ class Flag(Base):
def created_datetime(self):
return str(time.strftime("%d/%B/%Y %H:%M:%S UTC", time.gmtime(self.created_utc)))
@lazy
def realreason(self, v):
return censor_slurs(self.reason, v)
class CommentFlag(Base):
@ -53,4 +58,8 @@ class CommentFlag(Base):
@property
@lazy
def created_datetime(self):
return str(time.strftime("%d/%B/%Y %H:%M:%S UTC", time.gmtime(self.created_utc)))
return str(time.strftime("%d/%B/%Y %H:%M:%S UTC", time.gmtime(self.created_utc)))
@lazy
def realreason(self, v):
return censor_slurs(self.reason, v)

View File

@ -180,7 +180,7 @@ PUSHER_INSTANCE_ID = '02ddcc80-b8db-42be-9022-44c546b4dce6'
PUSHER_KEY = environ.get("PUSHER_KEY", "").strip()
single_words = "|".join([slur.lower() for slur in SLURS.keys()])
SLUR_REGEX = re.compile(rf"(?i)((?<=\s|>)|^)(nigger)((?=[\s<,.]|s[\s<,.])|$)")
SLUR_REGEX = re.compile(rf"(?i)((?<=\s|>)|^)({single_words})((?=[\s<,.]|s[\s<,.])|$)")
def sub_matcher(match: re.Match) -> str:
return SLURS[match.group(0).lower()]

View File

@ -17,6 +17,26 @@ site = environ.get("DOMAIN").strip()
beams_client = PushNotifications(instance_id=PUSHER_INSTANCE_ID, secret_key=PUSHER_KEY)
@app.get("/most_downvoted")
@auth_desired
def most_downvoted(v):
votes = g.db.query(Submission.author_id, func.count(Submission.author_id)).join(Vote, Vote.submission_id==Submission.id).filter(Vote.vote_type==-1).group_by(Submission.author_id).order_by(func.count(Submission.author_id).desc()).limit(25).all()
votes2 = g.db.query(Comment.author_id, func.count(Comment.author_id)).join(CommentVote, CommentVote.comment_id==Comment.id).filter(CommentVote.vote_type==-1).group_by(Comment.author_id).order_by(func.count(Comment.author_id).desc()).limit(25).all()
votes = Counter(dict(votes)) + Counter(dict(votes2))
users = g.db.query(User).filter(User.id.in_(votes.keys())).all()
users2 = []
for user in users: users2.append((user, votes[user.id]))
users = sorted(users2, key=lambda x: x[1], reverse=True)[:25]
return render_template("most_downvoted.html", v=v, users=users)
@app.get("/@<username>/upvoters")
@auth_desired
def upvoters(v, username):

View File

@ -319,7 +319,7 @@
<pre></pre>
<ul style="padding-left:20px; margin-bottom: 0;">
{% for f in c.ordered_flags %}
<li><a style="font-weight:bold" href="{{f.user.url}}">{{f.user.username}}</a>{% if f.reason %}: {{f.reason | safe}}{% endif %} {% if v and v.admin_level > 1 %}<a href="javascript:void(0)" onclick="post_toast('/del_report/c{{ f.id }}')">[remove]</a>{% endif %}</li>
<li><a style="font-weight:bold" href="{{f.user.url}}">{{f.user.username}}</a>{% if f.reason %}: {{f.realreason(v) | safe}}{% endif %} {% if v and v.admin_level > 1 %}<a href="javascript:void(0)" onclick="post_toast('/del_report/c{{ f.id }}')">[remove]</a>{% endif %}</li>
{% endfor %}
</ul>
</div>

View File

@ -0,0 +1,28 @@
{% extends "default.html" %}
{% block content %}
<pre>
</pre>
<h5 style="text-align: center">Most downvoted users</h5>
<pre></pre>
<table class="table table-striped mb-5">
<thead class="bg-primary text-white">
<tr>
<th style="font-weight: bold">#</th>
<th style="font-weight: bold">Name</th>
<th style="font-weight: bold">Downvotes</th>
</tr>
</thead>
<tbody id="followers-table">
{% for user in users %}
<tr>
<td style="font-weight: bold">{{loop.index}}</td>
<td><a style="color:#{{user[0].namecolor}}; font-weight:bold;" href="/@{{user[0].username}}"><img loading="lazy" src="/uid/{{user[0].id}}/pic" class="pp20"><span {% if user[0].patron %}class="patron" style="background-color:#{{user[0].namecolor}};"{% endif %}>{{user[0].username}}</span></a></td>
<td style="font-weight: bold">{{user[1]}}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}

View File

@ -459,7 +459,7 @@
<pre></pre>
<ul style="padding-left:20px; margin-bottom: 0;">
{% for f in p.ordered_flags %}
<li><a style="font-weight:bold" href="{{f.user.url}}">{{f.user.username}}</a>{% if f.reason %}: {{f.reason | safe}}{% endif %} {% if v and v.admin_level > 1 %}<a href="javascript:void(0)" onclick="post_toast('/del_report/p{{ f.id }}')">[remove]</a>{% endif %}</li>
<li><a style="font-weight:bold" href="{{f.user.url}}">{{f.user.username}}</a>{% if f.reason %}: {{f.realreason(v) | safe}}{% endif %} {% if v and v.admin_level > 1 %}<a href="javascript:void(0)" onclick="post_toast('/del_report/p{{ f.id }}')">[remove]</a>{% endif %}</li>
{% endfor %}
</ul>
</div>

View File

@ -125,7 +125,7 @@
<pre></pre>
<ul style="padding-left:20px; margin-bottom: 0;">
{% for f in p.ordered_flags %}
<li><a style="font-weight:bold" href="{{f.user.url}}">{{f.user.username}}</a>{% if f.reason %}: {{f.reason | safe}}{% endif %} {% if v and v.admin_level > 1 %}<a href="javascript:void(0)" onclick="post_toast('/del_report/p{{ f.id }}')">[remove]</a>{% endif %}</li>
<li><a style="font-weight:bold" href="{{f.user.url}}">{{f.user.username}}</a>{% if f.reason %}: {{f.realreason(v) | safe}}{% endif %} {% if v and v.admin_level > 1 %}<a href="javascript:void(0)" onclick="post_toast('/del_report/p{{ f.id }}')">[remove]</a>{% endif %}</li>
{% endfor %}
</ul>
</div>