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: elif search.shared == BookmarkSearch.FILTER_SHARED_UNSHARED:
query_set = query_set.filter(shared=False) query_set = query_set.filter(shared=False)
# Sort by date added # Sort
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
if ( if (
search.sort == BookmarkSearch.SORT_TITLE_ASC search.sort == BookmarkSearch.SORT_TITLE_ASC
or search.sort == BookmarkSearch.SORT_TITLE_DESC or search.sort == BookmarkSearch.SORT_TITLE_DESC
@ -124,6 +118,11 @@ def _base_bookmarks_query(
query_set = query_set.order_by(order_field) query_set = query_set.order_by(order_field)
elif search.sort == BookmarkSearch.SORT_TITLE_DESC: elif search.sort == BookmarkSearch.SORT_TITLE_DESC:
query_set = query_set.order_by(order_field).reverse() 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 return query_set

View file

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

View file

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