Skip to content
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

Priority field to Post/Polls + Refactor #246

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions backend/portal/migrations/0015_auto_20240226_2236.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 3.2.22 on 2024-02-27 03:36

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("portal", "0014_alter_post_post_url"),
]

operations = [
migrations.AddField(
model_name="poll", name="priority", field=models.IntegerField(default=0),
),
migrations.AddField(
model_name="post", name="priority", field=models.IntegerField(default=0),
),
migrations.AlterField(model_name="poll", name="expire_date", field=models.DateTimeField(),),
]
35 changes: 12 additions & 23 deletions backend/portal/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __str__(self):
return self.population


class Poll(models.Model):
class Content(models.Model):
STATUS_DRAFT = "DRAFT"
STATUS_REVISION = "REVISION"
STATUS_APPROVED = "APPROVED"
Expand All @@ -37,15 +37,22 @@ class Poll(models.Model):
)

club_code = models.CharField(max_length=255, blank=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, not entirely sure of this myself. What are people's thoughts on having club_code and club_comment here? Do you think this is general enough for future models or should we push this back down to the Poll and Post models.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait what future models were you thinking of? I was thinking Content is just the "superclass" to Post/Polls, so has all the shared stuff. I guess you're thinking of a different "meaning" to Content?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm that is fair. Yea I think posts and polls are really all that is it. I was thinking maybe Ashley's Events could also inherit but thinking about it some more that wouldn't make sense. Okay down to merge haha

question = models.CharField(max_length=255)
created_date = models.DateTimeField(default=timezone.now)
start_date = models.DateTimeField(default=timezone.now)
expire_date = models.DateTimeField(default=timezone.now)
expire_date = models.DateTimeField()
status = models.CharField(max_length=30, choices=STATUS_OPTIONS, default=STATUS_DRAFT)
multiselect = models.BooleanField(default=False)
club_comment = models.CharField(max_length=255, null=True, blank=True)
admin_comment = models.CharField(max_length=255, null=True, blank=True)
target_populations = models.ManyToManyField(TargetPopulation, blank=True)
priority = models.IntegerField(default=0)

class Meta:
abstract = True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff haha



class Poll(Content):
question = models.CharField(max_length=255)
multiselect = models.BooleanField(default=False)

def __str__(self):
return f"{self.id} - {self.club_code} - {self.question}"
Expand All @@ -68,29 +75,11 @@ class PollVote(models.Model):
target_populations = models.ManyToManyField(TargetPopulation, blank=True)


class Post(models.Model):
STATUS_DRAFT = "DRAFT"
STATUS_REVISION = "REVISION"
STATUS_APPROVED = "APPROVED"

STATUS_OPTIONS = (
(STATUS_DRAFT, "Draft"),
(STATUS_REVISION, "Revision"),
(STATUS_APPROVED, "Approved"),
)

club_code = models.CharField(max_length=255, blank=True)
class Post(Content):
title = models.CharField(max_length=255)
subtitle = models.CharField(max_length=255)
post_url = models.CharField(max_length=255, null=True, blank=True)
image = models.ImageField(upload_to="portal/images", null=True, blank=True)
created_date = models.DateTimeField(default=timezone.now)
start_date = models.DateTimeField(default=timezone.now)
expire_date = models.DateTimeField()
status = models.CharField(max_length=30, choices=STATUS_OPTIONS, default=STATUS_DRAFT)
club_comment = models.CharField(max_length=255, null=True, blank=True)
admin_comment = models.CharField(max_length=255, null=True, blank=True)
target_populations = models.ManyToManyField(TargetPopulation, blank=True)

def __str__(self):
return f"{self.id} - {self.club_code} - {self.title}"
10 changes: 8 additions & 2 deletions backend/portal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ def browse(self, request):
# )

return Response(
RetrievePollSerializer(polls.distinct().order_by("expire_date"), many=True).data
RetrievePollSerializer(
polls.distinct().order_by("-priority", "start_date", "expire_date"), many=True
).data
)

@action(detail=False, methods=["get"], permission_classes=[IsSuperUser])
Expand Down Expand Up @@ -304,7 +306,11 @@ def browse(self, request):
# excludes the bad polls
posts = unfiltered_posts.exclude(id__in=bad_posts)

return Response(PostSerializer(posts.distinct().order_by("expire_date"), many=True).data)
return Response(
PostSerializer(
posts.distinct().order_by("-priority", "start_date", "expire_date"), many=True
).data
)

@action(detail=False, methods=["get"], permission_classes=[IsSuperUser])
def review(self, request):
Expand Down
Loading