From c142ea4b299517139ce5205c58e3cd2838af4ce7 Mon Sep 17 00:00:00 2001
From: Doug Blank
Date: Wed, 11 Nov 2009 16:18:01 +0000
Subject: [PATCH] Added context_processor to handle contexts for every
template; refer to favion2; some visual polish
svn: r13559
---
src/data/templates/gramps-base.html | 4 +--
src/data/templates/main_page.html | 16 +++++++---
src/web/djangodb.py | 2 ++
src/web/grampsdb/views.py | 48 +++++++++++++++++++++--------
src/web/settings.py | 19 +++++-------
5 files changed, 59 insertions(+), 30 deletions(-)
diff --git a/src/data/templates/gramps-base.html b/src/data/templates/gramps-base.html
index 8e8745e60..f98fd8292 100644
--- a/src/data/templates/gramps-base.html
+++ b/src/data/templates/gramps-base.html
@@ -11,11 +11,11 @@
{% endblock %}
-
+
{% block css %}
-
+
{% endblock %}
diff --git a/src/data/templates/main_page.html b/src/data/templates/main_page.html
index 2727aaabb..7c763e340 100644
--- a/src/data/templates/main_page.html
+++ b/src/data/templates/main_page.html
@@ -16,13 +16,19 @@
-Database information:
-
+Database information:
+
+
{% endblock %}
diff --git a/src/web/djangodb.py b/src/web/djangodb.py
index 332b71f2c..a4f0edfd3 100644
--- a/src/web/djangodb.py
+++ b/src/web/djangodb.py
@@ -43,6 +43,7 @@ class DjangoDb(GrampsDbBase):
return obj
def get_event_from_handle(self, handle):
+ print "get_event_from_handle:", handle
obj = gen.lib.Event()
obj.unserialize(self.dji.get_event(self.dji.Event.get(handle=handle)))
return obj
@@ -53,6 +54,7 @@ class DjangoDb(GrampsDbBase):
return obj
def get_person_from_handle(self, handle):
+ print "get_person_from_handle:", handle
obj = gen.lib.Person()
data = self.dji.get_person(self.dji.Person.get(handle=handle))
obj.unserialize(data)
diff --git a/src/web/grampsdb/views.py b/src/web/grampsdb/views.py
index a5f007d36..b75d0cfa0 100644
--- a/src/web/grampsdb/views.py
+++ b/src/web/grampsdb/views.py
@@ -10,24 +10,51 @@ from django.db.models import Q
import web
from web.grampsdb.models import *
-from web.settings import VIEWS
-def get_views():
- '''
- VIEWS is [("People", "person"), (plural, singular), ...]
- '''
- return VIEWS
+# Views: [(Nice name plural, /name/handle, Model), ]
+VIEWS = [('People', 'person', Person),
+ ('Families', 'family', Family),
+ ('Events', 'event', Event),
+ ('Notes', 'note', Note),
+ ('Media', 'media', Media),
+ ('Sources', 'source', Source),
+ ('Places', 'place', Place),
+ ('Repositories', 'repository', Repository),
+ ]
+
+def context_processor(request):
+ """
+ This function is executed before template processing.
+ takes a request, and returns a dictionary context.
+ """
+ # FIXME: make the css_theme based on user's selection
+ context = {}
+ context["css_theme"] = "Web_Mainz.css"
+ # FIXME: get the views from a config?
+ context["views"] = VIEWS
+ return context
+
+# CSS Themes:
+#Web_Basic-Ash.css
+#Web_Mainz.css
+#Web_Basic-Cypress.css
+#Web_Nebraska.css
+#Web_Basic-Lilac.css
+#Web_Print-Default.css
+#Web_Basic-Peach.css
+#Web_Visually.css
+#Web_Basic-Spruce.css
def main_page(request):
context = RequestContext(request)
- context["views"] = [(pair[0], pair[1],
- getattr(web.grampsdb.models, pair[2]).objects.count())
- for pair in get_views()]
context["view"] = 'home'
context["cview"] = 'Home'
return render_to_response("main_page.html", context)
def logout_page(request):
+ context = RequestContext(request)
+ context["view"] = 'home'
+ context["cview"] = 'Home'
logout(request)
return HttpResponseRedirect('/')
@@ -38,7 +65,6 @@ def user_page(request, username):
raise Http404('Requested user not found.')
context = RequestContext(request)
context["username"] = username
- context["views"] = get_views()
context["view"] = 'user'
context["cview"] = 'User'
return render_to_response('user_page.html', context)
@@ -46,7 +72,6 @@ def user_page(request, username):
def view_detail(request, view, handle):
cview = view.title()
context = RequestContext(request)
- context["views"] = get_views()
context["cview"] = cview
context["view"] = view
context["handle"] = handle
@@ -118,7 +143,6 @@ def view(request, view):
context = RequestContext(request)
context["page"] = page
- context["views"] = get_views()
context["view"] = view
context["cview"] = cview
context["search"] = search
diff --git a/src/web/settings.py b/src/web/settings.py
index c8ff0a66a..526be41a0 100644
--- a/src/web/settings.py
+++ b/src/web/settings.py
@@ -44,6 +44,14 @@ TEMPLATE_DIRS = (
os.path.join(const.DATA_DIR, "templates"),
)
+TEMPLATE_CONTEXT_PROCESSORS = (
+ "django.core.context_processors.auth",
+ "django.core.context_processors.debug",
+ "django.core.context_processors.i18n",
+ "django.core.context_processors.media",
+ "web.grampsdb.views.context_processor",
+)
+
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
@@ -63,14 +71,3 @@ CACHE_BACKEND = 'locmem://'
TRANSACTIONS_MANAGED = False
LOCALE_PATHS = tuple()
-# Views: (Nice name plural, /name/handle, Model Name)
-VIEWS = [('People', 'person', 'Person'),
- ('Families', 'family', 'Family'),
- ('Events', 'event', 'Event'),
- ('Notes', 'note', 'Note'),
- ('Media', 'media', 'Media'),
- ('Sources', 'source', 'Source'),
- ('Places', 'place', 'Place'),
- ('Repositories', 'repository', 'Repository'),
- ]
-