Added context_processor to handle contexts for every template; refer to favion2; some visual polish

svn: r13559
This commit is contained in:
Doug Blank 2009-11-11 16:18:01 +00:00
parent d1340f66fe
commit c142ea4b29
5 changed files with 59 additions and 30 deletions

View File

@ -11,11 +11,11 @@
<meta name="generator" content="GRAMPS 3.2.0-0.SVN12859M http://gramps-project.org/" />
<meta name="author" content="" />
{% endblock %}
<link href="/images/favicon.ico" type="image/x-icon" rel="shortcut icon" />
<link href="/images/favicon2.ico" type="image/x-icon" rel="shortcut icon" />
{% block css %}
<link media="screen" href="/styles/behaviour.css" type="text/css" rel="stylesheet" />
<link media="screen" href="/styles/Web_Alphabet-Horizontal.css" type="text/css" rel="stylesheet" />
<link media="screen" href="/styles/Web_Mainz.css" type="text/css" rel="stylesheet" />
<link media="screen" href="/styles/{{css_theme}}" type="text/css" rel="stylesheet" />
<link media="print" href="/styles/Web_Print-Default.css" type="text/css" rel="stylesheet" />
{% endblock %}
</head>

View File

@ -16,13 +16,19 @@
</p>
<p id="description">
Database information:
<ul>
Database information:</p>
<table class="infolist">
<tr>
<th>Item</th>
<th>Count</th>
</tr>
{% for view in views %}
<li><a href="/{{view.1}}">{{view.0}}</a> ({{view.2}} records)</li>
<tr><td align="left"><a href="/{{view.1}}">{{view.0}}</a></td>
<td align="right"><a href="/{{view.1}}">{{view.2.objects.count}}</td>
</tr>
{% endfor %}
</ul>
</p>
</table>
{% endblock %}

View File

@ -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)

View File

@ -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

View File

@ -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'),
]