-
Notifications
You must be signed in to change notification settings - Fork 9
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
Migrate Edraak i18n platform #38
Conversation
fedb7a5
to
d347204
Compare
import edraak_i18n.helpers | ||
INSTALLED_APPS += ('edraak_i18n',) | ||
MIDDLEWARE_CLASSES = edraak_i18n.helpers.add_locale_middleware(MIDDLEWARE_CLASSES) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Glad you do 👍
Should be installed *before* any middleware that checks request.META['HTTP_ACCEPT_LANGUAGE'], | ||
specifically django.middleware.locale.LocaleMiddleware | ||
|
||
Although the middleware is installed by default, it sill checks for the feature flag bellow in order to work. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling mistakes:
- bellow is below (line 19)
- the the (line 11)
elif request.path.startswith('/user_api/'): | ||
return True | ||
elif request.path.startswith('/notifier_api/'): | ||
return True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use regex here to reduce lines of code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but I'd like to be very specific and it is more readable for me this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its not generic though, if more urls are introduced in the future that represent api requests, then the decision tree becomes hideous, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not generic, and we'll wait for it to break in the future, we still rely on manual QA for e2e tests.
While the regexp is a valid suggestion, it's not guaranteed to work.
For example edX could add any of these:
/certificate_api/
/xmodule/api/
There's still some guessing and the code won't be future proof anyway, in this case I always fallback to the stupid solution i.e. simple if statement vs. a RegExp.
cms/envs/test.py
Outdated
|
||
# Enable Edraak apps for testing | ||
# Keep it in sync with {lms,cms}/envs/{test,aws}.py | ||
import edraak_i18n.helpers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use from ... import
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually better, to avoid polluting the settings.
updated_middleware.index('edraak_i18n.middleware.DefaultLocaleMiddleware'), | ||
updated_middleware.index('django.middleware.locale.LocaleMiddleware'), | ||
'The i18n middleware should come before the `LocaleMiddleware`', | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is already tested before, no need to repeat again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
first_index = min(indexes) | ||
|
||
# Insert the DefaultLocaleMiddleware any other locale-related middleware in order for it to work | ||
return middleware_classes[:first_index] + (edraak_middleware,) + middleware_classes[first_index:] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do another logic with less complexity, check for the first element, if it is any of the (other_local_middlewares), then add the middleware as the first element, otherwise, make it the second, or you could always add it as the first, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the SessionMiddleware
or the SafeSessionMiddleware
? locale middleware requires one of them to work.
Besides it's much more defensive to write it this way!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But here you are not checking for SessionMiddleware
or any other middleware that Locale middleware depends on, thus defensive programming does not exactly apply here, maybe if there was a function that checks middlewares and rearranges them correctly, what do you think?
d347204
to
d86427f
Compare
All comments have been addressed. Please let me know if you have more. |
@OmarIthawi sounds good, maybe you can add a TODO: write more comprehensive tests |
The edX default setup hates TODOs and the build will fail, so we won't write any TODOs. If you have a suggestion for a specific missing test, please suggest. Otherwise, we'll go with what we have. |
d86427f
to
02ec26c
Compare
@Salomari1987 Let's wait for #39 to get merged so we can get rid off the failing flaky tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update this branch with master
02ec26c
to
0526d78
Compare
@Salomari1987 the tests should pass now. TL;DRI've actually cherry-picked the flaky test fixups here as well. If either one is merged, we'll remove the cherry-picks from the others and rebase. |
@OmarIthawi PR Ratelimit is merged, so you can rebase here and reference me to merge |
0526d78
to
255db86
Compare
Thanks @Salomari1987. Just did. |
b5a6eb8
to
6c66961
Compare
6c66961
to
62cc58f
Compare
@Salomari1987 it passed CI tests. !فرصة تراجعها قبل ما يغير رأيه |
😄 الله يسعدك رفيق |
Task:
Things wasn't migrated: