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

Migrate Edraak i18n platform #38

Merged
merged 1 commit into from
Mar 27, 2017
Merged

Conversation

OmarIthawi
Copy link
Contributor

@OmarIthawi OmarIthawi commented Feb 22, 2017

Task:

Things wasn't migrated:

@OmarIthawi OmarIthawi changed the title Migrate Edraak i18n platform (WIP) Migrate Edraak i18n platform Feb 22, 2017
@OmarIthawi OmarIthawi force-pushed the omar/migrate-edraak-i18n-module branch from fedb7a5 to d347204 Compare February 26, 2017 08:38
@OmarIthawi OmarIthawi changed the title (WIP) Migrate Edraak i18n platform Migrate Edraak i18n platform Feb 26, 2017
import edraak_i18n.helpers
INSTALLED_APPS += ('edraak_i18n',)
MIDDLEWARE_CLASSES = edraak_i18n.helpers.add_locale_middleware(MIDDLEWARE_CLASSES)

Copy link
Contributor

Choose a reason for hiding this comment

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

I like this

Copy link
Contributor Author

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.
Copy link
Contributor

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

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

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

@OmarIthawi OmarIthawi Mar 6, 2017

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

Choose a reason for hiding this comment

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

use from ... import

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 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`',
)
Copy link
Contributor

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

Copy link
Contributor Author

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:]
Copy link
Contributor

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?

Copy link
Contributor Author

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!

Copy link
Contributor

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?

@OmarIthawi OmarIthawi force-pushed the omar/migrate-edraak-i18n-module branch from d347204 to d86427f Compare March 6, 2017 12:49
@OmarIthawi
Copy link
Contributor Author

All comments have been addressed. Please let me know if you have more.

@Salomari1987
Copy link
Contributor

@OmarIthawi sounds good, maybe you can add a TODO: write more comprehensive tests

@OmarIthawi
Copy link
Contributor Author

OmarIthawi commented Mar 6, 2017

@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.

@OmarIthawi OmarIthawi force-pushed the omar/migrate-edraak-i18n-module branch from d86427f to 02ec26c Compare March 6, 2017 15:17
@OmarIthawi
Copy link
Contributor Author

@Salomari1987 Let's wait for #39 to get merged so we can get rid off the failing flaky tests.

Copy link
Contributor

@Salomari1987 Salomari1987 left a 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

@OmarIthawi OmarIthawi force-pushed the omar/migrate-edraak-i18n-module branch from 02ec26c to 0526d78 Compare March 16, 2017 10:45
@OmarIthawi
Copy link
Contributor Author

@Salomari1987 the tests should pass now.

TL;DR

I'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.

@Salomari1987
Copy link
Contributor

@OmarIthawi PR Ratelimit is merged, so you can rebase here and reference me to merge

@OmarIthawi OmarIthawi force-pushed the omar/migrate-edraak-i18n-module branch from 0526d78 to 255db86 Compare March 18, 2017 15:14
@OmarIthawi
Copy link
Contributor Author

Thanks @Salomari1987. Just did.

@OmarIthawi OmarIthawi force-pushed the omar/migrate-edraak-i18n-module branch 3 times, most recently from b5a6eb8 to 6c66961 Compare March 19, 2017 11:46
@OmarIthawi OmarIthawi force-pushed the omar/migrate-edraak-i18n-module branch from 6c66961 to 62cc58f Compare March 19, 2017 12:40
@OmarIthawi
Copy link
Contributor Author

@Salomari1987 it passed CI tests.

!فرصة تراجعها قبل ما يغير رأيه

@Salomari1987 Salomari1987 merged commit a3c97d7 into master Mar 27, 2017
@OmarIthawi
Copy link
Contributor Author

😄 الله يسعدك رفيق

@OmarIthawi OmarIthawi deleted the omar/migrate-edraak-i18n-module branch August 24, 2017 09:08
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.

2 participants