Repository: uccser/cs-unplugged

Issue:
Add page for ct links
To be added to every unit plan.


Discussion:

Resolving patch:
diff --git a/csunplugged/topics/management/commands/_UnitPlanLoader.py b/csunplugged/topics/management/commands/_UnitPlanLoader.py
--- a/csunplugged/topics/management/commands/_UnitPlanLoader.py
+++ b/csunplugged/topics/management/commands/_UnitPlanLoader.py
@@ -55,11 +55,28 @@ def load(self):
         if unit_plan_content.heading_tree:
             heading_tree = convert_heading_tree_to_dict(unit_plan_content.heading_tree)
 
+        if "computational-thinking-links" in unit_plan_structure:
+            file_name = unit_plan_structure["computational-thinking-links"]
+            file_path = os.path.join(
+                self.BASE_PATH,
+                file_name
+            )
+            ct_links_content = self.convert_md_file(
+                file_path,
+                self.structure_file_path,
+                heading_required=False,
+                remove_title=False,
+            )
+            ct_links = ct_links_content.html_string
+        else:
+            ct_links = None
+
         unit_plan = self.topic.unit_plans.create(
             slug=self.unit_plan_slug,
             name=unit_plan_content.title,
             content=unit_plan_content.html_string,
             heading_tree=heading_tree,
+            computational_thinking_links=ct_links,
         )
         unit_plan.save()
 
diff --git a/csunplugged/topics/migrations/0081_unitplan_computational_thinking_links.py b/csunplugged/topics/migrations/0081_unitplan_computational_thinking_links.py
new file mode 100644
--- /dev/null
+++ b/csunplugged/topics/migrations/0081_unitplan_computational_thinking_links.py
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.2 on 2017-06-19 03:50
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('topics', '0080_auto_20170618_0124'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='unitplan',
+            name='computational_thinking_links',
+            field=models.TextField(null=True),
+        ),
+    ]
diff --git a/csunplugged/topics/models.py b/csunplugged/topics/models.py
--- a/csunplugged/topics/models.py
+++ b/csunplugged/topics/models.py
@@ -109,6 +109,7 @@ class UnitPlan(models.Model):
     slug = models.SlugField()
     name = models.CharField(max_length=100)
     content = models.TextField()
+    computational_thinking_links = models.TextField(null=True)
     heading_tree = JSONField(null=True)
 
     def __str__(self):


Test patch:
diff --git a/csunplugged/tests/topics/loaders/assets/unit_plan/ct-links/ct-links-text.md b/csunplugged/tests/topics/loaders/assets/unit_plan/ct-links/ct-links-text.md
new file mode 100644
--- /dev/null
+++ b/csunplugged/tests/topics/loaders/assets/unit_plan/ct-links/ct-links-text.md
@@ -0,0 +1 @@
+CT link text
diff --git a/csunplugged/tests/topics/loaders/assets/unit_plan/ct-links/ct-links.md b/csunplugged/tests/topics/loaders/assets/unit_plan/ct-links/ct-links.md
new file mode 100644
--- /dev/null
+++ b/csunplugged/tests/topics/loaders/assets/unit_plan/ct-links/ct-links.md
@@ -0,0 +1,3 @@
+# CT Links
+
+Etiam in massa. Nam ut metus.
diff --git a/csunplugged/tests/topics/loaders/assets/unit_plan/ct-links/ct-links.yaml b/csunplugged/tests/topics/loaders/assets/unit_plan/ct-links/ct-links.yaml
new file mode 100644
--- /dev/null
+++ b/csunplugged/tests/topics/loaders/assets/unit_plan/ct-links/ct-links.yaml
@@ -0,0 +1,7 @@
+lessons: lessons/lessons.yaml
+computational-thinking-links: ct-links-text.md
+
+age-groups:
+  8-10:
+    lesson-1:
+      number: 1
diff --git a/csunplugged/tests/topics/loaders/test_unit_plan_loader.py b/csunplugged/tests/topics/loaders/test_unit_plan_loader.py
--- a/csunplugged/tests/topics/loaders/test_unit_plan_loader.py
+++ b/csunplugged/tests/topics/loaders/test_unit_plan_loader.py
@@ -96,6 +96,45 @@ def test_unit_plan_missing_age_groups(self):
             up_loader.load,
         )
 
+    def test_unit_plan_loader_valid_computational_thinking_content(self):
+        config_file = "ct-links/ct-links.yaml"
+
+        factory = Mock()
+        topic = self.test_data.create_topic("1")
+        unit_plan = self.test_data.create_unit_plan(topic, "test")
+        self.test_data.create_lesson(topic, unit_plan, "1")
+        self.test_data.create_age_group(8, 10)
+
+        up_loader = UnitPlanLoader(factory, config_file, topic, self.BASE_PATH)
+        up_loader.load()
+        self.assertEqual(
+            UnitPlan.objects.get(slug="ct-links").computational_thinking_links,
+            "<p>CT link text</p>"
+        )
+
+    def test_unit_plan_loader_missing_computational_thinking_content(self):
+        config_file = "unit-plan-1/unit-plan-1.yaml"
+
+        factory = Mock()
+        topic = self.test_data.create_topic("1")
+        unit_plan = self.test_data.create_unit_plan(topic, "test")
+        self.test_data.create_lesson(topic, unit_plan, "1")
+        self.test_data.create_age_group(8, 10)
+
+        up_loader = UnitPlanLoader(factory, config_file, topic, self.BASE_PATH)
+        up_loader.load()
+
+        up_objects = UnitPlan.objects.all()
+
+        self.assertQuerysetEqual(
+            up_objects,
+            [
+                "<UnitPlan: Unit Plan test>",
+                "<UnitPlan: Unit Plan 1>"
+            ],
+            ordered=False
+        )
+
     def test_unit_plan_missing_lesson_keys(self):
         config_file = "unit-plan-1/missing-lesson-keys.yaml"