-
Notifications
You must be signed in to change notification settings - Fork 27
Simple comments feed #4499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hlbmtc
wants to merge
66
commits into
main
Choose a base branch
from
feat/4497-simple-comments-feed
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Simple comments feed #4499
Changes from all commits
Commits
Show all changes
66 commits
Select commit
Hold shift + click to select a range
5ba498d
Top comments card design
hlbmtc 0303b96
Small fixes
hlbmtc 3fe16a2
Small fixes
hlbmtc a3315f3
Small fixes
hlbmtc 0564847
Small fix
hlbmtc faa50f5
Added PostPreview continuous fit
hlbmtc 13db015
Small tweaks
hlbmtc bf56a28
Added comment skeleton
hlbmtc cc06b6e
- Compact version
hlbmtc 7a96210
Moved comment "View" button
hlbmtc fd00f62
Adjusted button
hlbmtc 244ac47
Small polish
hlbmtc 5c94b34
Don't show "expand" button for short comments
hlbmtc c0a74b6
Tweaked the skeleton
hlbmtc fa40ffe
Small fix
hlbmtc 1c1bdc3
Moved comments + forecasters block on top
hlbmtc cab8cb0
Don't fetch CP history for top comments
hlbmtc a9de7d3
Added notebooks support
hlbmtc d244ef6
Mobile improvements
hlbmtc f1c0883
Adjusted page navigation transition
hlbmtc b000e72
Skeleton tweaks
hlbmtc a235faf
Extra fixes
hlbmtc 7e39bf4
Small fix
hlbmtc f155ce4
Review comments
hlbmtc b8395fa
Review comments
hlbmtc 584be9f
Small refactor
hlbmtc 189d11f
Merge branch 'main' into feat/top-comments-card-design
hlbmtc 0379494
Small refactor
hlbmtc 3f11fcd
Small fix
hlbmtc bcf5452
Small fix
hlbmtc 53af71c
PR review fixes
hlbmtc bce39ea
Small fix
hlbmtc 3cc1e55
Backend integration
hlbmtc 873a706
Comments feed frontend
hlbmtc 064404f
Adjusted migration
hlbmtc f60c415
Small fix
hlbmtc 6619430
Small fix
hlbmtc e5abf52
Small fix
hlbmtc d2bc11f
Small fix
hlbmtc f67afb5
Merge remote-tracking branch 'origin/feat/4497-simple-comments-feed' …
hlbmtc b35cfab
Small fix
hlbmtc a46bdfe
Small fix
hlbmtc 4a2a7fb
Merge branch 'main' into feat/4497-simple-comments-feed
hlbmtc ba560a2
Small fix
hlbmtc d491582
Ajdusted loading
hlbmtc 3af6dff
Migration fix
hlbmtc df53b65
Merge remote-tracking branch 'origin/feat/4497-simple-comments-feed' …
hlbmtc 4b8e71c
Added Voting
hlbmtc 6ff1def
Adjusted mobile nav
hlbmtc 713d522
Small refactor
hlbmtc dd672e7
Added exclude_bots flag
hlbmtc 7398d63
Small adjustments
hlbmtc e78374a
Merge remote-tracking branch 'origin/feat/4497-simple-comments-feed' …
hlbmtc 07bc3cb
Comments denormalization
hlbmtc 4bc4ef0
Small fix
hlbmtc f41943e
Merge branch 'feat/comment-denormalized-fields' into feat/4497-simple…
hlbmtc 4000898
Small fix
hlbmtc 5742872
Small fix
hlbmtc ba12edf
Merge branch 'feat/comment-denormalized-fields' into feat/4497-simple…
hlbmtc 5e4481e
Small fix
hlbmtc 194b096
Merge branch 'main' into feat/4497-simple-comments-feed
hlbmtc 40bfe27
Small adjustments
hlbmtc 3965cec
Backend fixes
hlbmtc b71a664
Small fix
hlbmtc f4fda79
Comments feed: use CountlessLimitOffsetPagination isntead of LimitOff…
hlbmtc 905eead
Small fix
hlbmtc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import datetime | ||
| import difflib | ||
|
|
||
| from django.db import transaction | ||
| from django.db import IntegrityError, transaction | ||
| from django.db.models import ( | ||
| F, | ||
| Sum, | ||
|
|
@@ -267,6 +267,40 @@ def compute_comment_score( | |
| return score | ||
|
|
||
|
|
||
| def vote_comment(comment: Comment, user: User, direction: int | None) -> int: | ||
| try: | ||
| with transaction.atomic(): | ||
| CommentVote.objects.filter(user=user, comment=comment).delete() | ||
|
|
||
| if direction: | ||
| CommentVote.objects.create( | ||
| user=user, comment=comment, direction=direction | ||
| ) | ||
| except IntegrityError: | ||
| pass | ||
|
|
||
| return comment.update_vote_score() | ||
|
|
||
|
|
||
| def toggle_cmm(comment: Comment, user: User, enabled: bool) -> bool | None: | ||
| """Returns True if created, False if deleted, None if no-op.""" | ||
| try: | ||
| with transaction.atomic(): | ||
| cmm = ChangedMyMindEntry.objects.filter(user=user, comment=comment) | ||
|
|
||
| if not enabled and cmm.exists(): | ||
| cmm.delete() | ||
| comment.update_cmm_count() | ||
| return False | ||
|
|
||
| if enabled and not cmm.exists(): | ||
| ChangedMyMindEntry.objects.create(user=user, comment=comment) | ||
| comment.update_cmm_count() | ||
| return True | ||
| except IntegrityError: | ||
| pass | ||
|
|
||
|
|
||
|
Comment on lines
+270
to
+303
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not silently swallow Current Safer pattern: validate inputs + deterministic writes + explicit failure def vote_comment(comment: Comment, user: User, direction: int | None) -> int:
- try:
- with transaction.atomic():
- CommentVote.objects.filter(user=user, comment=comment).delete()
-
- if direction:
- CommentVote.objects.create(
- user=user, comment=comment, direction=direction
- )
- except IntegrityError:
- pass
+ if direction not in (None, -1, 1):
+ raise ValidationError("direction must be one of: -1, 1, null")
+
+ with transaction.atomic():
+ if direction is None:
+ CommentVote.objects.filter(user=user, comment=comment).delete()
+ else:
+ CommentVote.objects.update_or_create(
+ user=user,
+ comment=comment,
+ defaults={"direction": direction},
+ )
return comment.update_vote_score()
def toggle_cmm(comment: Comment, user: User, enabled: bool) -> bool | None:
"""Returns True if created, False if deleted, None if no-op."""
- try:
- with transaction.atomic():
- cmm = ChangedMyMindEntry.objects.filter(user=user, comment=comment)
-
- if not enabled and cmm.exists():
- cmm.delete()
- comment.update_cmm_count()
- return False
-
- if enabled and not cmm.exists():
- ChangedMyMindEntry.objects.create(user=user, comment=comment)
- comment.update_cmm_count()
- return True
- except IntegrityError:
- pass
+ with transaction.atomic():
+ if enabled:
+ _, created = ChangedMyMindEntry.objects.get_or_create(
+ user=user, comment=comment
+ )
+ if created:
+ comment.update_cmm_count()
+ return True
+ return None
+
+ deleted, _ = ChangedMyMindEntry.objects.filter(
+ user=user, comment=comment
+ ).delete()
+ if deleted:
+ comment.update_cmm_count()
+ return False
+ return None🤖 Prompt for AI Agents |
||
| def set_comment_excluded_from_week_top(comment: Comment, excluded: bool = True): | ||
| entry = comment.comments_of_the_week_entry | ||
| if entry: | ||
|
|
||
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: Metaculus/metaculus
Length of output: 246
🏁 Script executed:
Repository: Metaculus/metaculus
Length of output: 4348
Use
schema_editor.connectioninstead of globaldjango.db.connectionin migration callbacks.RunPythonshould use the migration's active DB alias; globalconnectioncan target the wrong DB in multi-database setups. This migration calls three backfill functions viamigrations.RunPython()(lines 91–95), all of which use the incorrect pattern on lines 10, 25, and 40.Suggested fix
🤖 Prompt for AI Agents