Compare commits

..
Author SHA1 Message Date
Typosaurus 141921d7a3 ticket #135 attempt 1 2026-07-25 07:23:47 +00:00
11 changed files with 78 additions and 84 deletions
File diff suppressed because one or more lines are too long
+1
View File
@@ -42,6 +42,7 @@ def init_db():
_index(db, "posts", "idx_posts_created_at", ["created_at"])
_index(db, "posts", "idx_posts_topic", ["topic"])
_index(db, "posts", "idx_posts_slug", ["slug"])
_index(db, "posts", "idx_posts_project_uid", ["project_uid"])
if "posts" in tables:
posts_table = get_table("posts")
if not posts_table.has_column("tags"):
-2
View File
@@ -38,7 +38,6 @@ def field(
example="",
description="",
options=None,
nullable=False,
):
spec = {
"name": name,
@@ -47,7 +46,6 @@ def field(
"required": required,
"example": example,
"description": description,
"nullable": nullable,
}
if options:
spec["options"] = list(options)
+2 -11
View File
@@ -39,15 +39,7 @@ def _unwrap_optional(annotation):
return annotation
def _is_optional(annotation):
if get_origin(annotation) is Union:
return type(None) in get_args(annotation)
return False
def _value(name, annotation, stack, is_nullable=False):
if is_nullable:
return None
def _value(name, annotation, stack):
annotation = _unwrap_optional(annotation)
origin = get_origin(annotation)
if origin in (list, set, tuple):
@@ -79,8 +71,7 @@ def _from_model(model, stack):
stack = stack | {model}
example = {}
for name, info in model.model_fields.items():
is_nullable = _is_optional(info.annotation)
example[name] = _value(name, info.annotation, stack, is_nullable)
example[name] = _value(name, info.annotation, stack)
return example
+10
View File
@@ -216,6 +216,15 @@ async def project_detail(request: Request, project_slug: str):
if parent
else None
)
posts_table = get_table("posts")
project_posts = list(
posts_table.find(
project_uid=project["uid"],
deleted_at=None,
order_by=["-created_at"],
)
)
return respond(
request,
"project_detail.html",
@@ -235,6 +244,7 @@ async def project_detail(request: Request, project_slug: str):
"forked_from": forked_from,
"fork_count": count_forks(project["uid"]),
"file_count": count_files(project["uid"]),
"project_posts": project_posts,
},
),
model=ProjectDetailOut,
+1
View File
@@ -163,6 +163,7 @@ class ProjectDetailOut(_Out):
forked_from: Optional[dict] = None
fork_count: int = 0
file_count: int = 0
project_posts: list[PostOut] = []
class GistsOut(_Out):
-10
View File
@@ -218,16 +218,6 @@
font-weight: 700;
}
.param-nullable {
font-size: 0.625rem;
text-transform: uppercase;
letter-spacing: 0.05em;
color: var(--text-muted);
border: 1px dashed var(--border);
border-radius: 999px;
padding: 0.05rem 0.4rem;
}
.param-loc {
font-size: 0.625rem;
text-transform: uppercase;
+47
View File
@@ -313,3 +313,50 @@
color: var(--text-muted);
margin-bottom: 0.5rem;
}
.project-devlog {
margin-top: 2rem;
padding-top: 1.5rem;
border-top: 1px solid var(--border);
}
.devlog-list {
list-style: none;
padding: 0;
margin: 0;
}
.devlog-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.5rem 0;
border-bottom: 1px solid var(--border);
gap: 1rem;
}
.devlog-item:last-child {
border-bottom: none;
}
.devlog-link {
color: var(--text-primary);
text-decoration: none;
font-weight: 500;
}
.devlog-link:hover {
color: var(--accent);
}
.devlog-date {
font-size: 0.8125rem;
color: var(--text-muted);
white-space: nowrap;
flex-shrink: 0;
}
.devlog-empty {
color: var(--text-muted);
font-size: 0.875rem;
}
-1
View File
@@ -139,7 +139,6 @@ export class ApiTester {
const label = this.el("div", { class: "param-label" }, [
this.el("span", { class: "param-name", text: param.name }),
param.required ? this.el("span", { class: "param-required", text: "*" }) : null,
param.nullable ? this.el("span", { class: "param-nullable", text: "nullable" }) : null,
this.el("span", { class: "param-loc param-loc-" + param.location, text: param.location }),
]);
const allowed = param.type === "enum" && param.options && param.options.length
+16
View File
@@ -170,6 +170,22 @@
{% endcall %}
{% endif %}
<div class="project-devlog">
<h2 class="project-section-label">Devlog</h2>
{% if project_posts %}
<ul class="devlog-list">
{% for post in project_posts %}
<li class="devlog-item">
<a href="/posts/{{ post['slug'] }}" class="devlog-link">{{ render_title(post['title']) }}</a>
<span class="devlog-date">{{ local_dt(post['created_at'], 'date') }}</span>
</li>
{% endfor %}
</ul>
{% else %}
<p class="devlog-empty">No posts yet for this project.</p>
{% endif %}
</div>
{% with target_uid=project['uid'], target_type="project" %}
{% include "_comment_section.html" %}
{% endwith %}
-59
View File
@@ -1,59 +0,0 @@
# retoor <retoor@molodetz.nl>
from typing import Optional
from pydantic import BaseModel
from devplacepy.docs_api._shared import field
from devplacepy.docs_examples import _is_optional, schema_example
def test_field_nullable_parameter():
f = field("bio", "query", "string", False, "", "User biography", nullable=True)
assert f["nullable"] is True
f2 = field("username", "path", "string", True, "alice", "Target username")
assert f2["nullable"] is False
def test_is_optional_optional_type():
assert _is_optional(Optional[str]) is True
assert _is_optional(Optional[int]) is True
assert _is_optional(Optional[list[str]]) is True
def test_is_optional_non_optional():
assert _is_optional(str) is False
assert _is_optional(int) is False
assert _is_optional(list[str]) is False
assert _is_optional(dict) is False
def test_schema_example_nullable_fields():
class NullableModel(BaseModel):
name: str
bio: Optional[str] = None
age: int
score: Optional[int] = None
tags: Optional[list[str]] = None
result = schema_example(NullableModel)
assert result["name"] == "string"
assert result["age"] == 0
assert result["bio"] is None
assert result["score"] is None
assert result["tags"] is None
def test_schema_example_non_nullable_fields_unaffected():
class StrictModel(BaseModel):
x: str
y: int
z: bool
result = schema_example(StrictModel)
assert result["x"] == "string"
assert result["y"] == 0
assert result["z"] is False