Conversation
Template formatting
KavyanshKhaitan2
requested review from
Heliodex
and
a lite review from Copilot
September 9, 2026 12:14
There was a problem hiding this comment.
🟡 Changes recommended
A few new request-path validations rely on assert (unsafe in production) and the auth callback can still raise on missing sub, both leading to avoidable 500s.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR modernizes Twisted’s Django code and templates by adding typing/defensive checks, refactoring Slack notifications for admin/review flows, and reformatting UI templates (including some accessibility improvements like lang and alt attributes).
Changes:
- Add/adjust type annotations and more explicit empty-string checks across client/admin views and model helpers.
- Refactor Slack messaging to use a
send_blockshelper and add Slack logging error handling. - Reformat many templates/CSS and improve some markup semantics/accessibility (e.g.,
lang="en",alt=).
File summaries
| File | Description |
|---|---|
| twisted/twisted_site/views/image_upload.py | Tightens upload typing/validation and return types. |
| twisted/twisted_site/views/client/referrals.py | Adds typing and explicit referral-code emptiness checks. |
| twisted/twisted_site/views/client/projects.py | Adds typing/casts for profile/projects and request data. |
| twisted/twisted_site/views/client/project.py | Adds typed context, helper formatting, and safer sorting. |
| twisted/twisted_site/views/client/pathways.py | Adds typing/casts and list element typing. |
| twisted/twisted_site/views/client/journal.py | Adds typing and switches to typed template context. |
| twisted/twisted_site/views/client/homepage.py | Adds typing and explicit query-param emptiness checks. |
| twisted/twisted_site/views/client/discover.py | Adds typed request/response signatures. |
| twisted/twisted_site/views/client/dashboard.py | Adds typing for context and query param handling. |
| twisted/twisted_site/views/client/auth.py | Adds typed OAuth flow and more explicit null/empty handling. |
| twisted/twisted_site/views/ari.py | Refactors Slack blocks sending and adds some defensive checks. |
| twisted/twisted_site/views/admin/users.py | Adds typing and minor query handling tweaks. |
| twisted/twisted_site/views/admin/shop.py | Adds typed request/response signatures. |
| twisted/twisted_site/views/admin/review.py | Adds typing and minor cleanup for debug paths. |
| twisted/twisted_site/views/admin/pathways.py | Adds typing and explicit empty-string checks for form inputs. |
| twisted/twisted_site/views/admin/fulfillment.py | Adds typed request/response signatures. |
| twisted/twisted_site/views/admin/dashboard.py | Adds typing for chart data containers. |
| twisted/twisted_site/views/admin/audit_logs.py | Adds typed request/response and parameter typing. |
| twisted/twisted_site/views/admin/announcements.py | Adds typed request/response signatures. |
| twisted/twisted_site/views/admin/admin.py | Adds typed context/dispatch and staff permission provisioning. |
| twisted/twisted_site/templatetags/time_filters.py | Adds typing to template filters. |
| twisted/twisted_site/templatetags/maths.py | Adds typing to divide template filter. |
| twisted/twisted_site/templates/cotton/svg/tick.html | Reformat SVG markup. |
| twisted/twisted_site/templates/cotton/svg/cross.html | Reformat SVG markup. |
| twisted/twisted_site/templates/cotton/sidebar/item.html | Reformat sidebar item markup. |
| twisted/twisted_site/templates/cotton/sidebar/index.html | Reformat sidebar layout + add missing alt text. |
| twisted/twisted_site/templates/cotton/ship_message.html | Reformat ship message layout. |
| twisted/twisted_site/templates/cotton/project_ship_mark.html | Reformat and normalize quote style/indentation. |
| twisted/twisted_site/templates/cotton/pathway_card.html | Reformat pathway card markup. |
| twisted/twisted_site/templates/cotton/mdpreview.html | Reformat md preview wrapper. |
| twisted/twisted_site/templates/cotton/mdedit.html | Reformat md editor markup and JS indentation. |
| twisted/twisted_site/templates/cotton/button.html | Collapse button class formatting. |
| twisted/twisted_site/templates/cotton/base.html | Reformat admin base template, add lang, adjust message toasts. |
| twisted/twisted_site/templates/client/referrals.html | Reformat + add missing alt attributes. |
| twisted/twisted_site/templates/client/projects/ship.html | Reformat ship submission UI and some element semantics. |
| twisted/twisted_site/templates/client/projects/settings.html | Reformat + improves screenshot upload preview handling. |
| twisted/twisted_site/templates/client/projects/list.html | Reformat + set explicit type="button" where needed. |
| twisted/twisted_site/templates/client/projects/journal/new_untracked.html | Reformat + button/link semantics tweaks. |
| twisted/twisted_site/templates/client/projects/journal/new_journal.base.html | Reformat and simplify journal creation layout. |
| twisted/twisted_site/templates/client/projects/journal/new_hackatime.html | Reformat + button/link semantics tweaks. |
| twisted/twisted_site/templates/client/projects/journal/delete.html | Reformat delete confirmation UI. |
| twisted/twisted_site/templates/client/projects/create.html | Reformat create project UI. |
| twisted/twisted_site/templates/client/pathways.html | Reformat pathways listing and layout. |
| twisted/twisted_site/templates/client/osbase.html | Add lang, reformat, and tweak cookie setting JS. |
| twisted/twisted_site/templates/client/homepage.html | Reformat homepage UI and CTA button/link markup. |
| twisted/twisted_site/templates/client/faqs.html | Reformat FAQ page and close button markup. |
| twisted/twisted_site/templates/client/discover.html | Reformat discover UI and pagination buttons. |
| twisted/twisted_site/templates/admin/users.html | Reformat admin users search UI. |
| twisted/twisted_site/templates/admin/user.html | Reformat admin user detail view and tables. |
| twisted/twisted_site/templates/admin/shop.html | Reformat placeholder buttons. |
| twisted/twisted_site/templates/admin/review.html | Reformat placeholder buttons. |
| twisted/twisted_site/templates/admin/pathways/list.html | Reformat pathways list and SVG markup. |
| twisted/twisted_site/templates/admin/pathways/detail.html | Reformat pathway detail and participant table. |
| twisted/twisted_site/templates/admin/pathways/create.html | Reformat pathway create form and button markup. |
| twisted/twisted_site/templates/admin/logs.html | Reformat audit logs rendering + add alt to avatars. |
| twisted/twisted_site/templates/admin/fulfillment.html | Reformat placeholder buttons. |
| twisted/twisted_site/templates/admin/debug/review.html | Reformat debug review UI. |
| twisted/twisted_site/templates/admin/dashboard.html | Reformat dashboard tabs and Google charts scripts. |
| twisted/twisted_site/templates/admin/announcements.html | Reformat placeholder buttons. |
| twisted/twisted_site/slack.py | Adds send_blocks helper and Slack error handling for logging. |
| twisted/twisted_site/models.py | Adds typing, @override, and improves queryset truthiness handling. |
| twisted/twisted_site/hackatime.py | Adds typing and narrows JSON parsing shapes. |
| twisted/twisted_site/ari.py | Adds typing and more explicit empty checks; tightens helper signatures. |
| twisted/tailwindcsstheme/static_src/src/styles.css | Reformat styling and normalize casing/format. |
| twisted/mysite/wsgi.py | Assigns return value to _ for lint/type cleanliness. |
| twisted/mysite/settings.py | Uses explicit (None, \"\") empty checks and adds type-ignore comments. |
| twisted/mysite/middleware.py | Adds typing and explicit empty-cookie handling. |
| twisted/mysite/asgi.py | Assigns return value to _ for lint/type cleanliness. |
| twisted/manage.py | Adds return type and assigns env default to _. |
| twisted/common/templates/base.html | Adds doctype/lang and reformat cookie JS. |
Review details
Files not reviewed (1)
- twisted/tailwindcsstheme/static_src/src/cotton-ui.sources.css: Generated file
Suppressed comments (3)
twisted/twisted_site/views/image_upload.py:49
assert file.size is not Noneis not safe for production (asserts may be disabled) and will produce a 500 if size is missing. Prefer an explicit check with a clear client error response before computingfile_size_mb.
twisted/twisted_site/views/admin/admin.py:101- When
staff_permissionsis missing, a new object is created butpermsis never updated, soself.permsremainsNoneeven after provisioning permissions. Assign the newly created permissions topermsbefore storing it onself.
twisted/twisted_site/views/image_upload.py:124 file_uploaderrelies onassert image.name is not Nonefor a required field. If asserts are disabled, this can raise later (e.g.,Path(None)) and return a 500. Handle missing/empty names by returning a structured error dict.
- Files reviewed: 73/74 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
72
to
76
| email = userinfo.get("email", "hackclubber@example.com") | ||
| name = userinfo.get("name", "") | ||
| sub = userinfo.get("sub") | ||
| sub = cast(str, userinfo.get("sub")) | ||
| clean_sub = sub.replace("!", "_") | ||
| slack_id = userinfo.get("slack_id", "") |
Comment on lines
32
to
35
| if "file" in request.FILES: | ||
| file = request.FILES["file"] | ||
| assert isinstance(file, DjangoUploadedFile) | ||
|
|
yes the buttons still work :pensive-wobble:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before
After