Breadcrumbs on all pages; refactor menus and views

svn: r18334
This commit is contained in:
Doug Blank 2011-10-16 17:00:32 +00:00
parent 9e6bd3c4ba
commit f00b6374a0
18 changed files with 136 additions and 31 deletions

View File

@ -29,8 +29,27 @@
{% block navigation %}
<ul>
<li {{ tview|currentSection:"home" }}><a href="/">Home</a></li>
{% for view in views %}
<li {{tview|currentSection:view.1 }}><a href="/{{view.1}}/">{{view.0}}</a></li>
{% for title in menu %}
{# (<Nice name>, /<path>/, <Model> | None, Need authentication ) #}
{% if title.3 %}
{% if user.is_authenticated %}
<li {{tview|currentSection:title.1 }}>
{% if title.1 %}
<a href="/{{title.1}}/">{{title.0}}</a></li>
{% else %}
<a href="/">{{title.0}}</a></li>
{% endif %}
{% else %}
{# don't show #}
{% endif %}
{% else %}
<li {{tview|currentSection:title.1 }}>
{% if title.1 %}
<a href="/{{title.1}}/">{{title.0}}</a></li>
{% else %}
<a href="/">{{title.0}}</a></li>
{% endif %}
{% endif %}
{% endfor %}
{% if user.is_authenticated %}
{% if next %}

View File

@ -26,8 +26,10 @@ Database information:</p>
</tr>
{% for view in views %}
<tr class="{% cycle odd,even %}">
<td align="left"><a href="/{{view.1}}">{{view.0}}</a></td>
<td align="right"><a href="/{{view.1}}">{{view.2.objects.count|format_number}}</td>
{% if view.2 %}
<td align="left"><a href="/{{view.1}}">{{view.0}}</a></td>
<td align="left"><a href="/{{view.1}}">{{view.2.objects.count|format_number}}</td>
{% endif %}
</tr>
{% endfor %}
</table>

View File

@ -11,6 +11,7 @@
</script>
<div class="content" id="IndividualDetail">
{{ "/browse|Browse,/event|Events"|breadcrumb}}
<div id="summaryarea">
<table class="infolist">
<trbody>

View File

@ -11,6 +11,7 @@
</script>
<div class="content" id="IndividualDetail">
{{ "/browse|Browse,/family|Families"|breadcrumb}}
<h3>{{family.father|make_name:user}} and {{family.mother|make_name:user}}</h3>

View File

@ -10,6 +10,8 @@
});
</script>
{{ "/browse|Browse,/media|Media"|breadcrumb}}
<table>
<tr>
<td>Event type:</td><td> {{event.event_type|escape}}</td><td>Date:</td><td></td>

View File

@ -11,6 +11,9 @@
</script>
<div class="content" id="IndividualDetail">
{{ "/browse|Browse,/person|People,/person/{0}|Person"|breadcrumb:person.handle}}
<h3>{{person|make_name:user}} [{{person.gramps_id}}]</h3>
<div id="summaryarea">
<table class="infolist"> {% comment %} 4 cols {% endcomment %}

View File

@ -11,6 +11,9 @@
</script>
<div class="content" id="IndividualDetail">
{{ "/browse|Browse,/note|Notes"|breadcrumb}}
<div id="summaryarea">
<table class="infolist">
<tbody>

View File

@ -8,6 +8,9 @@
<div id="description" style="padding: 10pt 10pt 10pt 10pt;">
<form name="SearchForm">
{% if tview != "Report" %}
{{ "/browse|Browse"|breadcrumb}}
{% endif %}
<input type="submit" value="Search:"></input>
<input autocomplete="off" name="search" id="get_focus" type="text" size="50" value="{{search}}"></input>
</form>

View File

@ -11,6 +11,9 @@
</script>
<div class="content" id="IndividualDetail">
{{ "/browse|Browse,/person|People"|breadcrumb}}
<h3>{{nameform|render_name:user}} [{{person.gramps_id}}]</h3>
<div id="summaryarea">
<table class="infolist"> {% comment %} 5 cols {% endcomment %}

