Skip to content

Commit

Permalink
Blacken context_processors.py
Browse files Browse the repository at this point in the history
  • Loading branch information
acdha committed Sep 11, 2018
1 parent d20bba6 commit 37c108f
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions core/context_processors.py
@@ -1,7 +1,7 @@
from django.conf import settings
from django.core.cache import cache

from chronam.core import models, index
from chronam.core import index, models
from chronam.core.forms import _fulltext_range


Expand All @@ -11,12 +11,12 @@ def extra_request_info(request):
"""
fulltext_range = _fulltext_range()
return {
'site_title': 'Chronicling America',
'omniture_url': getattr(settings, "OMNITURE_SCRIPT", None),
'sharetool_url': getattr(settings, "SHARETOOL_URL", None),
'RAVEN_PUBLIC_DSN': getattr(settings, 'RAVEN_PUBLIC_DSN', None),
'fulltext_startdate': fulltext_range[0],
'fulltext_enddate': fulltext_range[1],
"site_title": "Chronicling America",
"omniture_url": getattr(settings, "OMNITURE_SCRIPT", None),
"sharetool_url": getattr(settings, "SHARETOOL_URL", None),
"RAVEN_PUBLIC_DSN": getattr(settings, "RAVEN_PUBLIC_DSN", None),
"fulltext_startdate": fulltext_range[0],
"fulltext_enddate": fulltext_range[1],
}


Expand All @@ -28,10 +28,14 @@ def newspaper_info(request):
titles_with_issues_count = titles_with_issues.count()

_places = models.Place.objects.filter(titles__in=titles_with_issues)
states_with_issues = sorted(set(place.state for place in _places if place.state is not None))
states_with_issues = sorted(
set(place.state for place in _places if place.state is not None)
)

_languages = models.Language.objects.filter(titles__in=titles_with_issues)
languages_with_issues = sorted(set((lang.code, lang.name) for lang in _languages))
languages_with_issues = sorted(
set((lang.code, lang.name) for lang in _languages)
)

# TODO: might make sense to add a Ethnicity.has_issue model field
# to save having to recompute this all the time, eventhough it
Expand All @@ -43,11 +47,13 @@ def newspaper_info(request):
if e.has_issues and e.name not in ["African", "Canadian", "Welsh"]:
ethnicities_with_issues.append(e.name)

info = {'titles_with_issues_count': titles_with_issues_count,
'states_with_issues': states_with_issues,
'languages_with_issues': languages_with_issues,
'ethnicities_with_issues': ethnicities_with_issues,
'total_page_count': total_page_count}
info = {
"titles_with_issues_count": titles_with_issues_count,
"states_with_issues": states_with_issues,
"languages_with_issues": languages_with_issues,
"ethnicities_with_issues": ethnicities_with_issues,
"total_page_count": total_page_count,
}

cache.set("newspaper_info", info, settings.METADATA_TTL_SECONDS)

Expand Down

0 comments on commit 37c108f

Please sign in to comment.