Browse Source

Fix templates not to fail when footer or nav don't exist

master
David Beltra 1 year ago
parent
commit
c2a253e7a9
3 changed files with 15 additions and 4 deletions
  1. +1
    -0
      .gitignore
  2. +10
    -4
      apps/pep_theme/context_processors.py
  3. +4
    -0
      apps/pep_theme/templates/base.html

+ 1
- 0
.gitignore View File

@@ -31,6 +31,7 @@ venv.bak/

#local db, must run migrations on production to sync
dev.db
data.json

#credentials
credentials.sh


+ 10
- 4
apps/pep_theme/context_processors.py View File

@@ -1,9 +1,15 @@
from mezzanine.pages.models import Page

def footer(request):
footer_page = Page.objects.get(id=13)
return {'footer_page': footer_page}
if Page.objects.filter(slug='footer').exists():
footer_page = Page.objects.get(slug='footer')
return {'footer_page': footer_page}
else:
return {'footer_page': None}

def navbar(request):
navbar_page = Page.objects.get(id=11)
return {'navbar_page': navbar_page}
if Page.objects.filter(slug='navbar').exists():
navbar_page = Page.objects.get(slug='navbar')
return {'navbar_page': navbar_page}
else:
return {'navbar_page': None}

+ 4
- 0
apps/pep_theme/templates/base.html View File

@@ -54,9 +54,11 @@
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="nav-logo">
<div class="container">
{% if navbar_page %}
{% editable navbar_page.get_content_model.image %}
<a href="/"><img src="{{ MEDIA_URL }}{{ navbar_page.get_content_model.image}}" alt=""{{navbar_page.title}}></a>
{% endeditable %}
{% endif %}
</div>
</div>
<div class="container">
@@ -116,6 +118,7 @@
<footer>
<div class="container">
<div class="row">
{% if footer_page %}
<div class="col-md-4">
{% editable footer_page.get_content_model.text_1 %}
{{ footer_page.get_content_model.text_1 | safe }}
@@ -131,6 +134,7 @@
{{ footer_page.get_content_model.text_3 | safe }}
{% endeditable %}
</div>
{% endif %}
</div>
</div>
</footer>


Loading…
Cancel
Save