Compare commits

..
Author SHA1 Message Date
Typosaurus aae9c3698c ticket #89 attempt 1 2026-07-23 01:35:14 +00:00
7 changed files with 12 additions and 16 deletions
File diff suppressed because one or more lines are too long
+3
View File
@@ -44,6 +44,7 @@ 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
@@ -671,6 +672,7 @@ 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(
{
@@ -680,6 +682,7 @@ 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:
+2 -2
View File
@@ -439,8 +439,8 @@ class VoteForm(BaseModel):
@field_validator("value")
@classmethod
def valid_value(cls, value):
if value not in (1, -1, 0):
raise ValueError("value must be 1, -1, or 0")
if value not in (1, -1):
raise ValueError("value must be 1 or -1")
return value
+3 -1
View File
@@ -7,7 +7,6 @@ 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,
@@ -48,6 +47,7 @@ from devplacepy.utils import (
)
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,8 +188,10 @@ 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)
+2 -1
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 UserOut
from devplacepy.schemas.content import AttachmentOut, UserOut
class AuthPageOut(_Out):
@@ -38,6 +38,7 @@ class LandingPostOut(_Out):
comment_count: int = 0
stars: int = 0
slug: str = ""
attachments: list[AttachmentOut] = []
class TrendingTopicOut(_Out):
@@ -22,7 +22,7 @@ ENGAGEMENT_ACTIONS: tuple[Action, ...] = (
),
body(
"value",
"Vote value: 1 to upvote, -1 to downvote, 0 to retract.",
"Vote value: 1 to upvote, -1 to downvote (re-send to remove).",
required=True,
),
),
-10
View File
@@ -135,13 +135,3 @@ def test_non_ajax_vote_redirects_to_referer(app_server):
)
assert r.status_code == 302
assert r.headers["location"] == "/gists"
def test_explicit_zero_retracts_vote(app_server):
s_a, a_name = _session_votes()
s_b, _ = _session_votes()
post_uid = _make_post_votes(_uid_votes(a_name))
s_b.post(f"{BASE_URL}/votes/post/{post_uid}", data={"value": "1"}, headers=AJAX_votes)
r = s_b.post(f"{BASE_URL}/votes/post/{post_uid}", data={"value": "0"}, headers=AJAX_votes)
assert r.json()["value"] == 0
assert r.json()["net"] == 0