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

chore: activities shown in custom order & then alphabetical #2234

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 5.0.8 on 2024-09-19 22:07

from django.db import migrations


def update_activity_weights(apps, schema_monitor):
'''
Update weights to reflect how IRC would like activities ordered
'''

Activity = apps.get_model('registration', 'Activity')
Activity.objects.all().update(weight=9999)
Activity.objects.filter(name='General stationary combustion excluding line tracing').update(weight=100)
Activity.objects.filter(name='General stationary combustion solely for the purpose of line tracing').update(
weight=200
)
Activity.objects.filter(
name='General stationary combustion, other than non-compression and non-processing combustion'
).update(weight=300)
Activity.objects.filter(name='General stationary non-compression and non-processing combustion').update(weight=400)
Activity.objects.filter(name='Fuel combustion by mobile equipment').update(weight=500)


class Migration(migrations.Migration):

dependencies = [
('registration', '0042_prod_data'),
]

operations = [
# No reverse function needed here
migrations.RunPython(update_activity_weights),
]
2 changes: 1 addition & 1 deletion bc_obps/service/activity_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ def get_initial_activity_data(request, activity_name: str, report_date: str) ->

@classmethod
def get_all_activities(cls) -> List[Dict[str, Any]]:
activities = Activity.objects.all().values("id", "name", "applicable_to")
activities = Activity.objects.all().order_by('weight', 'name').values("id", "name", "applicable_to")
return [dict(activity) for activity in activities]
2 changes: 1 addition & 1 deletion bc_obps/service/data_access_service/activity_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ def get_activities(cls) -> QuerySet[Activity]:
if cached_data:
return cached_data
else:
activities = Activity.objects.only(*ActivitySchema.Meta.fields)
activities = Activity.objects.only(*ActivitySchema.Meta.fields).order_by('weight', 'name')
cache.set("activities", activities, 60 * 60 * 24 * 1)
return activities
14 changes: 14 additions & 0 deletions bc_obps/service/tests/test_activity_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pytest
from registration.models import Activity
from service.activity_service import ActivityService

pytestmark = pytest.mark.django_db


class TestAddressService:
@staticmethod
def test_get_all_activities():
all_activities_sorted = Activity.objects.all().order_by('weight', 'name')
from_service = ActivityService.get_all_activities()
for i in range(len(all_activities_sorted)):
assert all_activities_sorted[i].name == from_service[i]['name']