Skip to content

Commit

Permalink
Merge pull request #428 from Monstarrrr/feat/0_ispending
Browse files Browse the repository at this point in the history
rename isShadow to isPending and return isPending with Post resource
  • Loading branch information
seporterfield authored Jan 3, 2025
2 parents f51ebfa + c83410d commit e736677
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
17 changes: 17 additions & 0 deletions backend/core/migrations/0019_rename_isshadow_post_ispending.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 5.0.7 on 2025-01-03 20:28

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("core", "0018_post_isshadow"),
]

operations = [
migrations.RenameField(
model_name="post",
old_name="isShadow",
new_name="isPending",
),
]
2 changes: 1 addition & 1 deletion backend/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Post(models.Model):
followers: models.ManyToManyField = models.ManyToManyField(
User, related_name="followers", blank=True
)
isShadow: models.BooleanField = models.BooleanField(default=False)
isPending: models.BooleanField = models.BooleanField(default=False)


class Report(models.Model):
Expand Down
1 change: 1 addition & 0 deletions backend/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class Meta:
"upvotes",
"downvotes",
"followers",
"isPending",
"ownerUser",
]
read_only_fields = [
Expand Down
10 changes: 5 additions & 5 deletions backend/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,12 @@ def get_queryset(self):
if type == "argument":
if not self.request.user.is_authenticated:
# If user is not authenticated, only show non-shadow posts
queryset = queryset.filter(isShadow=False)
queryset = queryset.filter(isPending=False)
else:
# For arguments, show non-shadow posts plus user's shadow posts
queryset = queryset.filter(
Q(isShadow=False)
| Q(isShadow=True, ownerUserId=self.request.user.id)
Q(isPending=False)
| Q(isPending=True, ownerUserId=self.request.user.id)
)

if parentId:
Expand All @@ -445,10 +445,10 @@ def get_queryset(self):
return queryset

def perform_create(self, serializer):
is_shadow = serializer.validated_data.get("type") == "argument"
is_pending = serializer.validated_data.get("type") == "argument"

post: Post = serializer.save(
ownerUserId=self.request.user.id, isShadow=is_shadow
ownerUserId=self.request.user.id, isPending=is_pending
)

# Get or create user profile
Expand Down

0 comments on commit e736677

Please sign in to comment.