Skip to content

Commit

Permalink
cleanup (#1501)
Browse files Browse the repository at this point in the history
  • Loading branch information
charmander authored Dec 19, 2024
2 parents e6e7dc4 + bd2b41f commit 5c454ce
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion weasyl/controllers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def signin_2fa_auth_post_(request):
two_factor_auth.force_deactivate(tfa_userid)
raise WeasylError('TwoFactorAuthenticationZeroRecoveryCodesRemaining',
links=[["2FA Dashboard", "/control/2fa/status"], ["Return to the Home Page", "/"]])
# Return to the target page, removing the scheme and domain per urlsplit.
# Return to the target page.
ref = request.POST["referer"] or "/"
response = HTTPSeeOther(location=define.path_redirect(ref))
response.set_cookie('WZL', request.weasyl_session.sessionid, max_age=60 * 60 * 24 * 365,
Expand Down
33 changes: 14 additions & 19 deletions weasyl/favorite.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from __future__ import annotations

from typing import Literal

from weasyl import collection
from weasyl import define as d
from weasyl import frienduser
Expand Down Expand Up @@ -272,26 +276,17 @@ def check(userid, submitid=None, charid=None, journalid=None):
)


def count(id, contenttype='submission'):
"""Fetches the count of favorites on some content.
Args:
id (int): ID of the content to get the count for.
contenttype (str): Type of content to fetch. It accepts one of the following:
submission, journal, or character
Returns:
An int with the number of favorites.
def count(id: int, content_type: Literal["journal", "character"]) -> int:
"""

if contenttype == 'submission':
querytype = 's'
elif contenttype == 'journal':
querytype = 'j'
elif contenttype == 'character':
querytype = 'f'
else:
raise ValueError("type should be one of 'submission', 'journal', or 'character'")
Fetches the count of favorites on some content.
"""
match content_type:
case "journal":
querytype = "j"
case "character":
querytype = "f"
case _: # pragma: no cover
raise ValueError("type must be 'journal' or 'character'")

return d.engine.scalar(
"SELECT COUNT(*) FROM favorite WHERE targetid = %s AND type = %s",
Expand Down
2 changes: 1 addition & 1 deletion weasyl/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ def select_view_api(userid, submitid, anyway=False, increment_views=False):
'rating': sub.rating.name,

'views': views,
'favorites': favorite.count(submitid),
'favorites': sub.favorites,
'comments': comment.count(submitid),
'favorited': favorite.check(userid, submitid=submitid),
'friends_only': sub.friends_only,
Expand Down
6 changes: 6 additions & 0 deletions weasyl/test/web/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ def test_submission_view(app, submission_user):
}],
}

favoriter = db_utils.create_user()
db_utils.create_favorite(favoriter, submitid=submission)

resp_json = app.get('/api/submissions/%i/view' % (submission,)).json
assert resp_json['favorites'] == 1


@pytest.mark.usefixtures('db')
def test_submission_view_missing(app):
Expand Down
2 changes: 1 addition & 1 deletion wzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ case "$head" in
assets)
$docker_compose create "$@" build-assets
$docker_compose cp ./assets build-assets:/weasyl-build/
container_id="$($docker_compose ps -a --format=json build-assets | grep -o '"ID":"[^"]*"' | cut -d '"' -f 4)"
container_id="$($docker_compose ps -a --format='{{.ID}}' build-assets)"
exec docker start -ai "$container_id"
;;

Expand Down

0 comments on commit 5c454ce

Please sign in to comment.