Skip to content

Conversation

@hom3mad3
Copy link
Contributor

@hom3mad3 hom3mad3 commented Mar 24, 2025

Description

This PR introduces the new Learning Nuggets App, which includes the Learning Center. Admins can now add learning categories via Wagtail snippets, and each category can contain individual nuggets.

learning-nuggets-720.mov
  • Learning Center: The Learning Center is a singleton page that can be added under the homepage in Wagtail. It supports custom slugs for each category, which define the category's URL. Each category is linked to custom permissions, allowing content access to be controlled based on roles (Moderator, Initiator, Participant).

  • Video Block: Repurposed a Video Block from the Liquid website and added it to the apps/cms module. This block is now used in the Learning Nuggets to embed videos alongside the learning content, enhancing interactivity and flexibility.

  • AJAX Handling: Added AJAX handling to load sidebar content dynamically without refreshing the page, while still maintaining a traditional SSR fallback in case JavaScript is not supported. The /learning-center page is available under its URL, while the sidebar renders content dynamically from anywhere on the page. By adding AJAX handling, I’m offering an alternative to our current approach of using React for everything. This demonstrates a more sustainable approach, leveraging Django to handle the heavy lifting while still providing dynamic functionality.

  • Modularity: introduced an /assets folder at the app level for better modularity. This is a suggestion for how we should structure our assets moving forward, as it aligns with best practices. We should discuss this further, but I believe it will make managing assets in a more scalable and organized way easier as the app grows.

Still a few things on my list to finish up, but this should give us a solid foundation for testing this feature ✨
Let me know if you have any questions or feedback!

To do

  • Fix urls in config/urls.py to follow the standard organisation convention. (tests are failing)
  • Write tests for rules and views.
  • README.md at the app-level to include documentation for the Learning Nuggets.

Lower prio stuff I didn't get around to doing yet (to be addressed in future PRs?)

  • Implement translations for the Wagtail models.
  • Resolve 404 error on preview page in Wagtail due to URL overwriting with categories.
  • Refactor LearningContentBlock to use StreamField (?) so it looks cleaner and we only show the fields we need.

Tasks

  • PR name contains story or task reference
  • Documentation (docs and inline)
  • Tests (including n+1 and django_assert_num_queries where applicable)
  • Changelog

Notes
@m4ra i was unable to simulate users with moderator and initiator roles locally (i don't think I know well enough about the different permissions and how they get created). In rules.py, I'm calling some predefined rules for organisations and projects, but we definitely need to double check and write a few tests.


@hom3mad3 hom3mad3 changed the title wip wip learning nuggets Mar 24, 2025

class LearningCenterView(ListView):
"""Main learning center page that shows all categories"""
template_name = 'learning_center_index.html'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hom3mad3 @partizipation templates need to be in a directory that follows the app label, and give that path here. See e.g in meinberlin, the templates e.g for the project app, are found under templates/meinberlin_project/, where the name derives from the project label meinberlin + app. For the a+ forks, I guess there was an agreement to call the fork projects as a4_candy

@m4ra m4ra force-pushed the mr-2025-03-learning-nuggets branch from 12809b2 to c4f2f33 Compare March 24, 2025 19:01
Copy link
Contributor

@m4ra m4ra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! I fixed the few missing bits for the tests. I need to run it locally too. Let me know if the error you were getting still persists.

},
bases=("wagtailcore.page",),
),
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hom3mad3 I squashed them in one file, by deleting them all, and recreating them.

@m4ra m4ra force-pushed the mr-2025-03-learning-nuggets branch from c4f2f33 to bf4db85 Compare March 24, 2025 19:21
@hom3mad3 hom3mad3 changed the title wip learning nuggets wip #ST-78 add learning center Mar 27, 2025
@hom3mad3 hom3mad3 changed the title wip #ST-78 add learning center wip [#ST-78] add learning center Mar 27, 2025
@hom3mad3 hom3mad3 changed the title wip [#ST-78] add learning center [#ST-78] add learning center Mar 27, 2025
@hom3mad3 hom3mad3 requested review from arc64 and partizipation March 27, 2025 18:14

# generic patterns at the very end
urlpatterns += [
path('learning-center/', include('apps.learning_nuggets.urls', namespace='learning_nuggets')),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might need to be moved up, however since i'm overwriting the urls of wagtail pages, would need to look into it in more detail and i didn't have the time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends how the URL should be constructed. Should it be below the wagtail'sadmin/ path or below the domain name? If they work as they are, I would leave them for now.

@@ -0,0 +1,11 @@
import rules
Copy link
Contributor Author

@hom3mad3 hom3mad3 Mar 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m4ra kept it simple, we might need to confirm what actually needs to be shown to whom. also couldn't simulate, since I realized don't know how to create users with the respective permissions hehe 🙃

@hom3mad3 hom3mad3 changed the title [#ST-78] add learning center [#ST-78] add learning nuggets app Mar 27, 2025
@hom3mad3 hom3mad3 force-pushed the mr-2025-03-learning-nuggets branch from 20a5963 to 165f59d Compare March 27, 2025 18:44
Copy link
Contributor

@m4ra m4ra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall. Need to check why tests are failing. For the extra test as initiator, did you have a look at projects tests? There are similar tests,


# generic patterns at the very end
urlpatterns += [
path('learning-center/', include('apps.learning_nuggets.urls', namespace='learning_nuggets')),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends how the URL should be constructed. Should it be below the wagtail'sadmin/ path or below the domain name? If they work as they are, I would leave them for now.

description = CharBlock(
max_length=500,
required=False,
help_text="Please insert a short description of the video "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

help text need the translation function _ from gettext_lazy
see e.g here

{% if value.media.url|lower|slice:"-3:" == "mp3" or value.media.url|lower|slice:"-3:" == "wav" %}
<audio controls class="w-full" {% if value.title %}aria-labelledby="media-title"{% endif %} {% if value.description %}aria-describedby="media-description"{% endif %}>
<source src="{{ value.media.url }}" type="audio/{{ value.media.url|lower|slice:"-3:" }}">
<a href="{{ value.media.url }}" class="underline focus:ring-2 focus:ring-blue-500">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you change all the trans to translate? it is the preferred method, and we had changed most of them in other projects.

elif media_file.endswith(".wav"):
return "audio/wav"
else:
return "type invalid"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we have a thorough check for the file type here? to be on the safer side?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, I'll look at this now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added extra file types. I'm wondering if you think it is a good idea to extend the Wagtail document model in order to validate the real content of the file - is this a security concern we have?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated this to have audio/mpeg as this is more correct

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this return "application/octet-stream" instead of type invalid?

title = blocks.CharBlock(
required=True,
max_length=100,
help_text="Enter a clear, concise title for this learning nugget (max 100 characters recommended)",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, and all help_text fields, need the gettext_lazy _
Also the length of the line should be 79 I think, we try to break longer lines in two with the use of brackets. See the example am linking above for this too.

def __call__(self, request):
request.is_ajax = request.headers.get('X-Requested-With') == 'XMLHttpRequest'
response = self.get_response(request)
return response No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noice

@hom3mad3 hom3mad3 force-pushed the mr-2025-03-learning-nuggets branch from 6df7eb1 to 9be14f9 Compare April 17, 2025 10:37
@hom3mad3 hom3mad3 merged commit bda9ac7 into main Apr 17, 2025
2 of 3 checks passed
@hom3mad3 hom3mad3 deleted the mr-2025-03-learning-nuggets branch April 17, 2025 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants