forked from retoor/devplacepy
feat: add threaded comments with polymorphic targets and slug-based routing
Introduce `load_comments` helper supporting polymorphic target types (post, project, bug) with nested parent-child threading. Refactor comment creation to use `target_type`/`target_uid` and `resolve_target_redirect` for correct redirects. Replace raw UID-based post/project routes with slug-aware resolution via `resolve_post`/`resolve_project` and `make_combined_slug`. Update SEO, sitemap, and FAB styling to use slugs and hardcoded red accent. Add reusable `_comment_section.html` template.
This commit is contained in:
+18
-8
@@ -15,6 +15,7 @@ SEED_USERS = []
|
||||
ALL_USERNAMES = []
|
||||
USER_UIDS = []
|
||||
POST_UIDS = []
|
||||
POST_SLUGS = []
|
||||
PROJECT_UIDS = []
|
||||
COMMENT_UIDS = []
|
||||
TOPICS = ["devlog", "showcase", "question", "rant", "fun", "random"]
|
||||
@@ -105,9 +106,14 @@ def seed_data(environment, **kwargs):
|
||||
urllib.request.Request(f"{host}/posts/create", data=body),
|
||||
timeout=10,
|
||||
)
|
||||
m = re.search(r"/posts/([a-f0-9-]+)", resp.url)
|
||||
if m and m.group(1) not in POST_UIDS:
|
||||
POST_UIDS.append(m.group(1))
|
||||
m = re.search(r"/posts/(\S+)", resp.url)
|
||||
if m and m.group(1) not in POST_SLUGS:
|
||||
POST_SLUGS.append(m.group(1))
|
||||
# extract full UUID from the response HTML
|
||||
html = resp.read().decode("utf-8", errors="replace")
|
||||
m2 = re.search(rf'name="post_uid"\s+value="({UUID_RE})"', html)
|
||||
if m2 and m2.group(1) not in POST_UIDS:
|
||||
POST_UIDS.append(m2.group(1))
|
||||
except Exception as e:
|
||||
logger.warning(f"Create seed post failed: {e}")
|
||||
|
||||
@@ -214,10 +220,11 @@ class DevPlaceUser(HttpUser):
|
||||
|
||||
@task(4)
|
||||
def view_post(self):
|
||||
if not POST_UIDS:
|
||||
slugs = POST_SLUGS if POST_SLUGS else POST_UIDS
|
||||
if not slugs:
|
||||
return
|
||||
self.client.get(
|
||||
f"/posts/{random.choice(POST_UIDS)}", name="posts/[uid]"
|
||||
f"/posts/{random.choice(slugs)}", name="posts/[uid]"
|
||||
)
|
||||
|
||||
@task(3)
|
||||
@@ -272,9 +279,12 @@ class DevPlaceUser(HttpUser):
|
||||
catch_response=True,
|
||||
name="posts/create") as resp:
|
||||
if resp.status_code == 200 and resp.history:
|
||||
m = re.search(r"/posts/([a-f0-9-]+)", resp.url)
|
||||
if m and m.group(1) not in POST_UIDS:
|
||||
POST_UIDS.append(m.group(1))
|
||||
m = re.search(r"/posts/(\S+)", resp.url)
|
||||
if m and m.group(1) not in POST_SLUGS:
|
||||
POST_SLUGS.append(m.group(1))
|
||||
m2 = re.search(rf'name="post_uid"\s+value="({UUID_RE})"', resp.text)
|
||||
if m2 and m2.group(1) not in POST_UIDS:
|
||||
POST_UIDS.append(m2.group(1))
|
||||
resp.success()
|
||||
else:
|
||||
resp.failure("post not created")
|
||||
|
||||
Reference in New Issue
Block a user