From b30eb0947ee3912167121b1754be6a69b86532b6 Mon Sep 17 00:00:00 2001 From: Hunter Turcin Date: Mon, 30 Dec 2024 22:23:36 -0600 Subject: [PATCH] Add titles to titleless pages --- weasyl/controllers/interaction.py | 2 +- weasyl/controllers/marketplace.py | 3 ++- weasyl/controllers/messages.py | 4 ++-- weasyl/controllers/profile.py | 37 +++++++++++++++++-------------- 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/weasyl/controllers/interaction.py b/weasyl/controllers/interaction.py index 13ab41c6c..08122845a 100644 --- a/weasyl/controllers/interaction.py +++ b/weasyl/controllers/interaction.py @@ -123,7 +123,7 @@ def note_(request): # Private message data, profile.select_myself(request.userid), - ])) + ], title=data['title'])) @login_required diff --git a/weasyl/controllers/marketplace.py b/weasyl/controllers/marketplace.py index 8f0dfa9ba..573a2fbf8 100644 --- a/weasyl/controllers/marketplace.py +++ b/weasyl/controllers/marketplace.py @@ -25,4 +25,5 @@ def search_(request): next_index = offset + limit if rcount - limit > 0 else None return Response(define.webpage(request.userid, "etc/marketplace.html", [results, form, commishinfo.CURRENCY_CHARMAP, commishinfo.PRESET_COMMISSION_CLASSES, - prev_index, next_index])) + prev_index, next_index], + title='Marketplace')) diff --git a/weasyl/controllers/messages.py b/weasyl/controllers/messages.py index 3986d7bad..60122487e 100644 --- a/weasyl/controllers/messages.py +++ b/weasyl/controllers/messages.py @@ -57,7 +57,7 @@ def messages_notifications_(request): define._page_header_info.refresh(request.userid) return Response(define.webpage(request.userid, "message/notifications.html", [ sort_notifications(notifications), - ])) + ], title='Notifications')) @login_required @@ -70,4 +70,4 @@ def messages_submissions_(request): # Submissions message.select_submissions(request.userid, 66, include_tags=False, backtime=define.get_int(backtime), nexttime=define.get_int(nexttime)), - ))) + ), title='Submission Notifications')) diff --git a/weasyl/controllers/profile.py b/weasyl/controllers/profile.py index b6a1c967a..97215efdc 100644 --- a/weasyl/controllers/profile.py +++ b/weasyl/controllers/profile.py @@ -12,6 +12,13 @@ from weasyl.error import WeasylError +def _get_page_title(userprofile: dict, what: str) -> str: + has_fullname = userprofile['full_name'] is not None and userprofile['full_name'].strip() != '' + name = userprofile['full_name'] if has_fullname else userprofile['username'] + + return f"{name}'s {what}" + + def _get_post_counts_by_type(userid, *, friends: bool, rating): result = { "submission": 0, @@ -176,8 +183,7 @@ def submissions_(request): raise WeasylError('noGuests') userprofile = profile.select_profile(otherid, viewer=request.userid) - has_fullname = userprofile['full_name'] is not None and userprofile['full_name'].strip() != '' - page_title = "%s's submissions" % (userprofile['full_name'] if has_fullname else userprofile['username'],) + page_title = _get_page_title(userprofile, 'submissions') page = define.common_page_start(request.userid, title=page_title) url_format = "/submissions/{username}?%s{folderquery}".format( @@ -226,8 +232,7 @@ def collections_(request): raise WeasylError('noGuests') userprofile = profile.select_profile(otherid, viewer=request.userid) - has_fullname = userprofile['full_name'] is not None and userprofile['full_name'].strip() != '' - page_title = "%s's collections" % (userprofile['full_name'] if has_fullname else userprofile['username'],) + page_title = _get_page_title(userprofile, 'collections') page = define.common_page_start(request.userid, title=page_title) url_format = "/collections?userid={userid}&%s".format(userid=userprofile['userid']) @@ -265,8 +270,7 @@ def journals_(request): raise WeasylError('noGuests') userprofile = profile.select_profile(otherid, viewer=request.userid) - has_fullname = userprofile['full_name'] is not None and userprofile['full_name'].strip() != '' - page_title = "%s's journals" % (userprofile['full_name'] if has_fullname else userprofile['username'],) + page_title = _get_page_title(userprofile, 'journals') page = define.common_page_start(request.userid, title=page_title) relation = profile.select_relation(request.userid, otherid) @@ -302,8 +306,7 @@ def characters_(request): raise WeasylError('noGuests') userprofile = profile.select_profile(otherid, viewer=request.userid) - has_fullname = userprofile['full_name'] is not None and userprofile['full_name'].strip() != '' - page_title = "%s's characters" % (userprofile['full_name'] if has_fullname else userprofile['username'],) + page_title = _get_page_title(userprofile, 'characters') page = define.common_page_start(request.userid, title=page_title) url_format = "/characters?userid={userid}&%s".format(userid=userprofile['userid']) @@ -356,8 +359,7 @@ def shouts_(request): status=403, ) - has_fullname = userprofile['full_name'] is not None and userprofile['full_name'].strip() != '' - page_title = "%s's shouts" % (userprofile['full_name'] if has_fullname else userprofile['username'],) + page_title = _get_page_title(userprofile, 'shouts') page = define.common_page_start(request.userid, title=page_title) relation = profile.select_relation(request.userid, otherid) @@ -390,8 +392,7 @@ def staffnotes_(request): raise WeasylError("userRecordMissing") userprofile = profile.select_profile(otherid, viewer=request.userid) - has_fullname = userprofile['full_name'] is not None and userprofile['full_name'].strip() != '' - page_title = "%s's staff notes" % (userprofile['full_name'] if has_fullname else userprofile['username'],) + page_title = _get_page_title(userprofile, 'staff notes') page = define.common_page_start(request.userid, title=page_title) userinfo = profile.select_userinfo(otherid, config=userprofile['config']) @@ -442,8 +443,7 @@ def favorites_(request): raise WeasylError('hiddenFavorites') userprofile = profile.select_profile(otherid, viewer=request.userid) - has_fullname = userprofile['full_name'] is not None and userprofile['full_name'].strip() != '' - page_title = "%s's favorites" % (userprofile['full_name'] if has_fullname else userprofile['username'],) + page_title = _get_page_title(userprofile, 'favorites') page = define.common_page_start(request.userid, title=page_title) if feature: @@ -509,6 +509,7 @@ def friends_(request): raise WeasylError('noGuests') userprofile = profile.select_profile(otherid, viewer=request.userid) + page_title = _get_page_title(userprofile, 'friends') relation = profile.select_relation(request.userid, otherid) rating = define.get_rating(request.userid) @@ -523,7 +524,7 @@ def friends_(request): frienduser.select_friends(request.userid, otherid, limit=44, backid=define.get_int(backid), nextid=define.get_int(nextid)), _get_post_counts_by_type(otherid, friends=relation["friend"] or relation["is_self"], rating=rating), - ])) + ], title=page_title)) def following_(request): @@ -541,6 +542,7 @@ def following_(request): raise WeasylError('noGuests') userprofile = profile.select_profile(otherid, viewer=request.userid) + page_title = _get_page_title(userprofile, 'followed users') relation = profile.select_relation(request.userid, otherid) rating = define.get_rating(request.userid) @@ -555,7 +557,7 @@ def following_(request): followuser.select_following(request.userid, otherid, limit=44, backid=define.get_int(backid), nextid=define.get_int(nextid)), _get_post_counts_by_type(otherid, friends=relation["friend"] or relation["is_self"], rating=rating), - ])) + ], title=page_title)) def followed_(request): @@ -573,6 +575,7 @@ def followed_(request): raise WeasylError('noGuests') userprofile = profile.select_profile(otherid, viewer=request.userid) + page_title = _get_page_title(userprofile, 'followers') relation = profile.select_relation(request.userid, otherid) rating = define.get_rating(request.userid) @@ -587,4 +590,4 @@ def followed_(request): followuser.select_followed(request.userid, otherid, limit=44, backid=define.get_int(backid), nextid=define.get_int(nextid)), _get_post_counts_by_type(otherid, friends=relation["friend"] or relation["is_self"], rating=rating), - ])) + ], title=page_title))