Example #1
0
    def save(self, *args, **kwargs):
        if self.id is None:
            super(Lesson, self).save(*args, **kwargs)
            kwargs["force_update"] = True
            kwargs["force_insert"] = False

        agg_activities = curry(self.aggregate_activity_attr, self.activities.all())

        # These are normal fields, so we can set them before we save
        agg_pki = agg_activities("prior_knowledge_items")
        self.prior_knowledge = json.dumps(list(set(chain(*agg_pki))))
        self.accessibility_notes = list_as_ul(
            list(set(chain(*[ul_as_list(x) for x in agg_activities("accessibility_notes")])))
        )
        rsd = agg_activities("relevant_start_date")
        if rsd:
            self.relevant_start_date = min(rsd)
        red = agg_activities("relevant_end_date")
        if red:
            self.relevant_end_date = max(red)
        gt = agg_activities("geologic_time")
        if gt:
            self.geologic_time = min(gt)
        self.duration = self._calc_duration(self.activities.all())
        super(Lesson, self).save(*args, **kwargs)
        self._sync_m2m(self.eras, agg_activities("eras"))
        self._sync_m2m(self.subjects, agg_activities("subjects", ignore_own=True))
        self._sync_m2m(self.grades, agg_activities("grades", ignore_own=True))
        self._sync_m2m(self.physical_space_types, agg_activities("physical_space_types", ignore_own=True))
        self._sync_m2m(self.plugin_types, agg_activities("plugin_types", ignore_own=True))
        self._sync_m2m(self.tech_setup_types, agg_activities("tech_setup_types", ignore_own=True))
def reformat_prior_knowledge(apps, schema_editor):
    """
    Converts the HTML <ul> into a json array
    """
    Activity = apps.get_model("curricula", "Activity")  # NOQA
    Lesson = apps.get_model("curricula", "Lesson")  # NOQA

    for activity in Activity.objects.all():
        pk = activity.prior_knowledge or ""
        pk = pk.replace("\n", "")
        new_list = ul_as_list(pk)
        new_list = [x.strip() for x in new_list]
        activity.prior_knowledge = json.dumps([x for x in new_list if x])
        activity.save()

    for lesson in Lesson.objects.all():
        pk = lesson.prior_knowledge or ""
        pk = pk.replace("\n", "")
        new_list = ul_as_list(pk)
        new_list = [x.strip() for x in new_list]
        lesson.prior_knowledge = json.dumps([x for x in new_list if x])
        lesson.save()
Example #3
0
 def get_setup(self, activities=None):
     activities = activities or self.activities.all()
     setup = [ul_as_list(activity.setup) for activity in activities]
     deduped_setup = set(setup)
     return list(deduped_setup)
Example #4
0
 def get_accessibility(self, activities=None):
     if self.is_all_activities(activities):
         return self.accessibility_notes
     accessibility_notes = [ul_as_list(activity.accessibility_notes) for activity in activities]
     deduped_notes = set(accessibility_notes)
     return list(deduped_notes)