Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jlc/palm mig/language middleware #127

Merged
merged 3 commits into from
Feb 29, 2024
Merged

Conversation

johanseto
Copy link
Collaborator

@johanseto johanseto commented Jan 26, 2024

Description

Migrate the language per cookie usage from edx-platform to plugin.

This was inspired in the COOKIES manipulation by django.https://github.com/django/django/blob/main/django/core/handlers/wsgi.py#L100-L102

Testing instructions

  1. Checkout you edx-platform to open-release/palm.nelp.

  2. Install eox-nelp using this branch or using editable way.
    eg

pip install git+https://github.com/eduNEXT/eox-nelp.git@jlc/palm-mig/language-middleware --force-reinstall --no-deps
  1. add the middleware in setting using the following config.
index_nelp_lang = MIDDLEWARE.index("openedx.core.djangoapps.lang_pref.middleware.LanguagePreferenceMiddleware") + 1
MIDDLEWARE.insert(index_nelp_lang, "eox_nelp.middleware.PreserveUserLanguageCookieMiddleware")
Screencast.from.26-01-24.17.01.30.webm

Before

Screencast.from.26-01-24.16.54.14.webm

After

Screencast.from.26-01-24.17.02.47.webm

Additional information

PRS related
original-pr with discussion: nelc/edx-platform#5
migration pr: eduNEXT/edunext-platform#672

Checklist for Merge

  • Tested in a remote environment
  • Updated documentation
  • Rebased master/main
  • Squashed commits

@@ -6,7 +6,8 @@
ExtendedProfileFieldsMiddleware: Set extended_profile_fields in registration form.
"""
from django.conf import settings
from django.http import Http404
from django.http import Http404, parse_cookie
from django.utils.deprecation import MiddlewareMixin
Copy link
Collaborator

@andrey-canon andrey-canon Feb 29, 2024

Choose a reason for hiding this comment

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

why are you using deprecation ? it's not better to implement that in the new way ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

IMO that's is not a valid reason, probably that is a old middleware that openedx had to update when they made the django upgrade, however this is a new middleware that you're making from scratch

Copy link
Collaborator Author

@johanseto johanseto Feb 29, 2024

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

image

Some base middleware of django are inheriting from it.

This is the same argument that you exposed in the first comment but with django, my answer is the same those are old middlewares that they made compatible with the new middleware structure
my question would be do you have any reason to use the structure that django deprecated in the past, why do you think the deprecated version is better than the "new" django way ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, but I think that Django makes this middleware-mixin with the idea of being compatible with both ways: MIDDLEWARE AND MIDDLEWARE_CLASSES. So I prefer the compatibility of both ways for the middleware.
image

Copy link
Collaborator

Choose a reason for hiding this comment

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

MIDDLEWARE_CLASSES was deprecated in Django 1.10 and probably you won't find any use of that in later versions

Copy link
Collaborator Author

@johanseto johanseto Feb 29, 2024

Choose a reason for hiding this comment

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

@johanseto johanseto force-pushed the jlc/palm-mig/language-middleware branch from f8f0caa to d47f188 Compare February 29, 2024 20:43
This ensure to use the cookie language if the user send it.
This add the compatiblity for only he new django way of MIDDLEWARE.
@johanseto johanseto force-pushed the jlc/palm-mig/language-middleware branch from d47f188 to 78d7582 Compare February 29, 2024 20:50
@@ -5,6 +5,8 @@
classes:
ExtendedProfileFieldsMiddleware: Set extended_profile_fields in registration form.
Copy link
Collaborator

Choose a reason for hiding this comment

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

could you please add the new middleware here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@johanseto johanseto force-pushed the jlc/palm-mig/language-middleware branch from aab8199 to dbfda6b Compare February 29, 2024 22:09
@johanseto johanseto merged commit 9086711 into master Feb 29, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants