def snapshot(request, pkid): snapshot = get_object_or_404(Snapshot, id=pkid) groups = SubmissionGroup.group(snapshot.submissions) # get snapshots with the same product snapshots = list(Snapshot.snapshots_with_same_product(snapshot.product)) st_len = len(snapshots) first_item = False last_item = False pre_st = None next_st = None current_index = snapshots.index(snapshot) if current_index == 0: first_item = True else: pre_st = snapshots[current_index-1] if current_index == (st_len -1): last_item = True else: next_st = snapshots[current_index+1] return render(request, 'submissions/read/single/snapshot.html', { 'snapshot': snapshot, 'groups': groups, 'pre_st': pre_st, 'next_st': next_st, 'first_item': first_item, 'last_item': last_item, })
def snapshot(request, pkid): snapshot = get_object_or_404(Snapshot, id=pkid) groups = SubmissionGroup.group(snapshot.submissions) # get snapshots with the same product snapshots = list(Snapshot.snapshots_with_same_product(snapshot.product)) st_len = len(snapshots) first_item = False last_item = False pre_st = None next_st = None current_index = snapshots.index(snapshot) if current_index == 0: first_item = True else: pre_st = snapshots[current_index - 1] if current_index == (st_len - 1): last_item = True else: next_st = snapshots[current_index + 1] return render( request, 'submissions/read/single/snapshot.html', { 'snapshot': snapshot, 'groups': groups, 'pre_st': pre_st, 'next_st': next_st, 'first_item': first_item, 'last_item': last_item, })
def snapshot_by_product(request, product_id, offset=0, limit=10): """ if change limit, please also update the value in template: iris/submissions/templates/submissions/read/multiple/snapshots.html """ pro = Product.objects.get(pk=product_id) all_snapshots = Snapshot.snapshots_with_same_product(pro) offset = int(offset) limit = int(limit) end = offset + limit more_data = True if end >= len(all_snapshots): more_data = False snapshots = all_snapshots[offset:end] for snapshot in snapshots: groups = SubmissionGroup.group(snapshot.submissions) snapshot.groups = sorted(groups, key=lambda group: group.name, reverse=True) if request.is_ajax(): response = render( request, 'submissions/read/multiple/snapshot_submissions.html', { 'snapshots': snapshots, 'product': pro, }) response['X-No-More'] = more_data return response else: return render(request, 'submissions/read/multiple/snapshots.html', { 'snapshots': snapshots, 'product': pro, 'more_data': more_data, })
def snapshot_by_product(request, product_id, offset=0, limit=10): """ if change limit, please also update the value in template: iris/submissions/templates/submissions/read/multiple/snapshots.html """ pro = Product.objects.get(pk=product_id) all_snapshots = Snapshot.snapshots_with_same_product(pro) offset = int(offset) limit = int(limit) end = offset + limit more_data = True if end >= len(all_snapshots): more_data = False snapshots = all_snapshots[offset:end] for snapshot in snapshots: groups = SubmissionGroup.group(snapshot.submissions) snapshot.groups = sorted(groups, key=lambda group: group.name, reverse=True) if request.is_ajax(): response = render(request, 'submissions/read/multiple/snapshot_submissions.html', { 'snapshots': snapshots, 'product': pro, }) response['X-No-More'] = more_data return response else: return render(request, 'submissions/read/multiple/snapshots.html', { 'snapshots': snapshots, 'product': pro, 'more_data': more_data, })