Repository: uccser/cs-unplugged

Issue:
Fix Scratch block notation for 1.1 Display Binary Numbers (without calculations)

Fix Scratch block notation for 1.1 Display Binary Numbers (without calculations)



Discussion:

Resolving patch:
diff --git a/csunplugged/topics/urls.py b/csunplugged/topics/urls.py
--- a/csunplugged/topics/urls.py
+++ b/csunplugged/topics/urls.py
@@ -48,34 +48,28 @@
         views.UnitPlanView.as_view(),
         name='unit_plan'
     ),
-    # eg: /topics/binary-numbers/unit-plan/5-7/lesson-1
+    # eg: /topics/binary-numbers/unit-plan/lesson-1
     url(
-        r'^(?P<topic_slug>[-\w]+)/(?P<unit_plan_slug>[-\w]+)/lesson/(?P<lesson_slug>[-\w]+)/$',
+        r'^(?P<topic_slug>[-\w]+)/(?P<unit_plan_slug>[-\w]+)/(?P<lesson_slug>[-\w]+)/$',
         views.LessonView.as_view(),
         name='lesson'
     ),
-    # eg: /topics/binary-numbers/unit-plan/5-7/lesson-1/plugged-in/
+    # eg: /topics/binary-numbers/unit-plan/lesson-1/plugged-in/
     url(
-        r'^(?P<topic_slug>[-\w]+)/(?P<unit_plan_slug>[-\w]+)/lesson/(?P<lesson_slug>[-\w]+)/plugged-in/$',
+        r'^(?P<topic_slug>[-\w]+)/(?P<unit_plan_slug>[-\w]+)/(?P<lesson_slug>[-\w]+)/plugged-in/$',
         views.ProgrammingExerciseList.as_view(),
         name='programming_exercises_list'
     ),
-    # eg: /topics/binary-numbers/unit-plan/5-7/lesson-1/plugged-in/exercise-1
+    # eg: /topics/binary-numbers/plugged-in/exercise-1
     url(
-        r'^(?P<topic_slug>[-\w]+)/(?P<unit_plan_slug>[-\w]+)/lesson/(?P<lesson_slug>[-\w]+)/plugged-in/(?P<programming_exercise_slug>[-\w]+)$',  # noqa: E501
+        r'^(?P<topic_slug>[-\w]+)/plugged-in/(?P<programming_exercise_slug>[-\w]+)$',  # noqa: E501
         views.ProgrammingExerciseView.as_view(),
         name='programming_exercise'
     ),
-    # eg: /topics/binary-numbers/unit-plan/5-7/lesson-1/plugged-in/exercise-1/python-solution
+    # eg: /topics/binary-numbers/plugged-in/exercise-1/python-solution
     url(
-        r'^(?P<topic_slug>[-\w]+)/(?P<unit_plan_slug>[-\w]+)/lesson/(?P<lesson_slug>[-\w]+)/plugged-in/(?P<programming_exercise_slug>[-\w]+)/(?P<programming_language_slug>[-\w]+)-solution$',  # noqa: E501
+        r'^(?P<topic_slug>[-\w]+)/plugged-in/(?P<programming_exercise_slug>[-\w]+)/(?P<programming_language_slug>[-\w]+)-solution$',  # noqa: E501
         views.ProgrammingExerciseLanguageSolutionView.as_view(),
         name='programming_exercise_language_solution'
     ),
-    # eg: /topics/plugged-in/difficulty/1
-    url(
-        r'^plugged-in/difficulty/(?P<programming_exercise_difficulty_level>[0-9]+)$',
-        views.ProgrammingExerciseDifficultyView.as_view(),
-        name='programming_exercise_difficulty'
-    ),
 ]
diff --git a/csunplugged/topics/views.py b/csunplugged/topics/views.py
--- a/csunplugged/topics/views.py
+++ b/csunplugged/topics/views.py
@@ -11,7 +11,6 @@
     ProgrammingExercise,
     ProgrammingExerciseLanguageImplementation,
     ConnectedGeneratedResource,
