def person(request, slug, active_tab=""): """ Responsible for the person pages """ person = get_object_or_404(Person, slug=slug) links = object_links(person) # we have a home_role, but we should also provide a role, even where it's good enough to give us an address home_role = person.get_role() if home_role: entity = home_role.entity entity = person.get_entity() # don't rely on home_role.entity - could be None or overridden # address = person.get_address() contact = person.get_please_contact() email = contact.email phone = contact.phone_contacts if person.override_entity or person.please_contact: location = None else: location = person.precise_location access_note = person.access_note if home_role: description = ", ".join((home_role.__unicode__(), entity.__unicode__())) request.current_page = entity.get_website() else: description = default_entity.__unicode__() request.current_page = default_entity.get_website() meta = {"description": ": ".join((person.__unicode__(), description))} if entity: template = entity.get_template() else: # no memberships, no useful information print "no memberships, no useful information" template = default_entity.get_template() tabs = [] if "publications" in applications: try: if person.researcher and person.researcher.publishes: tabs.extend(("research", "publications")) except Researcher.DoesNotExist: pass return render_to_response( "contacts_and_people/persondetails" + str(active_tab) + ".html", { "person": person, # personal information "home_role": home_role, # entity and position "entity": entity, "template": template, # from entity # "address": address, # from entity "email": email, # from person or please_contact "location": location, # from person, or None "contact": contact, # from person or please_contact "phone": phone, "access_note": access_note, # from person "tabs": tabs, "active_tab": active_tab, "meta": meta, "links": links, }, RequestContext(request), )
def person(request, slug, active_tab=""): """ Responsible for the person pages """ person = get_object_or_404(Person,slug=slug) person.links = object_links(person) # we have a home_role, but we should also provide a role, even where it's good enough to give us an address home_role = person.get_role() if home_role: entity = home_role.entity entity = person.get_entity # don't rely on home_role.entity - could be None or overridden address = person.get_address() contact = person.get_please_contact() email = contact.email phone = contact.phone_contacts.all() if person.override_entity or person.please_contact: location = None else: location = person.precise_location access_note = person.access_note if home_role: description = ", ".join((home_role.__unicode__(), entity.__unicode__())) request.current_page = entity.get_website else: description = default_entity.__unicode__() request.current_page = default_entity.get_website meta = { "description": ": ".join((person.__unicode__(), description)) } if entity: template = entity.get_template() else: # no memberships, no useful information # print "no memberships, no useful information" template = default_entity.get_template() tabs_dict = { # information for each kind of person tab "default": { "tab": "contact", "title": "Contact information", "address": "", "meta_description_content": person, }, "research": { "tab": "research", "title": "Research", "address": "research", "meta_description_content": unicode(person) + "- research interests", }, "publications": { "tab": "publications", "title": "Publications", "address": "publications", "meta_description_content": unicode(person) + "- publications", }, } # mark the active tab, if there is one if active_tab: tabs_dict[active_tab]["active"] = True # add tabs to the list of tabs tabs = [] tabs.append(tabs_dict["default"]) if 'publications' in applications: try: if person.researcher and person.researcher.publishes: tabs.append(tabs_dict["research"]) tabs.append(tabs_dict["publications"]) except Researcher.DoesNotExist: pass # were there any tabs created? if tabs: if not active_tab: # find out what to add to the url for this tab # print tabs[0] active_tab=tabs[0]["address"] # mark the tab as active for the template tabs[0]["active"]=True # fewer than 2? not worth having tabs! if len(tabs)==1: tabs=[] meta_description_content = tabs_dict[active_tab or "default"]["meta_description_content"] if active_tab: active_tab = "_" + active_tab meta = { "description": meta_description_content, } # there's a problem here - pages such as Cardiff's /person/dr-kathrine-jane-craig/ don't # get the menu right - why? # print "****", request.auto_page_url, request.path, request.current_page, entity.get_website return render_to_response( "contacts_and_people/person%s.html" % active_tab, { "person":person, # personal information "home_role": home_role, # entity and position "entity": entity, "template": template, # from entity "address": address, # from entity "email": email, # from person or please_contact "location": location, # from person, or None "contact": contact, # from person or please_contact "phone": phone, "access_note": access_note, # from person "tabs": tabs, "tab_object": person, "active_tab": active_tab, "meta": meta, # "links": links, }, RequestContext(request), )