Skip to content

Commit

Permalink
Merge pull request #316 from Jenselme/miscs
Browse files Browse the repository at this point in the history
Miscs
  • Loading branch information
Jenselme committed Nov 26, 2024
2 parents 7fc42a1 + 28ae1da commit f962bf7
Show file tree
Hide file tree
Showing 21 changed files with 442 additions and 442 deletions.
16 changes: 8 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ default_language_version:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand Down Expand Up @@ -50,33 +50,33 @@ repos:
- --allow-past-years

- repo: https://github.com/adamchainz/django-upgrade
rev: "1.16.0"
rev: "1.22.1"
hooks:
- id: django-upgrade
args: ["--target-version", "5.0"]

- repo: https://github.com/asottile/pyupgrade
rev: v3.16.0
rev: v3.19.0
hooks:
- id: pyupgrade
args: [--py312-plus]

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.6.9
rev: v0.7.4
hooks:
- id: ruff
args: [--fix, --preview]
- id: ruff-format
args: [--preview]

- repo: https://github.com/seddonym/import-linter
rev: v2.0
rev: v2.1
hooks:
- id: import-linter

- repo: https://github.com/Riverside-Healthcare/djLint
rev: v1.34.1
rev: v1.36.1
hooks:
- id: djlint-reformat-django
- id: djlint-django
Expand All @@ -88,7 +88,7 @@ repos:
args: [-e, SC1091]

- repo: https://github.com/thibaudcolas/pre-commit-stylelint
rev: v16.3.1
rev: v16.10.0
hooks:
- id: stylelint
args: [--fix]
Expand All @@ -97,7 +97,7 @@ repos:
- "[email protected]"

- repo: https://github.com/pre-commit/mirrors-eslint
rev: "v9.12.0"
rev: "v9.15.0"
hooks:
- id: eslint
args: [--fix]
Expand Down
2 changes: 1 addition & 1 deletion config/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ async def application(scope, receive, send):
elif scope["type"] == "websocket":
await websocket_application(scope, receive, send)
else:
raise NotImplementedError(f"Unknown scope type {scope["type"]}")
raise NotImplementedError(f"Unknown scope type {scope['type']}")
3 changes: 2 additions & 1 deletion config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ def before_send_to_sentry(event, hint):
# Don't send any private information. The id is more than enough.
if user := event.get("user"):
user.pop("email", None)
user["username"] = f"user:{user["id"]}"
user["username"] = f"user:{user['id']}"

return event

