Skip to content

Commit cb07bc4

Browse files
Maffoochclaude
andcommitted
Fix ruff lint errors in template loaders, display tags, and user views
Hoist deferred imports to module scope, replace try/except/pass with contextlib.suppress, and collapse an if/else into a ternary. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 4823c41 commit cb07bc4

3 files changed

Lines changed: 8 additions & 11 deletions

File tree

dojo/template_loaders.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
"""Template loader that selects between the classic and Tailwind UI trees per request.
1+
"""
2+
Template loader that selects between the classic and Tailwind UI trees per request.
23
34
Two parallel template directories are maintained on this branch:
45
@@ -17,6 +18,7 @@
1718
"""
1819

1920
from crum import get_current_request
21+
from django.template import TemplateDoesNotExist
2022
from django.template.loaders.base import Loader as BaseLoader
2123
from django.template.loaders.cached import Loader as CachedLoader
2224
from django.template.loaders.filesystem import Loader as FilesystemLoader
@@ -53,7 +55,6 @@ def _ordered_loaders(self):
5355
return (self._classic_loader, self._tailwind_loader)
5456

5557
def get_template(self, template_name, skip=None):
56-
from django.template import TemplateDoesNotExist
5758
tried = []
5859
for loader in self._ordered_loaders():
5960
try:

dojo/templatetags/display_tags.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from django.conf import settings
1717
from django.contrib.auth.models import User
1818
from django.contrib.contenttypes.models import ContentType
19+
from django.contrib.staticfiles import finders
1920
from django.db.models import Case, IntegerField, Sum, Value, When
2021
from django.template.defaultfilters import stringfilter
2122
from django.urls import reverse
@@ -145,20 +146,18 @@ def dojo_version():
145146

146147
@register.simple_tag
147148
def static_v(static_path):
148-
"""Cache-busting query value for a static asset.
149+
"""
150+
Cache-busting query value for a static asset.
149151
150152
Returns the integer mtime of the file under STATIC_ROOT (or
151153
STATICFILES_DIRS) so any local edit forces a fresh fetch. Falls
152154
back to the dojo version string when the file isn't found, which
153155
is enough granularity for release deploys.
154156
"""
155-
try:
156-
from django.contrib.staticfiles import finders
157+
with contextlib.suppress(Exception):
157158
path = finders.find(static_path)
158159
if path:
159160
return str(int(Path(path).stat().st_mtime))
160-
except Exception:
161-
pass
162161
return __version__.replace(".", "")
163162

164163

dojo/user/views.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,7 @@ def alertcount(request):
236236

237237
def alertcount_text(request):
238238
"""Return alert count as plain text for htmx polling."""
239-
if not settings.DISABLE_ALERT_COUNTER:
240-
count = Alerts.objects.filter(user_id=request.user).count()
241-
else:
242-
count = 0
239+
count = Alerts.objects.filter(user_id=request.user).count() if not settings.DISABLE_ALERT_COUNTER else 0
243240
return HttpResponse(str(count), content_type="text/plain")
244241

245242

0 commit comments

Comments
 (0)