예제 #1
0
파일: views.py 프로젝트: airtonix/Arkestra
def place(request, slug, active_tab=""):
    """
    Receives active_tab from the slug.
    
    The template receives "_" + active_tab to identify the correct template (from includes).
    """
    place = Building.objects.get(slug=slug)
    places_dict = {  # information for each kind of place page
        "about": {"title": "About", "address": "", "meta_description_content": place.summary},
        "directions": {
            "title": "Directions etc.",
            "address": "directions",
            "meta_description_content": "How to get to " + place.get_name(),
        },
        "events": {
            "title": "What's on",
            "address": "events",
            "meta_description_content": "What's on at " + place.get_name(),
        },
    }
    # mark the active tab (no active_tab must be "about")
    places_dict[active_tab or "about"]["active"] = True
    tabs = []
    if place.events().forthcoming_events:
        tabs.append(places_dict["events"])
    if (
        place.getting_here
        or place.access_and_parking
        or (place.map and place.zoom and place.latitude and place.longitude)
    ):
        tabs.append(places_dict["directions"])
    # if we're going to show tabs, put the about tab first
    if tabs:
        tabs.insert(0, places_dict["about"])
    meta_description_content = places_dict[active_tab or "about"]["meta_description_content"]
    if active_tab:
        active_tab = "_" + active_tab
    meta = {"description": meta_description_content}
    if default_entity:
        page = default_entity.get_website()
        request.current_page = page
        template = page.get_template()
    else:
        page = entity.get_website()
        request.current_page = page  # for the menu, so it knows where we are
        template = page.get_template()

    return render_to_response(
        "contacts_and_people/place%s.html" % active_tab,
        {"place": place, "tabs": tabs, "active_tab": active_tab, "template": template, "meta": meta},
        RequestContext(request),
    )
예제 #2
0
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),
    )
예제 #3
0
def place(request, slug, active_tab=""):
    """
    Receives active_tab from the slug.
    
    The template receives "_" + active_tab to identify the correct template (from includes).
    """
    place = Building.objects.get(slug=slug)
    places_dict = {  # information for each kind of place page
        "about": {"tab": "about", "title": "About", "address": "", "meta_description_content": place.summary},
        "directions": {
            "tab": "directions",
            "title": "Directions etc.",
            "address": "directions",
            "meta_description_content": "How to get to " + place.get_name(),
        },
        "events": {
            "tab": "events",
            "title": "What's on here",
            "address": "events",
            "meta_description_content": "What's on at " + place.get_name(),
        },
    }

    # mark the active tab, if there is one
    if active_tab:
        places_dict[active_tab]["active"] = True

    # add tabs to the list of tabs
    tabs = []
    if place.postcode or place.street or place.description.cmsplugin_set.all():
        tabs.append(places_dict["about"])
    if place.getting_here.cmsplugin_set.all() or place.access_and_parking.cmsplugin_set.all() or place.has_map:
        tabs.append(places_dict["directions"])
    if place.events().forthcoming_events:
        tabs.append(places_dict["events"])

    # were there any tabs created?
    if tabs:
        if not active_tab:
            # find out what to add to the url for this tab
            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 = places_dict[active_tab or "about"]["meta_description_content"]
    if active_tab:
        active_tab = "_" + active_tab

    meta = {"description": meta_description_content}
    if default_entity:
        page = default_entity.get_website()
        request.current_page = page
        template = page.get_template()
    else:
        page = entity.get_website()
        request.current_page = page  # for the menu, so it knows where we are
        template = page.get_template()

    return render_to_response(
        "contacts_and_people/place%s.html" % active_tab,
        {"place": place, "tabs": tabs, "active_tab": active_tab, "template": template, "meta": meta},
        RequestContext(request),
    )