Skip to content

Jlc/palm mig/language middleware - #127

Merged
johanseto merged 3 commits into
masterfrom
jlc/palm-mig/language-middleware
Feb 29, 2024
Merged

Jlc/palm mig/language middleware#127
johanseto merged 3 commits into
masterfrom
jlc/palm-mig/language-middleware

Conversation

@johanseto

@johanseto johanseto commented Jan 26, 2024

Copy link
Copy Markdown
Collaborator

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

Comment thread eox_nelp/middleware.py Outdated
from django.conf import settings
from django.http import Http404
from django.http import Http404, parse_cookie
from django.utils.deprecation import MiddlewareMixin

@andrey-canon andrey-canon Feb 29, 2024

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
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

@johanseto johanseto Feb 29, 2024

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

@johanseto johanseto Feb 29, 2024

Copy link
Copy Markdown
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 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
Comment thread eox_nelp/middleware.py
@@ -5,6 +5,8 @@
classes:
ExtendedProfileFieldsMiddleware: Set extended_profile_fields in registration form.

Copy link
Copy Markdown
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
Copy Markdown
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
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