From 5cf375ae244fefa2754c09228da242a89de6cf6f Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Wed, 25 Apr 2018 10:21:01 +0300 Subject: [PATCH] Add baner template --- apps/content/models.py | 4 ++-- project/context_processors.py | 5 +++++ project/settings.py | 1 + project/templates/blocks/baner.html | 6 ++++++ project/templates/lilcity/index.html | 1 + 5 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 project/templates/blocks/baner.html diff --git a/apps/content/models.py b/apps/content/models.py index 571dfc9e..468058eb 100644 --- a/apps/content/models.py +++ b/apps/content/models.py @@ -127,7 +127,7 @@ class Baner(models.Model): verbose_name_plural = 'Банеры' ordering = ('-created_at',) - def save(*args, **kwargs): + def save(self, *args, **kwargs): if self.use: - Baner.objects.filter(use=true).update(use=False) + Baner.objects.filter(use=True).update(use=False) return super().save(*args, **kwargs) diff --git a/project/context_processors.py b/project/context_processors.py index cf8dc47a..0e7e9d32 100644 --- a/project/context_processors.py +++ b/project/context_processors.py @@ -1,5 +1,10 @@ from apps.config.models import Config +from apps.content.models import Baner def config(request): return {"config": Config.load()} + + +def baner(request): + return {'baner': Baner.objects.filter(use=True).first()} diff --git a/project/settings.py b/project/settings.py index 5889a98b..495e686a 100644 --- a/project/settings.py +++ b/project/settings.py @@ -88,6 +88,7 @@ TEMPLATES = [ 'OPTIONS': { 'context_processors': [ 'project.context_processors.config', + 'project.context_processors.baner', 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', diff --git a/project/templates/blocks/baner.html b/project/templates/blocks/baner.html new file mode 100644 index 00000000..5fd1aef6 --- /dev/null +++ b/project/templates/blocks/baner.html @@ -0,0 +1,6 @@ +{% if baner %} +
+ {{ baner.text }} + {{ baner.button_text }} +
+{% endif %} diff --git a/project/templates/lilcity/index.html b/project/templates/lilcity/index.html index 21032cca..a7269a0e 100644 --- a/project/templates/lilcity/index.html +++ b/project/templates/lilcity/index.html @@ -55,6 +55,7 @@
+ {% include "templates/blocks/baner.html" %} {% include "templates/blocks/header.html" %}
{% block content %}{% endblock content %}