Skip to content

Commit

Permalink
Merge pull request #435 from UCF/default-value-highlights
Browse files Browse the repository at this point in the history
Highlights Data Consistency Fix
  • Loading branch information
jmbarne3 authored Jul 24, 2024
2 parents 12e13f3 + 0af7b87 commit b30d1a1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
6 changes: 3 additions & 3 deletions core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def get_initial(self):
initial['jobs_source'] = jobs_source

if highlights:
initial['highlights'] = highlights
initial['highlights'] = json.dumps(highlights)

return initial

Expand Down Expand Up @@ -323,10 +323,10 @@ def form_valid(self, form):
# Filter out entries with empty 'icon_class' or 'description'
filtered_highlights = [entry for entry in highlights_list if entry['icon_class'] or entry['description']]
if filtered_highlights:
program.highlights = json.dumps(filtered_highlights)
program.highlights = filtered_highlights
program.save()
if not filtered_highlights:
program.highlights = json.dumps([])
program.highlights = []
program.save()

# Remove jobs that are no longer listed
Expand Down
29 changes: 29 additions & 0 deletions programs/migrations/0062_auto_20240724_1513.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 3.2.20 on 2024-07-24 15:13
import json

from django.db import migrations


class Migration(migrations.Migration):

def forward(apps, schema_editor):
Program = apps.get_model('programs', 'Program')
for row in Program.objects.filter(highlights__isnull=False):
highlights = row.highlights
if isinstance(highlights, str):
highlights = json.loads(highlights)

row.highlights = highlights
row.save()


dependencies = [
('programs', '0061_alter_program_highlights'),
]

operations = [
migrations.RunPython(
forward,
reverse_code=migrations.RunPython.noop
)
]
6 changes: 0 additions & 6 deletions programs/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,6 @@ class Meta:
)
model = AcademicTerm

class HighlightField(serializers.JSONField):
def to_representation(self, value):
# Convert the JSON to a dictionary for display
return json.loads(value) if value else []

class ProgramSerializer(DynamicFieldSetMixin, serializers.ModelSerializer):
level = serializers.StringRelatedField(many=False)
Expand Down Expand Up @@ -436,8 +432,6 @@ class ProgramSerializer(DynamicFieldSetMixin, serializers.ModelSerializer):
area_of_interest = serializers.SerializerMethodField()
subarea_of_interest = serializers.SerializerMethodField()

highlights = HighlightField(read_only=True)

def get_excerpt(self, obj: Program):
return obj.excerpt

Expand Down

0 comments on commit b30d1a1

Please sign in to comment.