remove deprecated API usage

This commit is contained in:
Sascha Ißbrücker 2024-09-19 19:29:01 +02:00
parent 3d8866c7bc
commit 6cf5fb396a
4 changed files with 22 additions and 19 deletions

View file

@ -87,13 +87,7 @@ def _base_bookmarks_query(
elif search.shared == BookmarkSearch.FILTER_SHARED_UNSHARED:
query_set = query_set.filter(shared=False)
# Sort by date added
if search.sort == BookmarkSearch.SORT_ADDED_ASC:
query_set = query_set.order_by("date_added")
elif search.sort == BookmarkSearch.SORT_ADDED_DESC:
query_set = query_set.order_by("-date_added")
# Sort by title
# Sort
if (
search.sort == BookmarkSearch.SORT_TITLE_ASC
or search.sort == BookmarkSearch.SORT_TITLE_DESC
@ -124,6 +118,11 @@ def _base_bookmarks_query(
query_set = query_set.order_by(order_field)
elif search.sort == BookmarkSearch.SORT_TITLE_DESC:
query_set = query_set.order_by(order_field).reverse()
elif search.sort == BookmarkSearch.SORT_ADDED_ASC:
query_set = query_set.order_by("date_added")
else:
# Sort by date added, descending by default
query_set = query_set.order_by("-date_added")
return query_set

View file

@ -210,7 +210,7 @@ class BookmarkListTemplateTest(TestCase, BookmarkFactoryMixin, HtmlTestMixin):
def assertNotesToggle(self, html: str, count=1):
self.assertInHTML(
f"""
"""
<button type="button" class="btn btn-link btn-sm btn-icon toggle-notes">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16">
<use xlink:href="#ld-icon-note"></use>
@ -314,7 +314,7 @@ class BookmarkListTemplateTest(TestCase, BookmarkFactoryMixin, HtmlTestMixin):
# contains description text, without leading/trailing whitespace
if has_description:
description_text = description.find("span", text=bookmark.description)
description_text = description.find("span", string=bookmark.description)
self.assertIsNotNone(description_text)
if not has_tags:
@ -331,7 +331,7 @@ class BookmarkListTemplateTest(TestCase, BookmarkFactoryMixin, HtmlTestMixin):
self.assertEqual(len(tag_links), len(bookmark.tags.all()))
for tag in bookmark.tags.all():
tag_link = tags.find("a", text=f"#{tag.name}")
tag_link = tags.find("a", string=f"#{tag.name}")
self.assertIsNotNone(tag_link)
self.assertEqual(tag_link["href"], f"?q=%23{tag.name}")
@ -400,7 +400,7 @@ class BookmarkListTemplateTest(TestCase, BookmarkFactoryMixin, HtmlTestMixin):
self.assertEqual(len(tag_links), len(bookmark.tags.all()))
for tag in bookmark.tags.all():
tag_link = tags.find("a", text=f"#{tag.name}")
tag_link = tags.find("a", string=f"#{tag.name}")
self.assertIsNotNone(tag_link)
self.assertEqual(tag_link["href"], f"?q=%23{tag.name}")

View file

@ -15,7 +15,7 @@ class LoginViewTestCase(TestCase, HtmlTestMixin):
response = self.client.get("/login/")
soup = self.make_soup(response.content.decode())
oidc_login_link = soup.find("a", text="Login with OIDC")
oidc_login_link = soup.find("a", string="Login with OIDC")
self.assertIsNone(oidc_login_link)
@ -24,6 +24,6 @@ class LoginViewTestCase(TestCase, HtmlTestMixin):
response = self.client.get("/login/")
soup = self.make_soup(response.content.decode())
oidc_login_link = soup.find("a", text="Login with OIDC")
oidc_login_link = soup.find("a", string="Login with OIDC")
self.assertIsNotNone(oidc_login_link)

View file

@ -2,7 +2,7 @@ import logging
import re
import unicodedata
import urllib.parse
from datetime import datetime
import datetime
from typing import Optional
from dateutil.relativedelta import relativedelta
@ -33,7 +33,9 @@ weekday_names = {
}
def humanize_absolute_date(value: datetime, now: Optional[datetime] = None):
def humanize_absolute_date(
value: datetime.datetime, now: Optional[datetime.datetime] = None
):
if not now:
now = timezone.now()
delta = relativedelta(now, value)
@ -51,7 +53,9 @@ def humanize_absolute_date(value: datetime, now: Optional[datetime] = None):
return weekday_names[value.isoweekday()]
def humanize_relative_date(value: datetime, now: Optional[datetime] = None):
def humanize_relative_date(
value: datetime.datetime, now: Optional[datetime.datetime] = None
):
if not now:
now = timezone.now()
delta = relativedelta(now, value)
@ -87,21 +91,21 @@ def parse_timestamp(value: str):
raise ValueError(f"{value} is not a valid timestamp")
try:
return datetime.utcfromtimestamp(timestamp).astimezone()
return datetime.datetime.fromtimestamp(timestamp, datetime.UTC)
except (OverflowError, ValueError, OSError):
pass
# Value exceeds the max. allowed timestamp
# Try parsing as microseconds
try:
return datetime.utcfromtimestamp(timestamp / 1000).astimezone()
return datetime.datetime.fromtimestamp(timestamp / 1000, datetime.UTC)
except (OverflowError, ValueError, OSError):
pass
# Value exceeds the max. allowed timestamp
# Try parsing as nanoseconds
try:
return datetime.utcfromtimestamp(timestamp / 1000000).astimezone()
return datetime.datetime.fromtimestamp(timestamp / 1000000, datetime.UTC)
except (OverflowError, ValueError, OSError):
pass