--- a/src/iconolab/views/objects.py Fri Dec 16 13:24:55 2016 +0100
+++ b/src/iconolab/views/objects.py Wed Jan 18 14:11:30 2017 +0100
@@ -25,11 +25,12 @@
def get(self, request, *args, **kwargs):
"""
Template is iconolab/home.html
-
+
Context variables provided to the template are:
collections_primary: list of collections to display as big images
collections_secondary: list of collections to display as small links at the bottom
- homepage = True: used to pass checks in the partials/header.html template to adjust the navbar to the homepage
+ homepage = True: used to pass checks in the partials/header.html
+ template to adjust the navbar to the homepage
"""
context = {}
context['collections_primary'] = Collection.objects.filter(show_image_on_home=True).all()
@@ -50,8 +51,10 @@
"""
def check_kwargs(self, kwargs):
'''
- Returns a boolean depending on wether (True) or not (False) the objects were found and a tuple containing the objects, with a select_related/prefetch_related on relevant related objects
- following this ordering: (collection, item, image, annotation, revision)
+ Returns a boolean depending on wether (True) or not (False) the objects
+ were found and a tuple containing the objects, with a select_related/prefetch_related
+ on relevant related objects following this ordering:
+ (collection, item, image, annotation, revision)
'''
objects_tuple = ()
@@ -81,11 +84,11 @@
except (ValueError, AnnotationRevision.DoesNotExist):
return False, RedirectView.as_view(url=reverse('404error'))
return True, objects_tuple
-
+
def get_pagination_data(self, list_to_paginate, page, perpage, adjacent_pages_count, perpage_range=[5, 10, 25, 100], trailing_qarg=""):
"""
Takes a queryset or a list and returns a dict with pagination data for display purposes
-
+
Dict will be of the format:
{
page: the page to load (integer)
@@ -98,7 +101,7 @@
show_last: used in template to display links, will be True if page_count is not in page_range
ellipsis_first: used in template to display links, will be True if page_range starts at 3 or more
ellipsis_last: used in template to display links, will be True if page_range ends at last_page - 2 or less
-
+
}
"""
pagination_data = {}
@@ -122,11 +125,11 @@
pagination_data["ellipsis_first"] = pagination_data["show_first"] and (page - adjacent_pages_count != 2)
pagination_data["show_last"] = page + adjacent_pages_count < paginator.num_pages
pagination_data["ellipsis_last"] = pagination_data["show_last"] and (page + adjacent_pages_count != paginator.num_pages - 1)
- return pagination_data
-
+ return pagination_data
+
class CollectionHomepageView(View, ContextMixin, IconolabObjectView):
"""
- View that displays a collection and four panels to show relevant paginated lists for collection:
+ View that displays a collection and four panels to show relevant paginated lists for collection:
* item lists
* annotations ordered by creation date
* annotations ordered by revisions count
@@ -135,10 +138,10 @@
def get(self, request, *args, **kwargs):
"""
Template is iconolab/collection_home.html
-
- Url args are:
- - collection_name: 'name' attribute of the requested collection
-
+
+ Url args are:
+ - collection_name: 'name' attribute of the requested collection
+
Queryargs understood by the view are:
- show : panel that will be shown on page load, one of ['items', 'recent', 'revised', 'contributions'], default to "items"
- items_page : item list page to load
@@ -149,7 +152,7 @@
- revised_perpage : most revised annotations count per page
- contributions_page : annotations with the most contribution calls list page to load
- contributions_perpage : annotations with the most contribution calls count per page for item list
-
+
Context variables provided to the template are:
- collection: the collection object for the requested collection
- collection_name : the collection_name url arg
@@ -158,7 +161,7 @@
- revised_pagination_data: pagination data dict in the format of the IconolabObjectView.get_pagination_data() method for the revised annotations list
- contributions_pagination_data: pagination data dict in the format of the IconolabObjectView.get_pagination_data() method for the contribution calls annotations list
"""
-
+
success, result = self.check_kwargs(kwargs)
if success:
(collection,) = result
@@ -167,7 +170,7 @@
context = super(CollectionHomepageView, self).get_context_data(**kwargs)
context['collection_name'] = self.kwargs.get('collection_name', '')
context['collection'] = collection
-
+
# get Pagination and navigation query args
try:
items_page = int(request.GET.get('items_page', '1'))
@@ -177,7 +180,7 @@
items_per_page = int(request.GET.get('items_perpage', '12'))
except ValueError:
items_per_page = 12
-
+
try:
recent_page = int(request.GET.get('recent_page', '1'))
except ValueError:
@@ -186,7 +189,7 @@
recent_per_page = int(request.GET.get('recent_perpage', '10'))
except ValueError:
recent_per_page = 10
-
+
try:
revised_page = int(request.GET.get('revised_page', '1'))
except ValueError:
@@ -195,7 +198,7 @@
revised_per_page = int(request.GET.get('revised_perpage', '10'))
except ValueError:
revised_per_page = 10
-
+
try:
contributions_page = int(request.GET.get('contributions_page', '1'))
except ValueError:
@@ -204,22 +207,22 @@
contributions_per_page = int(request.GET.get('contributions_perpage', '10'))
except ValueError:
contributions_per_page = 10
-
+
active_list = request.GET.get('show', 'items')
if active_list not in ['items', 'recent', 'revised', 'contributions']:
active_list = 'items'
context["active_list"] = active_list
-
-
+
+
# Pagination values
adjacent_pages_count = 2
-
+
# Paginated objects list
items_list = collection.items.order_by("metadatas__inventory_number").all()
context["items_pagination_data"] = self.get_pagination_data(
- items_list,
- items_page,
- items_per_page,
+ items_list,
+ items_page,
+ items_per_page,
adjacent_pages_count,
perpage_range=[6, 12, 48, 192],
trailing_qarg="&recent_page="+str(recent_page)
@@ -229,16 +232,16 @@
+"&contributions_page="+str(contributions_page)
+"&contributions_perpage="+str(contributions_per_page)
)
-
+
# Paginated recent annotations list
recent_annotations = Annotation.objects.filter(image__item__collection__name=collection.name).prefetch_related(
'current_revision',
'stats'
).order_by('-current_revision__created')
context["recent_pagination_data"] = self.get_pagination_data(
- recent_annotations,
- recent_page,
- recent_per_page,
+ recent_annotations,
+ recent_page,
+ recent_per_page,
adjacent_pages_count,
trailing_qarg="&items_page="+str(items_page)
+"&items_perpage="+str(items_per_page)
@@ -247,16 +250,16 @@
+"&contributions_page="+str(contributions_page)
+"&contributions_perpage="+str(contributions_per_page)
)
-
+
# Paginated revised annotations list
revised_annotations = Annotation.objects.filter(image__item__collection__name=collection.name).prefetch_related(
'current_revision',
'stats'
).annotate(revision_count=Count('revisions')).order_by('-revision_count')
context["revised_pagination_data"] = self.get_pagination_data(
- revised_annotations,
- revised_page,
- revised_per_page,
+ revised_annotations,
+ revised_page,
+ revised_per_page,
adjacent_pages_count,
trailing_qarg="&items_page="+str(items_page)
+"&items_perpage="+str(items_per_page)
@@ -265,7 +268,7 @@
+"&contributions_page="+str(contributions_page)
+"&contributions_perpage="+str(contributions_per_page)
)
-
+
# Paginated contribution calls annotation list
contrib_calls_annotations_ids = list(set(MetaCategoryInfo.objects.filter(
metacategory__collection__name=collection.name,
@@ -275,9 +278,9 @@
collection_ann_dict = dict([(str(annotation.id), annotation) for annotation in collection_annotations])
contributions_annotations = [collection_ann_dict[id] for id in contrib_calls_annotations_ids]
context["contributions_pagination_data"] = self.get_pagination_data(
- contributions_annotations,
- contributions_page,
- contributions_per_page,
+ contributions_annotations,
+ contributions_page,
+ contributions_per_page,
adjacent_pages_count,
trailing_qarg="&items_page="+str(items_page)
+"&items_perpage="+str(items_per_page)
@@ -286,7 +289,7 @@
+"&revised_page="+str(revised_page)
+"&revised_perpage="+str(revised_per_page)
)
-
+
return render(request, 'iconolab/collection_home.html', context)
@@ -298,16 +301,16 @@
def get(self, request, *args, **kwargs):
"""
Template is iconolab/item_detail.html
-
+
Url args are:
- collection_name : name of the collection
- - item_guid: 'item_guid' attribute of the requested item
-
+ - item_guid: 'item_guid' attribute of the requested item
+
Queryargs understood by the view are:
- show: image_guid for the image to show on load
- page: annotation list page on load for displayed image
- perpage: annotation count per page on load for displayed image
-
+
Context variables provided to the template are:
- collection_name : the collection_name url arg
- item_guid: the item_guid url arg
@@ -320,13 +323,13 @@
'annotations': the list of annotations on that image
}
"""
-
+
success, result = self.check_kwargs(kwargs)
if success:
(collection, item) = result
else:
return result(request)
-
+
context = super(ShowItemView, self).get_context_data(**kwargs)
image_guid_to_display = request.GET.get("show", str(item.images.first().image_guid))
if image_guid_to_display not in [str(guid) for guid in item.images.all().values_list("image_guid", flat=True)]:
@@ -340,7 +343,7 @@
displayed_annotations_per_page = int(request.GET.get('perpage', '10'))
except ValueError:
displayed_annotations_per_page = 10
-
+
context['collection_name'] = self.kwargs.get('collection_name', '')
context['item_guid'] = self.kwargs.get('image_guid', '')
context['collection'] = collection
@@ -359,7 +362,7 @@
except PageNotAnInteger:
annotations = annotations_paginator.page(1)
except EmptyPage:
- annotations = annotations_paginator.page(recent_paginator.num_pages)
+ annotations = annotations_paginator.page(recent_paginator.num_pages)
context['images'].append({
'obj' : image,
'annotations': annotations
@@ -444,10 +447,11 @@
class ShowAnnotationView(View, ContextMixin, IconolabObjectView):
"""
- View that show a given annotation with the corresponding data, links to submit new revisions and the paginated comments thread.
+ View that show a given annotation with the corresponding data, links to
+ submit new revisions and the paginated comments thread.
"""
-
-
+
+
def get_context_data(self, **kwargs):
context = super(ShowAnnotationView, self).get_context_data(**kwargs)
context['collection_name'] = self.kwargs.get('collection_name', '')
@@ -458,23 +462,23 @@
def get(self, request, *args, **kwargs):
"""
Template is iconolab/detail_annotations.html
-
- Url args are:
- - collection_name: 'name' attribute of the requested collection
- - item_guid: 'item_guid' attribute of the requested item
- - annotation_guid: 'annotation_guid' attribute of the requested annotation
-
+
+ Url args are:
+ - collection_name: 'name' attribute of the requested collection
+ - item_guid: 'item_guid' attribute of the requested item
+ - annotation_guid: 'annotation_guid' attribute of the requested annotation
+
Queryargs understood by the view are:
- page: comment thread page on load
- perpage: comment count per page on load
-
+
Context variables provided to the template are:
- collection: the collection object for the requested collection
- image: the image object for the requested image
- annotation: the annotation object for the requested annotation
- tags_data: a json string describing tags for the annotation current revision
- comments: the paginated comments list for the annotation according page and perpage queryargs
- - notification_comments_ids: the ids of the comments that are referenced by a notification for the authenticated user; This allows
+ - notification_comments_ids: the ids of the comments that are referenced by a notification for the authenticated user; This allows
us to highlight comments that triggered a notification in the page
"""
success, result = self.check_kwargs(kwargs)
@@ -535,7 +539,7 @@
def get(self, request, *args, **kwargs):
"""
- Exactly the same as ShowAnnotationView but without all the data around comments
+ Exactly the same as ShowAnnotationView but without all the data around comments
"""
success, result = self.check_kwargs(kwargs)
if success:
@@ -556,7 +560,7 @@
class EditAnnotationView(View, ContextMixin, IconolabObjectView):
"""
- View that handles displaying the edition form and editing an annotation
+ View that handles displaying the edition form and editing an annotation
"""
def get_context_data(self, **kwargs):
context = super(EditAnnotationView, self).get_context_data(**kwargs)
@@ -631,13 +635,13 @@
def get(self, request, *args, **kwargs):
"""
Template is iconolab/detail_annotations.html
-
- Url args are:
- - collection_name: 'name' attribute of the requested collection
- - item_guid: 'item_guid' attribute of the requested item
+
+ Url args are:
+ - collection_name: 'name' attribute of the requested collection
+ - item_guid: 'item_guid' attribute of the requested item
- annotation_guid: 'annotation_guid' attribute of the requested annotation
- revision_guid: 'revision_guid' attribute of the requested revision
-
+
Context variables provided to the template are:
- collection: the collection object for the requested collection
- image: the image object for the requested image