rename truecoins -> truescore (#544)

This commit is contained in:
justcool393 2023-07-28 02:56:49 -07:00 committed by GitHub
parent 64880c87fa
commit 46714fd520
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 53 additions and 27 deletions

View file

@ -1,6 +1,7 @@
from __future__ import annotations
import time
from datetime import datetime
from typing import TYPE_CHECKING, Union
import pyotp
@ -98,7 +99,7 @@ class User(CreatedBase):
login_nonce = Column(Integer, default=0, nullable=False)
reserved = deferred(Column(String))
coins = Column(Integer, default=0, nullable=False)
truecoins = Column(Integer, default=0, nullable=False)
truescore = Column(Integer, default=0, nullable=False)
procoins = Column(Integer, default=0, nullable=False)
mfa_secret = deferred(Column(String))
is_private = Column(Boolean, default=False, nullable=False)
@ -159,17 +160,23 @@ class User(CreatedBase):
def can_manage_reports(self):
return self.admin_level > 1
@property
def age_days(self):
return (datetime.now() - datetime.fromtimestamp(self.created_utc)).days
@property
def should_comments_be_filtered(self):
from files.__main__ import app # avoiding import loop
if self.admin_level > 0:
return False
# TODO: move settings out of app.config
site_settings = app.config['SETTINGS']
minComments = site_settings.get('FilterCommentsMinComments', 0)
minKarma = site_settings.get('FilterCommentsMinKarma', 0)
minAge = site_settings.get('FilterCommentsMinAgeDays', 0)
accountAgeDays = self.age_timedelta.days
return self.comment_count < minComments or accountAgeDays < minAge or self.truecoins < minKarma
min_comments = site_settings.get('FilterCommentsMinComments', 0)
min_karma = site_settings.get('FilterCommentsMinKarma', 0)
min_age = site_settings.get('FilterCommentsMinAgeDays', 0)
return self.comment_count < min_comments \
or self.age_days < min_age \
or self.truescore < min_karma
def can_change_user_privacy(self, v: "User") -> bool:
@ -186,7 +193,7 @@ class User(CreatedBase):
return (
self.comment_count >= min_comments
and self.truecoins >= min_truescore
and self.truescore >= min_truescore
and user_age_days >= min_age_days)
@ -214,7 +221,7 @@ class User(CreatedBase):
@property
@lazy
def paid_dues(self):
return not self.shadowbanned and not (self.is_banned and not self.unban_utc) and (self.admin_level or self.club_allowed or (self.club_allowed != False and self.truecoins > CLUB_TRUESCORE_MINIMUM))
return not self.shadowbanned and not (self.is_banned and not self.unban_utc) and (self.admin_level or self.club_allowed or (self.club_allowed != False and self.truescore > CLUB_TRUESCORE_MINIMUM))
@lazy
def any_block_exists(self, other):

View file

@ -631,7 +631,7 @@ def loggedin_list(v):
ids = [x for x, val in cache.get(f'{SITE}_loggedin').items() \
if (time.time() - val) < LOGGEDIN_ACTIVE_TIME]
users = g.db.query(User).filter(User.id.in_(ids)) \
.order_by(User.admin_level.desc(), User.truecoins.desc()).all()
.order_by(User.admin_level.desc(), User.truescore.desc()).all()
return render_template("admin/loggedin.html", v=v, users=users)

View file

@ -201,7 +201,7 @@ def api_comment(v):
abort(403, "Too much spam!")
is_filtered = v.should_comments_be_filtered()
is_filtered = v.should_comments_be_filtered
c = Comment(author_id=v.id,
parent_submission=parent_post.id,

View file

@ -199,9 +199,9 @@ def patrons(v):
@auth_desired
def admins(v):
if v and v.admin_level >= 3:
admins = g.db.query(User).filter(User.admin_level>1).order_by(User.truecoins.desc()).all()
admins += g.db.query(User).filter(User.admin_level==1).order_by(User.truecoins.desc()).all()
else: admins = g.db.query(User).filter(User.admin_level>0).order_by(User.truecoins.desc()).all()
admins = g.db.query(User).filter(User.admin_level>1).order_by(User.truescore.desc()).all()
admins += g.db.query(User).filter(User.admin_level==1).order_by(User.truescore.desc()).all()
else: admins = g.db.query(User).filter(User.admin_level>0).order_by(User.truescore.desc()).all()
return render_template("admins.html", v=v, admins=admins)

View file

@ -377,7 +377,7 @@ def leaderboard(v:User):
comments = SimpleLeaderboard(v, LeaderboardMeta("Comments", "comment count", "comments", "Comments", "comments"), g.db, users, User.comment_count)
received_awards = SimpleLeaderboard(v, LeaderboardMeta("Awards", "received awards", "awards", "Awards", None), g.db, users, User.received_award_count)
coins_spent = SimpleLeaderboard(v, LeaderboardMeta("Spent in shop", "coins spent in shop", "spent", "Coins", None), g.db, users, User.coins_spent)
truescore = SimpleLeaderboard(v, LeaderboardMeta("Truescore", "truescore", "truescore", "Truescore", None), g.db, users, User.truecoins)
truescore = SimpleLeaderboard(v, LeaderboardMeta("Truescore", "truescore", "truescore", "Truescore", None), g.db, users, User.truescore)
badges = BadgeMarseyLeaderboard(v, LeaderboardMeta("Badges", "badges", "badges", "Badges", None), g.db, Badge.user_id)
blocks = UserBlockLeaderboard(v, LeaderboardMeta("Blocked", "most blocked", "blocked", "Blocked By", "blockers"), g.db, UserBlock.target_id)

View file

@ -83,7 +83,7 @@ def api_vote_post(post_id, new, v):
# remove the old score data
if points_matter:
post.author.coins -= vote.vote_type
post.author.truecoins -= vote.vote_type
post.author.truescore -= vote.vote_type
# we'll be saving later anyway, so don't bother doing so here
else:
# create new vote data
@ -105,7 +105,7 @@ def api_vote_post(post_id, new, v):
# add relevant points
if points_matter:
post.author.coins += vote.vote_type
post.author.truecoins += vote.vote_type
post.author.truescore += vote.vote_type
# database it up
g.db.add(post.author)
@ -151,7 +151,7 @@ def api_vote_comment(comment_id, new, v):
# remove the old score data
if points_matter:
comment.author.coins -= vote.vote_type
comment.author.truecoins -= vote.vote_type
comment.author.truescore -= vote.vote_type
# we'll be saving later anyway, so don't bother doing so here
else:
# create new vote data
@ -173,7 +173,7 @@ def api_vote_comment(comment_id, new, v):
# add relevant points
if points_matter:
comment.author.coins += vote.vote_type
comment.author.truecoins += vote.vote_type
comment.author.truescore += vote.vote_type
# database it up
g.db.add(comment.author)

View file

@ -13,7 +13,7 @@
<tr>
<td>{{loop.index}}</td>
<td><a style="color:#{{user.name_color}}" href="/@{{user.username}}"><img loading="lazy" src="{{user.profile_url}}" class="pp20"><span {% if user.patron %}class="patron" style="background-color:#{{user.name_color}}"{% endif %}>{{user.username}}</span></a></td>
<td>{{user.truecoins}}</td>
<td>{{user.truescore}}</td>
</tr>
{% endfor %}
</table>

View file

@ -15,7 +15,7 @@
<p><a href="{{thing.permalink}}">{{thing.permalink}}</a></p>
<p><b>Author:</b> <a href="{{thing.author.url}}">@{{thing.author.username}}</a></p>
<p><b>Author Created At:</b> {{thing.author.created_datetime}}</p>
<p><b>Author Truescore:</b> {{thing.author.truecoins}}</p>
<p><b>Author Truescore:</b> {{thing.author.truescore}}</p>
<p><b>Upvotes: </b>{{ups | length}}</p>
<p><b>Downvotes: </b>{{downs | length}}</p>
@ -29,7 +29,7 @@
{% for vote in ups %}
<tr>
<td><a style="color:#{{vote.user.namecolor}};font-weight:bold" href="/@{{vote.user.username}}"><img loading="lazy" src="{{vote.user.profile_url}}" class="pp20"><span {% if vote.user.patron %}class="patron" style="background-color:#{{vote.user.namecolor}}"{% endif %}>{{vote.user.username}}</span></a></td>
<td>{{vote.user.truecoins}}</td>
<td>{{vote.user.truescore}}</td>
</tr>
{% endfor %}
</table>
@ -44,14 +44,9 @@
{% for vote in downs %}
<tr>
<td><a style="color:#{{vote.user.namecolor}};font-weight:bold" href="/@{{vote.user.username}}"><img loading="lazy" src="{{vote.user.profile_url}}" class="pp20"><span {% if vote.user.patron %}class="patron" style="background-color:#{{vote.user.namecolor}}"{% endif %}>{{vote.user.username}}</span></a></td>
<td>{{vote.user.truecoins}}</td>
<td>{{vote.user.truescore}}</td>
</tr>
{% endfor %}
</table>
{% endif %}
{% endblock %}

View file

@ -0,0 +1,24 @@
"""rename truecoins to truescore
Revision ID: 55488ee27b00
Revises: 5195118d6a51
Create Date: 2023-07-28 03:45:12.251007+00:00
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '55488ee27b00'
down_revision = '5195118d6a51'
branch_labels = None
depends_on = None
def upgrade():
op.alter_column('users', 'truecoins', new_column_name='truescore')
def downgrade():
op.alter_column('users', 'truescore', new_column_name='truecoins')