Browse Source

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

David Beltra 9 months 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/
31 31
 
32 32
 #local db, must run migrations on production to sync
33 33
 dev.db
34
+data.json
34 35
 
35 36
 #credentials
36 37
 credentials.sh

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

@@ -1,9 +1,15 @@
1 1
 from mezzanine.pages.models import Page
2 2
 
3 3
 def footer(request):
4
-    footer_page = Page.objects.get(id=13)
5
-    return {'footer_page': footer_page}
4
+    if Page.objects.filter(slug='footer').exists():
5
+        footer_page = Page.objects.get(slug='footer')
6
+        return {'footer_page': footer_page}
7
+    else:
8
+        return {'footer_page': None}
6 9
 
7 10
 def navbar(request):
8
-    navbar_page = Page.objects.get(id=11)
9
-    return {'navbar_page': navbar_page}
11
+    if Page.objects.filter(slug='navbar').exists():
12
+        navbar_page = Page.objects.get(slug='navbar')
13
+        return {'navbar_page': navbar_page}
14
+    else:
15
+        return {'navbar_page': None}

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

@@ -54,9 +54,11 @@
54 54
 <div class="navbar navbar-default navbar-fixed-top" role="navigation">
55 55
 <div class="nav-logo">
56 56
 <div class="container">
57
+    {% if navbar_page %}
57 58
     {% editable navbar_page.get_content_model.image  %}
58 59
         <a href="/"><img src="{{ MEDIA_URL }}{{ navbar_page.get_content_model.image}}" alt=""{{navbar_page.title}}></a>
59 60
     {% endeditable %}
61
+    {% endif %}
60 62
 </div>
61 63
 </div>
62 64
 <div class="container">
@@ -116,6 +118,7 @@
116 118
 <footer>
117 119
 <div class="container">
118 120
 <div class="row">
121
+    {% if footer_page %}
119 122
     <div class="col-md-4">
120 123
         {% editable footer_page.get_content_model.text_1  %}
121 124
         {{ footer_page.get_content_model.text_1 | safe }}
@@ -131,6 +134,7 @@
131 134
         {{ footer_page.get_content_model.text_3 | safe }}
132 135
         {% endeditable %}    
133 136
     </div>
137
+    {% endif %}
134 138
 </div>
135 139
 </div>
136 140
 </footer>

Loading…
Cancel
Save