Compare commits

..
Author SHA1 Message Date
Typosaurus 6a6e6716b1 ticket #112 attempt 1
DevPlace CI / test (pull_request) Failing after 11s
2026-07-23 02:49:57 +00:00
6 changed files with 43 additions and 9 deletions
File diff suppressed because one or more lines are too long
-3
View File
@@ -44,7 +44,6 @@ from devplacepy.templating import templates, jinja_unread_count
from devplacepy.cache import TTLCache
from devplacepy.responses import respond, wants_json, json_error
from devplacepy.schemas import LandingOut, ValidationErrorOut
from devplacepy.attachments import get_attachments_batch
from fastapi.responses import JSONResponse
from devplacepy.utils import get_current_user, time_ago, safe_next, client_ip
from devplacepy.seo import base_seo_context, site_url, website_schema
@@ -672,7 +671,6 @@ def _landing_recent_posts(blocked):
authors = get_users_by_uids(author_uids)
comment_counts = get_comment_counts_by_post_uids(post_uids)
upvotes, downvotes = get_vote_counts(post_uids)
attachments_map = get_attachments_batch("post", post_uids)
for p in raw_posts:
posts.append(
{
@@ -682,7 +680,6 @@ def _landing_recent_posts(blocked):
"comment_count": comment_counts.get(p["uid"], 0),
"stars": upvotes.get(p["uid"], 0) - downvotes.get(p["uid"], 0),
"slug": p.get("slug", "") or p["uid"],
"attachments": attachments_map.get(p["uid"], []),
}
)
if not blocked:
+8 -3
View File
@@ -7,6 +7,7 @@ from devplacepy.models import ProfileForm
from fastapi.responses import HTMLResponse, JSONResponse
from devplacepy.database import (
get_table,
db,
get_customization_prefs,
get_notification_prefs,
get_user_stars,
@@ -45,9 +46,9 @@ from devplacepy.utils import (
track_action,
build_achievements,
)
from devplacepy.utils.rewards import LEVEL_XP
from devplacepy.responses import respond, action_result, wants_json
from devplacepy.schemas import ProfileOut
from devplacepy.attachments import get_attachments_batch
from devplacepy.avatar import avatar_url, avatar_seed
from devplacepy.seo import (
base_seo_context,
@@ -188,10 +189,8 @@ async def profile_page(
else set()
)
polls_map = get_polls_by_post_uids(post_uids, current_user)
attachments_map = get_attachments_batch("post", post_uids)
for item in posts:
uid = item["post"]["uid"]
item["attachments"] = attachments_map.get(uid, [])
item["reactions"] = reactions_map.get(uid, {"counts": {}, "mine": []})
item["bookmarked"] = uid in bookmark_set
item["poll"] = polls_map.get(uid)
@@ -382,6 +381,10 @@ async def profile_page(
],
)
xp = profile_user.get("xp") or 0
xp_progress_pct = xp % LEVEL_XP
xp_next_level = ((xp // LEVEL_XP) + 1) * LEVEL_XP
return respond(
request,
"profile.html",
@@ -441,6 +444,8 @@ async def profile_page(
"awards_pagination": awards_pagination,
"awards_count": awards_count,
"prominent_award": prominent_award,
"xp_progress_pct": xp_progress_pct,
"xp_next_level": xp_next_level,
"can_give_award": can_give,
},
model=ProfileOut,
+1 -2
View File
@@ -5,7 +5,7 @@ from __future__ import annotations
from typing import Any, Optional
from devplacepy.schemas.base import _Out
from devplacepy.schemas.content import AttachmentOut, UserOut
from devplacepy.schemas.content import UserOut
class AuthPageOut(_Out):
@@ -38,7 +38,6 @@ class LandingPostOut(_Out):
comment_count: int = 0
stars: int = 0
slug: str = ""
attachments: list[AttachmentOut] = []
class TrendingTopicOut(_Out):
+2
View File
@@ -80,6 +80,8 @@ class ProfileOut(_Out):
awards_count: int = 0
prominent_award: Optional[AwardOut] = None
can_give_award: bool = False
xp_progress_pct: Optional[int] = None
xp_next_level: Optional[int] = None
class TelegramPairOut(_Out):
+31
View File
@@ -267,6 +267,37 @@ def test_activity_comment_card_renders_overlay_link(app_server):
assert f'class="card-link" href="/posts/{post_slug}#comment-{comment_uid}"' in r.text
def test_profile_json_contains_xp_progress(app_server):
from devplacepy.database import get_table, refresh_snapshot
import time
name = f"xp{int(time.time() * 1000)}"
session = requests.Session()
session.post(
f"{BASE_URL}/auth/signup",
data={
"username": name,
"email": f"{name}@t.dev",
"password": "secret123",
"confirm_password": "secret123",
},
allow_redirects=True,
)
user = get_table("users").find_one(username=name)
assert user is not None
get_table("users").update({"uid": user["uid"], "xp": 250}, ["uid"])
refresh_snapshot()
r = session.get(
f"{BASE_URL}/profile/{name}", headers={"Accept": "application/json"}
)
assert r.status_code == 200, f"status {r.status_code}: {r.text[:200]}"
body = r.json()
assert body["xp_progress_pct"] == 50
assert body["xp_next_level"] == 300
def test_profile_json_exposes_online_presence(app_server):
import time