Exemplo n.º 1
0
def collection_detail(request, collection_id):
    collection = get_object_or_404(Collection, pk=collection_id, is_public=True)
    collection_objects = collection.items.filter(public=True
            ).prefetch_related('category', 'country', 'global_region', 'artefactrepresentation_set'
            ).extra(
                select={'public_images_count': 'select count(*) from mediaman_artefactrepresentation a WHERE a.artefact_id = cat_museumobject.id AND a.public'}
                ).order_by('-public_images_count')

    objects = do_paging(request, collection_objects)

    return render(request, 'collections/collection_detail.html',
            {'collection': collection, 'objects': objects})
Exemplo n.º 2
0
def place_detail(request, place_id):
    """
    Lookup a ``Place`` based on its id. Pagination its objects.
    """
    place = get_object_or_404(Place, pk=place_id)
    try:
        region = Region.objects.get(name=place.region)
    except:
        region = None
    place_objects = place.museumobject_set.filter(public=True)

    objects = do_paging(request, place_objects)

    return render(request, "location/place_detail.html",
            {'place': place, 'objects': objects,
             'region': region})
Exemplo n.º 3
0
def person_detail(request, pk, item_type='default', template_name='parties/person_detail.html'):

    person = get_object_or_404(Person, pk=int(pk))

    mapping = {'docs': ('related_documents', 'Related documents', person.related_documents.filter(public=True).count()),
               'created': ('created_items', 'Created items', person.created_items.filter(public=True).count()),
               'collected': ('collected_objects', 'Collected items', person.collected_objects.filter(public=True).count()),
               'donated': ('donated_objects', 'Donated items', person.donated_objects.filter(public=True).count())}

    if item_type == 'default':
        # Select max count type
        item_count = -1
        for k, v in mapping.items():
            if v[2] > item_count:
                item_count = v[2]
                item_type = k

    # output types in correct order
    types = [(key, mapping[key][1], mapping[key][2]) for key in ('docs', 'created', 'collected', 'donated')]

    if item_type in mapping.keys():
        items = getattr(person, mapping[item_type][0]).select_related().filter(public=True
            ).prefetch_related('category', 'country', 'global_region', 'artefactrepresentation_set'
            ).extra(
                select={'public_images_count': 'select count(*) from mediaman_artefactrepresentation a WHERE a.artefact_id = cat_museumobject.id AND a.public'}
                ).order_by('-public_images_count', 'registration_number')

    else:
        items = []

    objects = do_paging(request, items)

    related_documents = person.related_documents.filter(public=True)

    return render(request, template_name, {
        'person': person,
        'objects': objects,
        'related_documents': related_documents,
        'types': types,
        'item_type': item_type,
        'item_name': mapping[item_type][1]
        })
Exemplo n.º 4
0
def item_type_list(request, category=None, item_name=None):
    category = get_object_or_404(Category, slug__exact=category)
    artefact_type = get_object_or_404(ArtefactType, name=item_name)

    breadcrumbs = []
    if category.parent:
        breadcrumbs.append(category.parent)
    breadcrumbs.append(category)

    objects = MuseumObject.objects.select_related().filter(
        category=category, artefact_type=artefact_type, public=True
        ).prefetch_related('category', 'country', 'global_region'
        ).extra(
            select={'public_images_count': 'select count(*) from mediaman_artefactrepresentation a WHERE a.artefact_id = cat_museumobject.id AND a.public'}
            ).order_by('-public_images_count', 'registration_number')

    objects = do_paging(request, objects)

    return render(request, "cat/category_list.html", {
            "breadcrumbs": breadcrumbs,
            "category": artefact_type,
            "objects": objects
        })
Exemplo n.º 5
0
def categories_list(request, full_slug=None, columns=3):
    """
    Hierarchical browsing of categories

    Based on http://djangosnippets.org/snippets/362/
    """
    parent = None
    breadcrumbs = []
    if full_slug:
        slugs = full_slug.split('/')
        for slug in slugs:
            parent = get_object_or_404(Category,
                    parent=parent, slug__exact=slug)
            breadcrumbs.append(parent)

    cat_list = Category.objects.filter(parent=parent)

    ms = parent.museumobject_set.filter(public=True)
    item_types = ArtefactType.objects.filter(
        id__in=ms.values_list('artefact_type', flat=True).distinct())
    # item_types = parent.suggested_artefact_types.all()

    objects = MuseumObject.objects.select_related().filter(category=parent, public=True
        ).prefetch_related('category', 'country', 'global_region'
        ).extra(
            select={'public_images_count': 'select count(*) from mediaman_artefactrepresentation a WHERE a.artefact_id = cat_museumobject.id AND a.public'}
            ).order_by('-public_images_count', 'registration_number') 
    objects = do_paging(request, objects)

    return render(request, "cat/category_list.html", {
            "category": parent,
            "categories": cat_list,
            "objects": objects,
            "breadcrumbs": breadcrumbs[0:-1],
            "num_item_types": len(item_types),
            "item_types": split_list(item_types, parts=columns)})
Exemplo n.º 6
0
def view_geoloc(request, loctype, id, columns=3):

    try:
        geolocation = find_location(loctype, id)
    except ObjectDoesNotExist:
        raise Http404

    items = geolocation.museumobject_set.select_related().filter(public=True
        ).prefetch_related('category', 'country', 'global_region'
        ).extra(
            select={'public_images_count': 'select count(*) from mediaman_artefactrepresentation a WHERE a.artefact_id = cat_museumobject.id AND a.public'}
            ).order_by('-public_images_count', 'registration_number')

    children = []
    if hasattr(geolocation, 'children'):
        children = geolocation.children.all()

    objects = do_paging(request, items)

    return render(request, 'location/geolocation.html',
        {'geolocation': geolocation,
         'objects': objects,
         'num_children': len(children),
         'children': split_list(children, parts=columns)})