View File

@ -11,6 +11,9 @@
</script>
<div class="content" id="IndividualDetail">
{{ "/browse|Browse,/place|Places"|breadcrumb}}
<div id="summaryarea">
<table class="infolist">

View File

@ -4,6 +4,9 @@
{% block content %}
<div class="content" id="IndividualDetail">
{{ "/report|Reports"|breadcrumb}}
<div id="summaryarea">
<form name="RunForm" action="/report/{{report.handle}}/run">

View File

@ -11,6 +11,9 @@
</script>
<div class="content" id="IndividualDetail">
{{ "/browse|Browse,/repository|Repositories"|breadcrumb}}
<div id="summaryarea">
<table class="infolist">

View File

@ -12,6 +12,9 @@
<div class="content" id="IndividualDetail">
{{ "/browse|Browse,/source|Sources"|breadcrumb}}
<h3>{{source.title|escape}}</h3>
<div id="summaryarea">
<table class="infolist"> {% comment %} 2 cols {% endcomment %}

View File

@ -11,6 +11,9 @@
</script>
<div class="content" id="IndividualDetail">
{{ "/browse|Browse,/tag|Tags"|breadcrumb}}
<div id="summaryarea">
<table class="infolist">

View File

@ -4,6 +4,7 @@ from django import template
from django.template import escape, Library
from django.utils.safestring import mark_safe
from webapp.utils import *
from webapp.grampsdb.views import VIEWS
import webapp.utils
register = Library()
@ -104,8 +105,29 @@ def missing(data):
missing.is_safe = True
register.filter('missing', missing)
def currentSection(view1, view2):
if view1.strip().lower() == view2.strip().lower():
def getViewName(item):
for view in VIEWS:
if view[1] == item:
return view[0]
if item == "name":
return "Names"
return "Unknown View"
def breadcrumb(path, arg=None):
if arg:
path = path.replace("{0}", arg)
retval = ""
for item in path.split(","):
p, name = item.split("|")
retval += '<a href="%s">%s</a> > ' % (p, name)
return "<p>%s</p>" % retval
breadcrumb.is_safe = True
register.filter('breadcrumb', breadcrumb)
def currentSection(view1, view2): # tview, menu
if view1.strip().lower() in [view[1] for view in VIEWS] and view2 == "browse":
return "class=CurrentSection"
elif view1.strip().lower() == view2.strip().lower():
return "class=CurrentSection"
return ""
currentSection.is_safe = True

View File