Expand All @@ -611,3 +611,4 @@ def before_send_to_sentry(event, hint):
# ------------------------------------------------------------------------------
ARTICLE_FETCH_TIMEOUT = env.int("LEGADILO_ARTICLE_FETCH_TIMEOUT", default=50)
RSS_FETCH_TIMEOUT = env.int("LEGADILO_RSS_FETCH_TIMEOUT", default=300)
CONTACT_EMAIL = env.str("LEGADILO_CONTACT_EMAIL", default=None)
1 change: 1 addition & 0 deletions docs/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,5 @@ You can create cryptahpicaly sure secrets in Python with `python3 -c "import sec
| `SENTRY_DSN` | `None` | To enable error monitoring with Sentry (leave empty to leave it deactivated). |
| `LEGADILO_ARTICLE_FETCH_TIMEOUT` | 50 | The fetch timeout when fetching articles in seconds. |
| `LEGADILO_RSS_FETCH_TIMEOUT` | 300 | The fetch timeout when fetching feeds in seconds. |
| `LEGADILO_CONTACT_EMAIL` | `None` | The contact email to display to authenticated user. |

2 changes: 1 addition & 1 deletion legadilo/core/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def check_model_names(*, app_configs, **kwargs):
"Model names should be singular.",
hint=(
"Rename to the singular form, e.g. "
f"“{class_name.removesuffix("s")}”, or mark the "
f"“{class_name.removesuffix('s')}”, or mark the "
f"name as allowed by adding {class_name!r} to "
f"{__name__}.SAFE_MODEL_NAMES."
),
Expand Down
1 change: 1 addition & 0 deletions legadilo/core/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
def provide_global_context(request):
return {
"VERSION": settings.VERSION,
"CONTACT_EMAIL": settings.CONTACT_EMAIL,
}
4 changes: 2 additions & 2 deletions legadilo/feeds/models/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ def _build_refresh_filters( # noqa: C901, PLR0911, PLR0912 too complex
then=True,
)
case feeds_constants.FeedRefreshDelays.EVERY_MORNING:
if 8 <= now.hour <= 12: # noqa: PLR2004 Magic value used in comparison
if 8 <= now.hour <= 10: # noqa: PLR2004 Magic value used in comparison
return models.When(
base_filters & ~models.Q(latest_feed_update__created_at__day=now.day), then=True
)
return models.When(base_filters, then=False)
case feeds_constants.FeedRefreshDelays.DAILY_AT_NOON:
if 11 <= now.hour <= 13: # noqa: PLR2004 Magic value used in comparison
if 12 <= now.hour <= 14: # noqa: PLR2004 Magic value used in comparison
return models.When(
base_filters & ~models.Q(latest_feed_update__created_at__day=now.day), then=True
)
Expand Down
4 changes: 2 additions & 2 deletions legadilo/feeds/services/feed_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ def _find_youtube_rss_feed_link(url: str) -> str:
if match_channel_with_id := re.match(
r"https://[^/]+/channel/(?P<channel_id>.+)", url, re.IGNORECASE
):
return f"https://www.youtube.com/feeds/videos.xml?channel_id={match_channel_with_id.group("channel_id")}"
return f"https://www.youtube.com/feeds/videos.xml?channel_id={match_channel_with_id.group('channel_id')}"

parsed_link = urlparse(url)
params = parse_qs(parsed_link.query)
if params.get("list"):
return f"https://www.youtube.com/feeds/videos.xml?playlist_id={params["list"][0]}"
return f"https://www.youtube.com/feeds/videos.xml?playlist_id={params['list'][0]}"

# Can't handle it. Let's let it through.
return url
Expand Down
26 changes: 13 additions & 13 deletions legadilo/feeds/tests/test_models/test_feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,47 +80,47 @@ def test_for_user(self, user, other_user):

assert list(feeds) == [feed]

@time_machine.travel("2024-05-08 11:00:00")
@time_machine.travel("2024-05-08 10:00:00")
def test_for_update(self, user):
feed_updated_more_than_one_hour_ago = FeedFactory(
title="Updated more than one hour ago",
user=user,
refresh_delay=feeds_constants.FeedRefreshDelays.HOURLY,
)
with time_machine.travel("2024-05-08 10:00:00"):
with time_machine.travel("2024-05-08 09:00:00"):
FeedUpdateFactory(feed=feed_updated_more_than_one_hour_ago)
disabled_feed_updated_more_than_one_hour_ago = FeedFactory(
title="Disabled feed",
user=user,
refresh_delay=feeds_constants.FeedRefreshDelays.HOURLY,
disabled_at=utcnow(),
)
with time_machine.travel("2024-05-08 10:00:00"):
with time_machine.travel("2024-05-08 09:00:00"):
FeedUpdateFactory(feed=disabled_feed_updated_more_than_one_hour_ago)
feed_updated_less_than_one_hour_ago = FeedFactory(
title="Updated less than one hour ago",
user=user,
refresh_delay=feeds_constants.FeedRefreshDelays.HOURLY,
)
with time_machine.travel("2024-05-08 08:30:00"):
with time_machine.travel("2024-05-08 07:30:00"):
FeedUpdateFactory(feed=feed_updated_less_than_one_hour_ago)
with time_machine.travel("2024-05-08 10:30:00"):
with time_machine.travel("2024-05-08 09:30:00"):
FeedUpdateFactory(feed=feed_updated_less_than_one_hour_ago)
feed_updated_this_morning = FeedFactory(
title="Updated this morning",
user=user,
refresh_delay=feeds_constants.FeedRefreshDelays.EVERY_MORNING,
)
with time_machine.travel("2024-05-07 10:00:00"):
with time_machine.travel("2024-05-07 09:00:00"):
FeedUpdateFactory(feed=feed_updated_this_morning)
with time_machine.travel("2024-05-08 10:00:00"):
with time_machine.travel("2024-05-08 09:00:00"):
FeedUpdateFactory(feed=feed_updated_this_morning)
feed_not_yet_updated_this_morning = FeedFactory(
title="Not yet updated this morning",
user=user,
refresh_delay=feeds_constants.FeedRefreshDelays.EVERY_MORNING,
)
with time_machine.travel("2024-05-07 10:00:00"):
with time_machine.travel("2024-05-07 09:00:00"):
FeedUpdateFactory(feed=feed_not_yet_updated_this_morning)

feed_no_feed_update_object = FeedFactory(
Expand All @@ -137,7 +137,7 @@ def test_for_update(self, user):
feed_no_feed_update_object,
]

@time_machine.travel("2024-05-08 11:00:00")
@time_machine.travel("2024-05-08 10:00:00")
def test_for_update_non_utc_user_nothing_to_update(self, user):
user.settings.timezone, _ = Timezone.objects.get_or_create(name="Europe/Paris")
user.settings.save()
Expand All @@ -147,14 +147,14 @@ def test_for_update_non_utc_user_nothing_to_update(self, user):
user=user,
refresh_delay=feeds_constants.FeedRefreshDelays.HOURLY,
)
with time_machine.travel("2024-05-08 10:00:00"):
with time_machine.travel("2024-05-08 09:00:00"):
FeedUpdateFactory(feed=feed_updated_more_than_one_hour_ago)
feed_not_yet_updated_this_morning = FeedFactory(
title="Not yet updated this morning",
user=user,
refresh_delay=feeds_constants.FeedRefreshDelays.EVERY_MORNING,
)
with time_machine.travel("2024-05-07 10:00:00"):
with time_machine.travel("2024-05-07 09:00:00"):
FeedUpdateFactory(feed=feed_not_yet_updated_this_morning)

# Morning feed update time passed in user TZ (but not in UTC).
Expand All @@ -164,7 +164,7 @@ def test_for_update_non_utc_user_nothing_to_update(self, user):
feed_updated_more_than_one_hour_ago,
]

@time_machine.travel("2024-05-08 09:00:00")
@time_machine.travel("2024-05-08 08:00:00")
def test_for_update_non_utc_user(self, user):
user.settings.timezone, _ = Timezone.objects.get_or_create(name="Europe/Paris")
user.settings.save()
Expand All @@ -174,7 +174,7 @@ def test_for_update_non_utc_user(self, user):
user=user,
refresh_delay=feeds_constants.FeedRefreshDelays.EVERY_MORNING,
)
with time_machine.travel("2024-05-07 10:00:00"):
with time_machine.travel("2024-05-07 09:00:00"):
FeedUpdateFactory(feed=feed_not_yet_updated_this_morning)

# Morning feed can be updated in user TZ (although not yet in UTC).
Expand Down
10 changes: 5 additions & 5 deletions legadilo/import_export/management/commands/import_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,21 @@ def add_arguments(self, parser: CommandParser):

def handle(self, *args, **options):
logger.info(
f"Starting import of {options["file_to_import"][0]} with type {options["source_type"]}"
f"Starting import of {options['file_to_import'][0]} with type {options['source_type']}"
)
try:
self._import(options)
except User.DoesNotExist as e:
raise CommandError(f"No user with id {options["user_id"]} was found!") from e
raise CommandError(f"No user with id {options['user_id']} was found!") from e
except JsonSchemaValidationError as e:
logger.debug(str(e))
raise CommandError("The file you supplied is not valid") from e
except FileNotFoundError as e:
raise CommandError(f"{options["file_to_import"][0]} does not exist") from e
raise CommandError(f"{options['file_to_import'][0]} does not exist") from e
except JSONDecodeError as e:
raise CommandError(f"{options["file_to_import"][0]} is not a valid JSON") from e
raise CommandError(f"{options['file_to_import'][0]} is not a valid JSON") from e
except XmlParseError as e:
raise CommandError(f"{options["file_to_import"][0]} is not a valid OPML") from e
raise CommandError(f"{options['file_to_import'][0]} is not a valid OPML") from e
except DataImportError as e:
logger.exception("Failed to import data")
raise CommandError("Failed to import data.") from e
Expand Down
6 changes: 3 additions & 3 deletions legadilo/import_export/services/custom_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ async def _import_feed(user, category, row, feed_url_in_file_to_true_feed):
SSLCertVerificationError,
):
logger.error(
f"Failed to import feed {row["feed_url"]} Created with basic data and disabled."
f"Failed to import feed {row['feed_url']} Created with basic data and disabled."
)
feed_data = build_feed_data(
feed_url=row["feed_url"],
Expand All @@ -168,13 +168,13 @@ async def _import_feed(user, category, row, feed_url_in_file_to_true_feed):
feed_url_in_file_to_true_feed[row["feed_url"]] = feed
return feed, created
except IntegrityError:
logger.info(f"You are already subscribed to {row["feed_url"]}")
logger.info(f"You are already subscribed to {row['feed_url']}")
return None, False


async def _import_article(user, feed, row):
article_data = build_article_data(
external_article_id=f"custom_csv:{row["article_id"]}",
external_article_id=f"custom_csv:{row['article_id']}",
source_title=feed.title if feed else urlparse(row["article_link"]).netloc,
title=row["article_title"],
summary="",
Expand Down
2 changes: 1 addition & 1 deletion legadilo/import_export/services/wallabag.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _import_wallabag_data(user: User, data: list[dict]) -> int:

tags = Tag.objects.get_or_create_from_list(user, raw_article_data.get("tags", []))
article_data = build_article_data(
external_article_id=f"wallabag:{raw_article_data["id"]}",
external_article_id=f"wallabag:{raw_article_data['id']}",
source_title=raw_article_data["domain_name"],
title=raw_article_data["title"],
summary="",
Expand Down
9 changes: 8 additions & 1 deletion legadilo/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,14 @@ <h1 class="modal-title fs-5"></h1>
{% endif %}
</p>
<p class="mb-1">
<a class="text-white" href="https://github.com/Jenselme/legadilo/issues">{% translate "Report a bug" %}</a>
<a class="text-white" href="https://github.com/Jenselme/legadilo/issues">{% translate "Report a bug." %}</a>
{% if CONTACT_EMAIL and user.is_authenticated %}
<span>
{% blocktranslate with email=CONTACT_EMAIL %}
Contact us at <a href="mailto:{{ email }}">{{ email }}</a>
{% endblocktranslate %}
</span>
{% endif %}
</p>
</footer>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ <h1>Confirm E-mail Address</h1>

</p>
<p class="mb-1">
<a class="text-white" href="https://github.com/Jenselme/legadilo/issues">Report a bug</a>
<a class="text-white" href="https://github.com/Jenselme/legadilo/issues">Report a bug.</a>

</p>
</footer>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ <h1>Sign In</h1>

</p>
<p class="mb-1">
<a class="text-white" href="https://github.com/Jenselme/legadilo/issues">Report a bug</a>
<a class="text-white" href="https://github.com/Jenselme/legadilo/issues">Report a bug.</a>

</p>
</footer>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ <h1>Sign In</h1>

</p>
<p class="mb-1">
<a class="text-white" href="https://github.com/Jenselme/legadilo/issues">Report a bug</a>
<a class="text-white" href="https://github.com/Jenselme/legadilo/issues">Report a bug.</a>

</p>
</footer>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,14 @@ <h1>Unread</h1>

</p>
<p class="mb-1">
<a class="text-white" href="https://github.com/Jenselme/legadilo/issues">Report a bug</a>
<a class="text-white" href="https://github.com/Jenselme/legadilo/issues">Report a bug.</a>

<span>

Contact us at <a href="mailto:[email protected]">[email protected]</a>

</span>

</p>
</footer>
</body>
Expand Down
2 changes: 2 additions & 0 deletions legadilo/users/tests/test_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from allauth.account.models import EmailAddress, EmailConfirmationHMAC
from django.contrib.sites.models import Site
from django.core import mail
from django.test import override_settings
from django.urls import reverse

from legadilo.core.middlewares import CSPMiddleware
Expand All @@ -39,6 +40,7 @@ class TestUserRegistration:
user_email = "[email protected]"
password = "tester-password" # noqa: S105 possible hardcoded password.

@override_settings(CONTACT_EMAIL="[email protected]")
def test_registration_success(self, client, utc_tz, mocker, snapshot):
self.client = client
self.mocker = mocker
Expand Down
2 changes: 1 addition & 1 deletion legadilo/utils/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def default(self, obj: Any) -> Any:
return obj.isoformat()

if is_dataclass(obj):
return asdict(obj) # type: ignore[call-overload]
return asdict(obj) # type: ignore[arg-type]

return super().default(obj)

Expand Down
Loading

0 comments on commit f962bf7

Please sign in to comment.