-    ProgrammingExerciseDifficulty,
 )
 
 
@@ -143,10 +142,10 @@ def get_context_data(self, **kwargs):
 
 
 class ProgrammingExerciseList(generic.ListView):
-    """View for listing all programming exercises."""
+    """View for listing all programming exercises for a lesson."""
 
     model = ProgrammingExercise
-    template_name = 'topics/programming_exercise_list.html'
+    template_name = 'topics/programming_exercise_lesson_list.html'
     context_object_name = 'all_programming_exercises'
 
     def get_queryset(self, **kwargs):
@@ -205,15 +204,8 @@ def get_context_data(self, **kwargs):
         """
         # Call the base implementation first to get a context
         context = super(ProgrammingExerciseView, self).get_context_data(**kwargs)
-        lesson = get_object_or_404(
-            Lesson.objects.select_related(),
-            topic__slug=self.kwargs.get('topic_slug', None),
-            unit_plan__slug=self.kwargs.get('unit_plan_slug', None),
-            slug=self.kwargs.get('lesson_slug', None),
-        )
-        context['lesson'] = lesson
-        context['unit_plan'] = lesson.unit_plan
-        context['topic'] = lesson.topic
+        context['lessons'] = self.object.lessons.all()
+        context['topic'] = self.object.topic
         # Add all the connected learning outcomes
         context['programming_exercise_learning_outcomes'] = self.object.learning_outcomes.all()
         context['implementations'] = self.object.implementations.all().order_by('-language__name').select_related()
@@ -250,15 +242,7 @@ def get_context_data(self, **kwargs):
         # Call the base implementation first to get a context
         context = super(ProgrammingExerciseLanguageSolutionView, self).get_context_data(**kwargs)
         # Loading object under consistent context names for breadcrumbs
-        lesson = get_object_or_404(
-            Lesson.objects.select_related(),
-            topic__slug=self.kwargs.get('topic_slug', None),
-            unit_plan__slug=self.kwargs.get('unit_plan_slug', None),
-            slug=self.kwargs.get('lesson_slug', None),
-        )
-        context['lesson'] = lesson
-        context['unit_plan'] = lesson.unit_plan
-        context['topic'] = lesson.topic
+        context['topic'] = self.object.topic
         context['programming_exercise'] = self.object.exercise
         return context
 
@@ -353,35 +337,3 @@ class OtherResourcesView(generic.DetailView):
     model = Topic
     template_name = 'topics/topic-other-resources.html'
     slug_url_kwarg = 'topic_slug'
-
-
-class ProgrammingExerciseDifficultyView(generic.DetailView):
-    """View for a specific programming exercise difficulty."""
-
-    model = ProgrammingExerciseDifficulty
-    template_name = 'topics/programming_exercise_difficulty.html'
-    context_object_name = 'difficulty'
-
-    def get_object(self, **kwargs):
-        """Retrieve object for the programming exercise difficulty view.
-
-        Returns:
-            ProgrammingExerciseDifficulty object, or raises 404 error if
-            not found.
-        """
-        return get_object_or_404(
-            self.model,
-            level=self.kwargs.get('programming_exercise_difficulty_level', None)
-        )
-
-    def get_context_data(self, **kwargs):
-        """Provide the context for the programming exercise difficulty view.
-
-        Returns:
-            Dictionary of context data.
-        """
-        # Call the base implementation first to get a context
-        context = super(ProgrammingExerciseDifficultyView, self).get_context_data(**kwargs)
-        # Add in a QuerySet of all the connected programming exercises
-        context['programming_exercises'] = self.object.difficulty_programming_exercises.all()
-        return context


Test patch:
diff --git a/csunplugged/tests/topics/urls/test_lesson.py b/csunplugged/tests/topics/urls/test_lesson.py
--- a/csunplugged/tests/topics/urls/test_lesson.py
+++ b/csunplugged/tests/topics/urls/test_lesson.py
@@ -10,4 +10,4 @@ def __init__(self, *args, **kwargs):
 
     def test_valid_lesson(self):
         url = reverse('topics:lesson', args=['binary-numbers', 'unit-plan', 'lesson-1'])
-        self.assertEqual(url, '/en/topics/binary-numbers/unit-plan/lesson/lesson-1/')
+        self.assertEqual(url, '/en/topics/binary-numbers/unit-plan/lesson-1/')
diff --git a/csunplugged/tests/topics/urls/test_programming_exercise.py b/csunplugged/tests/topics/urls/test_programming_exercise.py
--- a/csunplugged/tests/topics/urls/test_programming_exercise.py
+++ b/csunplugged/tests/topics/urls/test_programming_exercise.py
@@ -9,5 +9,5 @@ def __init__(self, *args, **kwargs):
         self.language = 'en'
 
     def test_valid_programming_exercise(self):
-        url = reverse('topics:programming_exercise', args=['binary-numbers', 'unit-plan', 'lesson-1', 'exercise-1'])
-        self.assertEqual(url, '/en/topics/binary-numbers/unit-plan/lesson/lesson-1/plugged-in/exercise-1')
+        url = reverse('topics:programming_exercise', args=['binary-numbers', 'exercise-1'])
+        self.assertEqual(url, '/en/topics/binary-numbers/plugged-in/exercise-1')
diff --git a/csunplugged/tests/topics/urls/test_programming_exercise_difficulty.py b/csunplugged/tests/topics/urls/test_programming_exercise_difficulty.py
deleted file mode 100644
--- a/csunplugged/tests/topics/urls/test_programming_exercise_difficulty.py
+++ /dev/null
@@ -1,13 +0,0 @@
-from tests.BaseTestWithDB import BaseTestWithDB
-from django.urls import reverse
-
-
-class ProgrammingExerciseDifficultyURLTest(BaseTestWithDB):
-
-    def __init__(self, *args, **kwargs):
-        super().__init__(*args, **kwargs)
-        self.language = 'en'
-
-    def test_valid_programming_exercise_difficulty(self):
-        url = reverse('topics:programming_exercise_difficulty', args=['1'])
-        self.assertEqual(url, '/en/topics/plugged-in/difficulty/1')
diff --git a/csunplugged/tests/topics/urls/test_programming_exercise_language_solution.py b/csunplugged/tests/topics/urls/test_programming_exercise_language_solution.py
--- a/csunplugged/tests/topics/urls/test_programming_exercise_language_solution.py
+++ b/csunplugged/tests/topics/urls/test_programming_exercise_language_solution.py
@@ -9,7 +9,7 @@ def __init__(self, *args, **kwargs):
         self.language = 'en'
 
     def test_valid_programming_exercise_language_solution(self):
-        args = ['binary-numbers', 'unit-plan', 'lesson-1', 'exercise-1', 'python']
+        args = ['binary-numbers', 'exercise-1', 'python']
         url = reverse('topics:programming_exercise_language_solution', args=args)
-        expected_url = '/en/topics/binary-numbers/unit-plan/lesson/lesson-1/plugged-in/exercise-1/python-solution'
+        expected_url = '/en/topics/binary-numbers/plugged-in/exercise-1/python-solution'
         self.assertEqual(url, expected_url)
diff --git a/csunplugged/tests/topics/urls/test_programming_exercises_list.py b/csunplugged/tests/topics/urls/test_programming_exercises_list.py
--- a/csunplugged/tests/topics/urls/test_programming_exercises_list.py
+++ b/csunplugged/tests/topics/urls/test_programming_exercises_list.py
@@ -10,4 +10,4 @@ def __init__(self, *args, **kwargs):
 
     def test_valid_programming_exercises_list(self):
         url = reverse('topics:programming_exercises_list', args=['binary-numbers', 'unit-plan', 'lesson-1'])
-        self.assertEqual(url, '/en/topics/binary-numbers/unit-plan/lesson/lesson-1/plugged-in/')
+        self.assertEqual(url, '/en/topics/binary-numbers/unit-plan/lesson-1/plugged-in/')