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

Django4 timezones: Enable & migrate ikhaya article model to DateTime field #1379

Merged
merged 87 commits into from
Jan 19, 2025

Conversation

chris34
Copy link
Member

@chris34 chris34 commented Jan 11, 2025

see CHANGELOG for the points that were changed along the way

  • migrate template changes to the uu theme

based on #1309

chris34 added 30 commits January 8, 2025 22:51
Prevent to make aware timezone objecs naive.
```
/inyoka/inyoka/markup/macros.py:295: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
  self.date = datetime.utcfromtimestamp(int(date))
```
an example

```
inyoka/tests/apps/forum/test_views.py:1824: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
  now_utc = datetime.datetime.utcnow().replace(tzinfo=zoneinfo.ZoneInfo("UTC"), microsecond=0)
```
Explicitly, use `as_div` to remove warning, even if it is the new default.

Warning was

```
inyoka/portal/jinja2/portal/user_edit_groups.html:57:
RemovedInDjango50Warning: The "default.html" templates for forms and
formsets will be removed. These were proxies to the equivalent "table.html"
templates, but the new "div.html" templates will be the default from
Django 5.0. Transitional renderers are provided to allow you to opt-in to
the new output style now.
See https://docs.djangoproject.com/en/4.2/releases/4.1/ for more details
```
Test that very old topcis/posts are not shown.
chris34 added 26 commits January 8, 2025 23:41
It is already enforced by the ORM. If these fields are NULL,
an IntegrityError is raised.
Slugs are always in UTC. Even if the articles display a date of the next day in localtime.
Examples from production:

https://ikhaya.ubuntuusers.de/2006/11/20/eine-kleine-geschichte-ueber-fremde-paketquellen/
https://ikhaya.ubuntuusers.de/2006/06/24/das-webteam-sucht-verstaerkung/
https://ikhaya.ubuntuusers.de/2013/07/30/ubuntuforums-org-wieder-verfuegbar/
https://ikhaya.ubuntuusers.de/2022/09/05/ubuntu-wochenrueckblick-2022-35/
https://ikhaya.ubuntuusers.de/2023/08/28/ubuntu-wochenrueckblick-2023-34/

found with the code snippet
```
for a in Article.objects.all():
    utc_dt = datetime.combine(a.pub_date, a.pub_time, timezone.utc)
    local_dt = utc_dt.astimezone()
    if utc_dt.date() != local_dt.date():
        print(a.id, a.subject, '    ', utc_dt, local_dt)
```
 - define used form fields and their order in python
 - style `.helptext` like `.notes`
   (latter is used for 'old style' forms for the helptext)
…leForm`

The old way lacked a little corner case, when the date in UTC vs
local time was different.

Found via the new written tests for the `EditArticleForm`.
Ideally, `Article.save` could also use this.
However, `find_next_increment` does not allow annotations.
Tests are added to document the behaviour.
Saves a DB query.
For anonymous user the status will be always False.
Only is a hidden performance overhead.
All other locations define an `order_by()` itself.
The margins uses an similar spacing like paragraphs.

Also the specific margin on usercp forms were removed
The following were checked

inyoka/portal/jinja2/portal/group_edit.html
inyoka/portal/jinja2/portal/group_edit_global_permissions.html
inyoka/portal/jinja2/portal/user_edit_groups.html
inyoka/portal/jinja2/portal/usercp/profile.html
inyoka/portal/jinja2/portal/usercp/settings.html
inyoka/portal/jinja2/portal/usercp/subscriptions.html
The forms were the classes were added used a lot of bold.
```
python manage.py squashmigrations ikhaya 0011 0018 --squashed-name article_publication_datetime
```

Old migration files were removed, as no instance should be in in-between state.
Otherwise, the second more likely changes until an answer from the server and parsing the feed was done
chris34 added a commit to chris34/theme-ubuntuusers-pub that referenced this pull request Jan 12, 2025
chris34 added a commit to inyokaproject/theme-ubuntuusers that referenced this pull request Jan 19, 2025
@chris34 chris34 merged commit 6b0dea2 into inyokaproject:staging Jan 19, 2025
21 checks passed
@chris34 chris34 deleted the django4-timezones branch January 19, 2025 21:44
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.

1 participant