Skip to content

Commit 0bf6f0f

Browse files
Inline project creation slug checks
1 parent 7708885 commit 0bf6f0f

2 files changed

Lines changed: 18 additions & 15 deletions

File tree

api/views/project_create.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,15 @@ def project_create_instructions_url(project_data):
4646
return instructions_url, None
4747

4848

49-
def project_slug(project_data, name):
49+
def project_create_slug(course, project_data, name):
5050
slug = project_data.get("slug")
51-
if slug:
52-
return slug
53-
generated_slug = slugify(name)
54-
return generated_slug
55-
51+
if not slug:
52+
slug = slugify(name)
5653

57-
def project_duplicate_error(course, slug):
5854
matching_project = Project.objects.filter(course=course, slug=slug)
5955
slug_exists = matching_project.exists()
6056
if slug_exists:
61-
return f"Project with slug '{slug}' already exists"
62-
return None
63-
64-
65-
def project_create_slug(course, project_data, name):
66-
slug = project_slug(project_data, name)
67-
error = project_duplicate_error(course, slug)
68-
if error:
57+
error = f"Project with slug '{slug}' already exists"
6958
return None, error
7059

7160
return slug, None

docs/refactoring-plan.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2901,6 +2901,20 @@ Steps:
29012901
append-construction, tuple-unpacking, and wide-positional-call cleanup gates
29022902
report zero violations with the 30-line production threshold and 60-line test
29032903
threshold, `uvx pyrefly check`, and `git diff --check`.
2904+
- [x] 2026-07-02: Removed the single-use project creation slug and duplicate
2905+
error helpers. `project_create_slug` now derives the requested/generated slug
2906+
and performs the duplicate check directly, keeping the slug validation path
2907+
in one short function. Verification:
2908+
`uv run ruff check api/views/project_create.py docs/refactoring-plan.md`,
2909+
`python -m py_compile api/views/project_create.py`,
2910+
`uv run python manage.py test api.tests.test_project_creation api.tests.test_projects`,
2911+
removed-helper reference scan, touched-function line-threshold scan,
2912+
`uvx pyrefly check`, repository AST cleanup scan excluding migrations
2913+
(`forbidden_comprehensions=0`, `threshold_violations=0`,
2914+
`append_constructed=0`, `wide_tuple_unpacking=0`,
2915+
`wide_positional_calls=0`, `wide_function_args=0`,
2916+
`nested_wide_for_unpacking=0`, `range_len_loops=0`), and
2917+
`git diff --check`.
29042918
- [x] Split Datamailer campaign action data construction out of the campaign
29052919
action handler so the handler only resolves the client, builds action data,
29062920
and runs the guarded action. Verification:

0 commit comments

Comments
 (0)