Source Code

/ src / blog / context.py

from blog.models import Column
from django.conf import settings

def listed_columns(request):
    """
    Expose non-unlisted columns to templates as CATEGORIES.
    """
    columns = Column.objects.filter(unlisted=False).order_by("name")
    return {
        "LISTED_COLUMNS": columns
    }

def data(request):
    """
    Expose data to templates from settings file
    """
    css_themes = settings.CSS_THEMES
    css_theme_paths = {
        name: f"/static/css/{name}.css"
        for name in css_themes.keys()
    }
    css_theme_labels = {
        name: name.replace("-", " ").title()
        for name in css_themes.keys()
    }
    return {
        "SITE_TITLE": settings.SITE_TITLE,
        "SITE_URL": settings.SITE_URL,
        "SITE_DESCRIP": settings.SITE_DESCRIP,
        "CSS_THEME_PATHS": css_theme_paths,
        "CSS_THEME_LABELS": css_theme_labels,
        "CSS_DEFAULT": settings.CSS_DEFAULT
    }