Skip to content

Commit

Permalink
unpin black version + lint
Browse files Browse the repository at this point in the history
  • Loading branch information
rm03 committed Nov 2, 2023
1 parent 4333f1d commit 2108fbe
Show file tree
Hide file tree
Showing 7 changed files with 515 additions and 529 deletions.
2 changes: 1 addition & 1 deletion backend/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
black = "==21.9b0"
black = "*"
unittest-xml-reporting = "*"
flake8 = "*"
flake8-isort = "*"
Expand Down
931 changes: 430 additions & 501 deletions backend/Pipfile.lock

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions backend/announcements/management/commands/populate_audiences.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@


class Command(BaseCommand):

def handle(self, *args, **options):
for x in ["MOBILE", "OHQ", "CLUBS", "COURSE_PLAN", "COURSE_REVIEW", "COURSE_ALERT"]:
Audience.objects.get_or_create(name=x)
for x in [
"MOBILE",
"OHQ",
"CLUBS",
"COURSE_PLAN",
"COURSE_REVIEW",
"COURSE_ALERT",
]:
Audience.objects.get_or_create(name=x)
65 changes: 51 additions & 14 deletions backend/announcements/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,67 @@


class Migration(migrations.Migration):

initial = True

dependencies = [
]
dependencies = []

operations = [
migrations.CreateModel(
name='Audience',
name="Audience",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(choices=[('MOBILE', 'Penn Mobile'), ('OHQ', 'OHQ'), ('CLUBS', 'Penn Clubs'), ('COURSE_PLAN', 'Penn Course Plan'), ('COURSE_REVIEW', 'Penn Course Review'), ('COURSE_ALERT', 'Penn Course Alert')], max_length=20)),
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"name",
models.CharField(
choices=[
("MOBILE", "Penn Mobile"),
("OHQ", "OHQ"),
("CLUBS", "Penn Clubs"),
("COURSE_PLAN", "Penn Course Plan"),
("COURSE_REVIEW", "Penn Course Review"),
("COURSE_ALERT", "Penn Course Alert"),
],
max_length=20,
),
),
],
),
migrations.CreateModel(
name='Announcement',
name="Announcement",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(blank=True, max_length=255, null=True)),
('message', models.TextField()),
('announcement_type', models.IntegerField(choices=[(1, 'Banner'), (2, 'Issue'), (3, 'Notice')], default=3)),
('release_time', models.DateTimeField(auto_now_add=True)),
('end_time', models.DateTimeField(blank=True, null=True)),
('audiences', models.ManyToManyField(related_name='announcements', to='announcements.audience')),
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("title", models.CharField(blank=True, max_length=255, null=True)),
("message", models.TextField()),
(
"announcement_type",
models.IntegerField(
choices=[(1, "Banner"), (2, "Issue"), (3, "Notice")], default=3
),
),
("release_time", models.DateTimeField(auto_now_add=True)),
("end_time", models.DateTimeField(blank=True, null=True)),
(
"audiences",
models.ManyToManyField(
related_name="announcements", to="announcements.audience"
),
),
],
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@


class Migration(migrations.Migration):

dependencies = [
('announcements', '0001_initial'),
("announcements", "0001_initial"),
]

operations = [
migrations.AlterField(
model_name='announcement',
name='announcement_type',
field=models.CharField(choices=[('NOTICE', 'Notice'), ('ISSUE', 'Issue')], default='NOTICE', max_length=20),
model_name="announcement",
name="announcement_type",
field=models.CharField(
choices=[("NOTICE", "Notice"), ("ISSUE", "Issue")],
default="NOTICE",
max_length=20,
),
),
]
3 changes: 1 addition & 2 deletions backend/announcements/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ class Announcement(models.Model):
choices=ANNOUNCEMENT_CHOICES,
default=ANNOUNCEMENT_NOTICE,
)
audiences = models.ManyToManyField("Audience",
related_name="announcements")
audiences = models.ManyToManyField("Audience", related_name="announcements")
release_time = models.DateTimeField(auto_now_add=True)
end_time = models.DateTimeField(null=True, blank=True)

Expand Down
18 changes: 15 additions & 3 deletions backend/announcements/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,27 @@ class Meta:


class AnnouncementSerializer(serializers.ModelSerializer):
audiences = serializers.SlugRelatedField(many=True, slug_field="name", queryset=Audience.objects.all())
audiences = serializers.SlugRelatedField(
many=True, slug_field="name", queryset=Audience.objects.all()
)

class Meta:
model = Announcement
fields = ("id", "title", "message", "announcement_type", "release_time", "end_time", "audiences")
fields = (
"id",
"title",
"message",
"announcement_type",
"release_time",
"end_time",
"audiences",
)

def to_representation(self, instance):
representation = super().to_representation(instance)
representation["audiences"] = [audience.name for audience in instance.audiences.all()]
representation["audiences"] = [
audience.name for audience in instance.audiences.all()
]
return representation

def to_internal_value(self, data):
Expand Down

0 comments on commit 2108fbe

Please sign in to comment.