@ -52,18 +52,24 @@ import const
_ = lambda text: text
# Menu: (<Nice name>, /<path>/, <Model> | None, Need authentication )
MENU = [
(_('Browse'), 'browse', None, False),
(_('Reports'), 'report', Report, True),
(_('User'), 'user', None, True),
]
# Views: [(<Nice name plural>, /<name>/handle, <Model>), ]
VIEWS = [(_('People'), 'person', Name),
(_('Families'), 'family', Family),
(_('Events'), 'event', Event),
(_('Notes'), 'note', Note),
(_('Media'), 'media', Media),
(_('Sources'), 'source', Source),
(_('Places'), 'place', Place),
(_('Repositories'), 'repository', Repository),
(_('Tags'), 'tag', Tag),
(_('Reports'), 'report', Report),
]
VIEWS = [
(_('People'), 'person', Name),
(_('Families'), 'family', Family),
(_('Events'), 'event', Event),
(_('Notes'), 'note', Note),
(_('Media'), 'media', Media),
(_('Sources'), 'source', Source),
(_('Places'), 'place', Place),
(_('Repositories'), 'repository', Repository),
(_('Tags'), 'tag', Tag),
]
def context_processor(request):
"""
@ -79,6 +85,7 @@ def context_processor(request):
# Other things for all environments:
context["gramps_version"] = const.VERSION
context["views"] = VIEWS
context["menu"] = MENU
context["True"] = True
context["False"] = False
context["default"] = ""
@ -100,16 +107,28 @@ def logout_page(request):
# return redirect(request.GET.get("next"))
return HttpResponseRedirect('/')
def user_page(request, username):
try:
user = User.objects.get(username=username)
except User.DoesNotExist:
raise Http404(_('Requested user not found.'))
def browse_page(request):
context = RequestContext(request)
context["username"] = username
context["view"] = 'user'
context["tview"] = _('User')
return render_to_response('user_page.html', context)
context["view"] = 'browse'
context["tview"] = _('Browse')
return render_to_response('browse_page.html', context)
def user_page(request, username=None):
if request.user.is_authenticated():
if username is None:
profile = request.user.get_profile()
username = profile.user.username
try:
user = User.objects.get(username=username)
except User.DoesNotExist:
raise Http404(_('Requested user not found.'))
context = RequestContext(request)
context["username"] = username
context["view"] = 'user'
context["tview"] = _('User')
return render_to_response('user_page.html', context)
else:
raise Http404(_("Requested page is not accessible."))
def fix_person(request, person):
try:
@ -255,7 +274,7 @@ def process_action(request, view, handle, action):
profile = request.user.get_profile()
report = Report.objects.get(handle=handle)
if action == "run":
args = {"off": "pdf"} # basic defaults
args = {"off": "pdf", "iff": "ged"} # basic defaults
# override from given defaults in table:
if report.options:
for pair in str(report.options).split(" "):
@ -266,7 +285,7 @@ def process_action(request, view, handle, action):
if request.GET.has_key("options"):
options = str(request.GET.get("options"))
if options:
for pair in options.split("%3D"): # from webpage
for pair in options.split(" "): # from webpage
if "=" in pair:
key, value = pair.split("=", 1)
args[key] = value
@ -279,7 +298,9 @@ def process_action(request, view, handle, action):
export_file(db, filename, lambda n: n) # callback
mimetype = 'text/plain'
elif report.report_type == "import":
filename = download(args["i"], "/tmp/%s-%s.ged" % (str(profile.user.username), str(handle)))
filename = download(args["i"], "/tmp/%s-%s.%s" % (str(profile.user.username),
str(handle),
args["iff"]))
if filename is not None:
import threading
def background():
@ -309,7 +330,6 @@ def process_action(request, view, handle, action):
return redirect("/report/")
# If failure, just fail for now:
context = RequestContext(request)
context["tview"] = "Results"
#context["view"] = view
#context["handle"] = handle
#context["action"] = action
@ -321,6 +341,7 @@ def view_detail(request, view, handle, action="view"):
context = RequestContext(request)
context["action"] = action
context["view"] = view
context["tview"] = _('Browse')
if view == "event":
try:
obj = Event.objects.get(handle=handle)

View File

@ -117,6 +117,14 @@ for table, entries in [("grampsdb.config",
("handle", '"ex_gpkg"'),
("options", '"off=gramps"'),
("report_type", '"export"')),
(("name", '"GEDCOM Import"'),
("handle", '"im_ged"'),
("options", '"iff=ged i=http://arborvita.free.fr/Kennedy/Kennedy.ged"'),
("report_type", '"import"')),
(("name", '"Gramps package (portable XML) Import"'),
("handle", '"im_gpkg"'),
("options", '"iff=gramps i=http://gramps.svn.sourceforge.net/viewvc/gramps/trunk/example/gramps/example.gramps?revision=18333"'),
("report_type", '"import"')),
])]:
entry_count = 0
for entry in entries:

View File

@ -40,7 +40,7 @@ admin.autodiscover()
from webapp.grampsdb.views import (main_page, user_page, logout_page,
process_action, view, view_detail,
view_name_detail)
view_name_detail, browse_page)
urlpatterns = patterns('',
# Specific matches first:
@ -63,7 +63,9 @@ urlpatterns += patterns('',
# The rest will match views:
urlpatterns += patterns('',
(r'^$', main_page),
(r'^user/$', user_page),
(r'^user/(\w+)/$', user_page),
(r'^browse/$', browse_page),
(r'^login/$', 'django.contrib.auth.views.login'),
(r'^logout/$', logout_page),
(r'^(?P<view>(\w+))/$', view),