New template tags; new view_detail function

svn: r13568
This commit is contained in:
Doug Blank 2009-11-13 05:33:38 +00:00
parent eb6f886e66
commit dc7174fd7e
2 changed files with 53 additions and 6 deletions

View File

@ -29,9 +29,11 @@ def display_date(obj):
if date_tuple:
gdate = GDate()
gdate.unserialize(date_tuple)
return _dd(gdate)
return escape(_dd(gdate))
else:
return ""
display_date.is_safe = True
register.filter('display_date', display_date)
def person_get_event(person, event_type):
event_ref_list = dji.get_event_ref_list(person)
@ -48,6 +50,12 @@ def person_get_event(person, event_type):
else:
return ""
def preview(text, width=40):
text = text.replace("\n", " ")
return escape(text[:width])
preview.is_safe = True
register.filter('preview', preview)
def make_name(name, user):
if isinstance(name, models.Name):
surname = name.surname.strip()
@ -71,6 +79,15 @@ def make_name(name, user):
make_name.is_safe = True
register.filter('make_name', make_name)
def preferred(name_set, attr):
name = name_set.get(preferred=True)
if name:
return escape(getattr(name, attr))
else:
return "[Missing]"
preferred.is_safe = True
register.filter('preferred', preferred)
def missing(data):
if data.strip() == "":
return "[Missing]"

View File

@ -70,26 +70,53 @@ def user_page(request, username):
return render_to_response('user_page.html', context)
def view_detail(request, view, handle):
if view == "event":
obj = Event.objects.get(handle=handle)
view_template = 'view_event_detail.html'
elif view == "family":
obj = Family.objects.get(handle=handle)
view_template = 'view_family_detail.html'
elif view == "media":
obj = Media.objects.get(handle=handle)
view_template = 'view_media_detail.html'
elif view == "note":
obj = Note.objects.get(handle=handle)
view_template = 'view_note_detail.html'
elif view == "person":
obj = Person.objects.get(handle=handle)
view_template = 'view_person_detail.html'
elif view == "place":
obj = Place.objects.get(handle=handle)
view_template = 'view_place_detail.html'
elif view == "repository":
obj = Repository.objects.get(handle=handle)
view_template = 'view_repository_detail.html'
elif view == "source":
obj = Source.objects.get(handle=handle)
view_template = 'view_source_detail.html'
cview = view.title()
context = RequestContext(request)
context["cview"] = cview
context["view"] = view
context["handle"] = handle
return render_to_response('view_detail_page.html', context)
context[view] = obj
return render_to_response(view_template, context)
def view(request, view):
cview = view.title()
search = ""
view_template = 'view_page.html'
if view == "event":
object_list = Event.objects.all().order_by("gramps_id")
view_template = 'view_events.html'
elif view == "family":
object_list = Family.objects.all().order_by("gramps_id")
view_template = 'view_family.html'
view_template = 'view_families.html'
elif view == "media":
object_list = Media.objects.all().order_by("gramps_id")
view_template = 'view_media.html'
elif view == "note":
object_list = Note.objects.all().order_by("gramps_id")
view_template = 'view_notes.html'
elif view == "person":
if request.GET.has_key("search"):
search = request.GET.get("search")
@ -121,15 +148,18 @@ def view(request, view):
select_related().filter(surname__istartswith=search).order_by("surname", "first_name")
else:
object_list = Name.objects.select_related().order_by("surname", "first_name")
view_template = 'view_person.html'
view_template = 'view_people.html'
elif view == "place":
object_list = Place.objects.all().order_by("gramps_id")
view_template = 'view_places.html'
elif view == "repository":
object_list = Repository.objects.all().order_by("gramps_id")
view_template = 'view_repositories.html'
elif view == "source":
object_list = Source.objects.all().order_by("gramps_id")
view_template = 'view_sources.html'
paginator = Paginator(object_list, 20)
paginator = Paginator(object_list, 15)
try:
page = int(request.GET.get('page', '1'))