Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
"SEE_API_CLIENT_SECRET": {}
},
"features": {},
"postStartCommand": "while [ \"$(python manage.py showmigrations | grep \"\\[ \\]\" | wc -l)\" -ne \"0\" ]; do echo \"waiting for migrations\"; sleep 2; done && python manage.py update_offered_by && python manage.py update_platforms && python manage.py update_departments_schools && python manage.py backpopulate_resource_channels --overwrite --all && python manage.py update_course_number_departments && python manage.py backpopulate_mitxonline_data && python manage.py backpopulate_micromasters_data && python manage.py recreate_index --all",
"postStartCommand": "while [ \"$(python manage.py showmigrations | grep \"\\[ \\]\" | wc -l)\" -ne \"0\" ]; do echo \"waiting for migrations\"; sleep 2; done && python manage.py update_offered_by && python manage.py update_platforms && python manage.py update_departments_schools && python manage.py update_course_number_departments && python manage.py backpopulate_mitxonline_data && python manage.py backpopulate_micromasters_data && python manage.py backpopulate_resource_channels --overwrite --all && python manage.py recreate_index --all",
"forwardPorts": [8062, 8063]
}
23 changes: 23 additions & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
Release Notes
=============

Version 0.22.1 (Released October 15, 2024)
--------------

- increase learning path listing limit to 100 (#1692)
- Shanbady/consolidate static fixtures (#1684)

Version 0.22.0 (Released October 15, 2024)
--------------

- Make add to list dialog scrollable (#1689)
- make search defaults settable (#1681)
- Shuffling around where the search_update event is fired so it happens in more places (#1679)
- prevent featured course carousel from re-randomizing (#1673)

Version 0.21.3 (Released October 15, 2024)
--------------

- removing invalid flag from clear cache command (#1675)
- Clear Cache on Deploy (#1668)
- Update Yarn to v4.5.0 (#1624)
- topic detail banner / subtopic logic revisions (#1646)
- Restore program letter intercept view (#1643)

Version 0.21.2 (Released October 10, 2024)
--------------

Expand Down
4 changes: 4 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@
"description": "Default max incompleteness penalty value for the search API and frontend",
"required": false
},
"DEFAULT_SEARCH_CONTENT_FILE_SCORE_WEIGHT": {
"description": "Default score weight for content file search match",
"required": false
},
"EDX_API_ACCESS_TOKEN_URL": {
"description": "URL to retrieve a MITx access token",
"required": false
Expand Down
32 changes: 32 additions & 0 deletions data_fixtures/migrations/0001_add_testimonial_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
from django.core.files import File
from django.db import migrations

from data_fixtures.utils import (
upsert_department_data,
upsert_offered_by_data,
upsert_platform_data,
upsert_school_data,
upsert_topic_data_file,
)

logger = logging.getLogger(__name__)

"""
Fix an issue with PIL's logger when running in test
https://github.com/camptocamp/pytest-odoo/issues/15
Expand Down Expand Up @@ -216,6 +226,27 @@
]


def load_initial_fixtures(apps, schema_editor):
"""
Load initial static fixtures required by
management commands further down
"""
offerors = upsert_offered_by_data()
departments = upsert_department_data()
schools = upsert_school_data()
platforms = upsert_platform_data()
topics = upsert_topic_data_file()
logout = (
f"Updated:"
f" {offerors} offerors"
f" {departments} departments"
f" {schools} schools"
f" {platforms} platforms"
f" {topics} topics"
)
logger.info(logout)


def load_fixtures(apps, schema_editor):
"""
Load fixtures for testimonials
Expand Down Expand Up @@ -252,5 +283,6 @@ class Migration(migrations.Migration):
dependencies = []

operations = [
migrations.RunPython(load_initial_fixtures, migrations.RunPython.noop),
migrations.RunPython(load_fixtures, migrations.RunPython.noop),
]
2 changes: 1 addition & 1 deletion data_fixtures/migrations/0004_upsert_initial_topic_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.db import migrations

from learning_resources.utils import upsert_topic_data_file
from data_fixtures.utils import upsert_topic_data_file


def perform_topic_upsert(apps, schema_editor):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from django.db import migrations

from learning_resources.utils import upsert_topic_data_string
from data_fixtures.utils import upsert_topic_data_string

map_changes = """
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.db import migrations

from channels.constants import ChannelType
from learning_resources.utils import upsert_topic_data_string
from data_fixtures.utils import upsert_topic_data_string

map_changes = """
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from django.db import migrations

from learning_resources.utils import upsert_topic_data_string
from data_fixtures.utils import upsert_topic_data_string

forward_map_changes = """
---
Expand Down
8 changes: 7 additions & 1 deletion data_fixtures/migrations/0014_add_department_SP.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def add_sp(apps, schema_editor):
department, _ = LearningResourceDepartment.objects.get_or_create(
department_id="SP",
name="Special Programs",
defaults={
"department_id": "SP",
"name": "Special Programs",
},
)
Channel = apps.get_model("channels", "Channel")

Expand All @@ -43,7 +47,9 @@ def add_sp(apps, schema_editor):
title=department.name,
)
ChannelDepartmentDetail.objects.get_or_create(
channel=channel, department=department
channel=channel,
department=department,
defaults={"channel": channel, "department": department},
)


Expand Down
147 changes: 147 additions & 0 deletions data_fixtures/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import json
from pathlib import Path

import yaml
from django.db import transaction

from learning_resources.models import (
LearningResourceDepartment,
LearningResourceOfferor,
LearningResourcePlatform,
LearningResourceSchool,
)
from learning_resources.utils import (
_walk_topic_map,
department_delete_actions,
offeror_delete_actions,
offeror_upserted_actions,
)


@transaction.atomic()
def upsert_topic_data_file(
config_path: str = "learning_resources/data/topics.yaml",
) -> None:
"""
Load the topics from a yaml file.

The yaml file should have a root "topics" key, and then any number of topic
records beneath it. See _walk_topic_map for an explanation of the record
format.

Args:
- config_path (str): the path to the topics file.
Returns:
- None
"""

with Path.open(Path(config_path)) as topic_file:
topic_file_yaml = topic_file.read()

topics = yaml.safe_load(topic_file_yaml)

_walk_topic_map(topics["topics"])


@transaction.atomic()
def upsert_offered_by_data():
"""
Upsert LearningResourceOfferor data
"""
offerors = []
with Path.open(Path(__file__).parent / "fixtures" / "offered_by.json") as inf:
offered_by_json = json.load(inf)
for offeror in offered_by_json:
offeror_fields = offeror["fields"]
offered_by, _ = LearningResourceOfferor.objects.update_or_create(
code=offeror_fields["code"],
defaults=offeror_fields,
)
offeror_upserted_actions(offered_by, overwrite=True)
offerors.append(offeror_fields["name"])
invalid_offerors = LearningResourceOfferor.objects.exclude(name__in=offerors)
for offeror in invalid_offerors:
offeror_delete_actions(offeror)
return offerors


@transaction.atomic()
def upsert_department_data():
"""
Upsert LearningResourceDepartment data
"""
departments = []
with Path.open(Path(__file__).parent / "fixtures" / "departments.json") as inf:
departments_json = json.load(inf)
for dept in departments_json:
department_fields = dept["fields"]
LearningResourceDepartment.objects.update_or_create(
department_id=department_fields["department_id"],
defaults=department_fields,
)
departments.append(department_fields["name"])
invalid_departments = LearningResourceDepartment.objects.exclude(
name__in=departments
).all()
for invalid_department in invalid_departments:
department_delete_actions(invalid_department)
return departments


@transaction.atomic()
def upsert_school_data():
"""
Upsert LearningResourceSchool data
"""
schools = []
with Path.open(Path(__file__).parent / "fixtures" / "schools.json") as inf:
schools_json = json.load(inf)
for school in schools_json:
school_fields = school["fields"]
LearningResourceSchool.objects.update_or_create(
id=school_fields["id"],
defaults=school_fields,
)
schools.append(school_fields["name"])
LearningResourceSchool.objects.exclude(name__in=schools).delete()
return schools


@transaction.atomic()
def upsert_platform_data():
"""
Upsert LearningResourcePlatform data
"""
platforms = []
with Path.open(Path(__file__).parent / "fixtures" / "platforms.json") as inf:
platform_json = json.load(inf)
for platform in platform_json:
platform_fields = platform["fields"]
LearningResourcePlatform.objects.update_or_create(
code=platform_fields["code"],
defaults=platform_fields,
)
platforms.append(platform_fields["code"])
LearningResourcePlatform.objects.exclude(code__in=platforms).delete()
return platforms


@transaction.atomic()
def upsert_topic_data_string(yaml_data: str) -> None:
"""
Load the topics from a yaml string.

The yaml string should be formatted in the same way that it is for
upsert_topic_data_file - this function exists just to allow you to specify
the data as a string so you can roll it into a migration file in the
data_fixtures app.

Args:
- yaml_data (str): the yaml to process
Returns:
- None
"""

topics = yaml.safe_load(yaml_data)

_walk_topic_map(topics["topics"])
5 changes: 5 additions & 0 deletions frontends/api/src/clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
NewsEventsApi,
ProfilesApi,
TestimonialsApi,
LearningResourcesSearchAdminParamsApi,
} from "./generated/v0/api"

import axiosInstance from "./axios"
Expand All @@ -46,6 +47,9 @@ const learningResourcesSearchApi = new LearningResourcesSearchApi(
axiosInstance,
)

const learningResourcesSearchAdminParamsApi =
new LearningResourcesSearchAdminParamsApi(undefined, BASE_PATH, axiosInstance)

const featuredApi = new FeaturedApi(undefined, BASE_PATH, axiosInstance)

const learningpathsApi = new LearningpathsApi(
Expand Down Expand Up @@ -108,4 +112,5 @@ export {
newsEventsApi,
featuredApi,
testimonialsApi,
learningResourcesSearchAdminParamsApi,
}
Loading
Loading