Skip to content

Commit

Permalink
remove deprecated API usage
Browse files Browse the repository at this point in the history
  • Loading branch information
sissbruecker committed Sep 19, 2024
1 parent 3d8866c commit 6cf5fb3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
13 changes: 6 additions & 7 deletions bookmarks/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions bookmarks/tests/test_bookmarks_list_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def assertNotes(self, html: str, notes_html: str, count=1):

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>
Expand Down Expand Up @@ -314,7 +314,7 @@ def inline_bookmark_description_test(self, bookmark):

# 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:
Expand All @@ -331,7 +331,7 @@ def inline_bookmark_description_test(self, bookmark):
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}")

Expand Down Expand Up @@ -400,7 +400,7 @@ def separate_bookmark_description_test(self, bookmark):
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}")

Expand Down
4 changes: 2 additions & 2 deletions bookmarks/tests/test_login_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_should_not_show_oidc_login_by_default(self):
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)

Expand All @@ -24,6 +24,6 @@ def test_should_show_oidc_login_when_enabled(self):
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)
16 changes: 10 additions & 6 deletions bookmarks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re
import unicodedata
import urllib.parse
from datetime import datetime
import datetime
from typing import Optional

from dateutil.relativedelta import relativedelta
Expand Down Expand Up @@ -33,7 +33,9 @@ def unique(elements, key):
}


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)
Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 6cf5fb3

Please sign in to comment.