Skip to content

Commit

Permalink
style: Minor style adjustments to context processors
Browse files Browse the repository at this point in the history
  • Loading branch information
jag1g13 committed Mar 25, 2020
1 parent 36c4b86 commit 4acfe61
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ backups/
*.log
*.log.*

# Python runtime and setup
# Python runtime, setup and testing
.mypy_cache/
__pycache__
env/
venv/
Expand Down
17 changes: 11 additions & 6 deletions lowfat/context.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
"""Context for template"""
"""Context processors to add data to template context."""
from django.contrib.sites.models import Site
from django.utils import timezone

from constance import config


def site(request): # pylint: disable=unused-argument
# type: (...) -> dict
"""Return the site."""
return {
'site': Site.objects.get_current()
}


def organisation(request): # pylint: disable=unused-argument
# type: (...) -> dict
"""Return the organisation."""
return {
'organisation_name': config.ORGANISATION_NAME,
'organisation_website': config.ORGANISATION_WEBSITE,
}


def maintenance(request): # pylint: disable=unused-argument
"""Return true if default maintancance time."""
# type: (...) -> dict
"""Return whether current time is within scheduled maintenance period."""
now = timezone.now()

if now.weekday() == config.MAINTENANCE_DAY and now.hour == config.MAINTENANCE_HOUR:
return {"is_maintenance_time": True}

return {"is_maintenance_time": False}
return {
'is_maintenance_time': now.weekday() == config.MAINTENANCE_DAY and now.hour == config.MAINTENANCE_HOUR
}

0 comments on commit 4acfe61

Please sign in to comment.