2009-05-13 05:14:51 +01:00
from django . shortcuts import render_to_response
from troggle . expo . models import Expedition , Person , PersonExpedition , PersonTrip , LogbookEntry
import troggle . settings as settings
2009-05-13 05:39:52 +01:00
2009-05-13 05:35:59 +01:00
from troggle . parsers . logbooks import LoadLogbookForExpedition
2009-05-13 05:39:52 +01:00
from troggle . parsers . people import GetPersonExpeditionNameLookup
2009-05-13 05:48:10 +01:00
from troggle . expo . forms import PersonForm
2009-05-13 05:39:52 +01:00
2009-05-13 05:52:15 +01:00
# Django uses Context, not RequestContext when you call render_to_response. We always want to use RequestContext, so that django adds the context from settings.TEMPLATE_CONTEXT_PROCESSORS. This way we automatically get necessary settings variables passed to each template. So we use a custom method, render_response instead of render_to_response. Hopefully future Django releases will make this unnecessary.
from troggle . alwaysUseRequestContext import render_response
2009-05-13 05:22:14 +01:00
import search
2009-05-13 05:24:37 +01:00
import re
2009-05-13 05:14:51 +01:00
def personindex ( request ) :
persons = Person . objects . all ( )
2009-05-13 05:52:15 +01:00
# From what I can tell, "persons" seems to be the table rows, while "personss" is the table columns. - AC 16 Feb 09
2009-05-13 05:44:35 +01:00
personss = [ ]
ncols = 5
nc = ( len ( persons ) + ncols - 1 ) / ncols
for i in range ( ncols ) :
personss . append ( persons [ i * nc : ( i + 1 ) * nc ] )
2009-05-13 05:48:47 +01:00
notablepersons = Person . objects . filter ( bisnotable = True )
2009-05-13 05:52:15 +01:00
return render_response ( request , ' personindex.html ' , { ' persons ' : persons , ' personss ' : personss , ' notablepersons ' : notablepersons , } )
2009-05-13 05:14:51 +01:00
2009-05-13 05:35:59 +01:00
def expedition ( request , expeditionname ) :
year = int ( expeditionname )
expedition = Expedition . objects . get ( year = year )
expedition_next = Expedition . objects . filter ( year = year + 1 ) and Expedition . objects . get ( year = year + 1 ) or None
expedition_prev = Expedition . objects . filter ( year = year - 1 ) and Expedition . objects . get ( year = year - 1 ) or None
message = " No message "
if " reload " in request . GET :
message = LoadLogbookForExpedition ( expedition )
2009-05-13 05:39:52 +01:00
#message = str(GetPersonExpeditionNameLookup(expedition).keys())
2009-05-13 05:35:59 +01:00
logbookentries = expedition . logbookentry_set . order_by ( ' date ' )
2009-05-13 05:52:15 +01:00
return render_response ( request , ' expedition.html ' , { ' expedition ' : expedition , ' expedition_next ' : expedition_next , ' expedition_prev ' : expedition_prev , ' logbookentries ' : logbookentries , ' message ' : message , } )
def person ( request , first_name = ' ' , last_name = ' ' ) :
person = Person . objects . get ( first_name = first_name , last_name = last_name )
return render_response ( request , ' person.html ' , { ' person ' : person , } )
def get_absolute_url ( self ) :
return settings . URL_ROOT + self . first_name + ' _ ' + self . last_name
2009-05-13 05:35:59 +01:00
2009-05-13 05:52:15 +01:00
#def person(request, name):
# person = Person.objects.get(href=name)
#
2009-05-13 05:14:51 +01:00
2009-05-13 05:52:15 +01:00
def personexpedition ( request , first_name = ' ' , last_name = ' ' , year = ' ' ) :
person = Person . objects . get ( first_name = first_name , last_name = last_name )
2009-05-13 05:38:18 +01:00
expedition = Expedition . objects . get ( year = year )
personexpedition = person . personexpedition_set . get ( expedition = expedition )
2009-05-13 05:52:15 +01:00
return render_response ( request , ' personexpedition.html ' , { ' personexpedition ' : personexpedition , } )
2009-05-13 05:38:18 +01:00
2009-05-13 05:52:15 +01:00
def logbookentry ( request , logbookentry_pk ) :
logbookentry = LogbookEntry . objects . get ( pk = logbookentry_pk )
return render_response ( request , ' logbookentry.html ' , { ' logbookentry ' : logbookentry , } )
2009-05-13 05:15:49 +01:00
2009-05-13 05:22:14 +01:00
def logbookSearch ( request , extra ) :
query_string = ' '
found_entries = None
if ( ' q ' in request . GET ) and request . GET [ ' q ' ] . strip ( ) :
query_string = request . GET [ ' q ' ]
entry_query = search . get_query ( query_string , [ ' text ' , ' title ' , ] )
found_entries = LogbookEntry . objects . filter ( entry_query )
2009-05-13 05:15:49 +01:00
2009-05-13 05:52:15 +01:00
return render_response ( request , ' logbooksearch.html ' ,
{ ' query_string ' : query_string , ' found_entries ' : found_entries , } )
2009-05-13 05:24:37 +01:00
#context_instance=RequestContext(request))
2009-05-13 05:48:10 +01:00
def personForm ( request , pk ) :
person = Person . objects . get ( pk = pk )
form = PersonForm ( instance = person )
2009-05-13 05:52:15 +01:00
return render_response ( request , ' personform.html ' , { ' form ' : form , } )