-
-
Notifications
You must be signed in to change notification settings - Fork 90
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
Replace timezone code by Django's built in solution #35
Comments
@anapaulagomes By delete timezone module you mean to delete timezone.py? |
Yes, @dubesar. I just updated the text to make it more explicit. |
@anapaulagomes So basically all the imports of timezone.py in all the other modules have to be replaced and also a single line of django for timezone is to be included. |
I can't tell for sure that these are the only things needed here. Yes, this issue is mainly about replacing the methods from |
@anapaulagomes what I am thinking to do is : from datetime import datetime
try:
from django.conf import settings
from django.utils.timezone import now, utc
except ImportError:
def now():
return datetime.now() with from django.utils import timezone
import datetime
def now():
"""
Returns an aware or naive datetime.datetime, depending on settings.USE_TZ.
"""
if settings.USE_TZ:
# timeit shows that datetime.now(tz=utc) is 24% slower
return datetime.utcnow().replace(tzinfo=utc)
else:
return datetime.now() Remove tz_aware as now is sufficient and also remove smart_datetime Replace : model_bakery/model_bakery/utils.py Line 44 in c2b609f
with series_date = now()+n And there seems to be no change in random_gen.py |
@anapaulagomes If you find these changes correct then ping me so that I can make changes in the repo |
A good way of starting this is making all the changes needed in For the example you've shown, I'd say that just
To test From:
To:
Same goes to Any thoughts here, @amureki? |
And use `django.utils.timezone.now` instead. Refs #35.
And use `django.utils.timezone.now` instead. Refs #35.
* Modify `setup.py` to not import the whole module for package data * mypy to run against lib only * Drop obsolete `model_bakery.timezone.now` And use `django.utils.timezone.now` instead. Refs #35.
* Add a unit test for `utils.seq` Previously, we only tested it within recipe tests. * Update changelog * Fix USE_TZ test * Clean up `model_bakery/timezone.py` (refs #35) - remove `smart_datetime` (replaced by direct `tz_aware` use) - update module docstrings, remove TODO comment * Update changelog
Model Bakery has a module to deal with timezones that was implemented before Django had a built in support for it. We should replace it by the timezone API from Django 1.11.
https://github.com/model-bakers/model_bakery/blob/c2b609f6b065e587cf4a2e4253b518634d4995b3/model_bakery/timezone.py
Expected behavior
This lib should use Django's built in timezone library instead of bakery's
timezone
module.Things I could think of:
smart_datetime
tz_aware
now
utc
timezone
moduleThe text was updated successfully, but these errors were encountered: