from django.views.generic import DetailView
#from django.http import Http404

from devilry.apps.core.models import AssignmentGroup


def get_previous_and_next_group_waiting_for_feedback(examineruser, current_group):
    groups = AssignmentGroup.objects\
        .filter_waiting_for_feedback()\
        .filter_examiner_has_access(examineruser)\
        .filter(parentnode=current_group.parentnode)\
        .order_by('last_deadline__deadline', 'last_delivery__time_of_delivery')
    use_next = False
    next = None
    previous = None
    for group in groups:
        if use_next:
            next = group
            break

        if group == current_group:
            use_next = True
        else:
            previous = group
    return previous, next


class SingleGroupOverview(DetailView):
    template_name = "devilry_examiner/singlegroupoverview.django.html"
    model = AssignmentGroup
    pk_url_kwarg = 'groupid'
    context_object_name = 'group'

    def get_queryset(self):
        return AssignmentGroup.objects.filter_examiner_has_access(self.request.user)

    def get_context_data(self, **kwargs):
        context = super(SingleGroupOverview, self).get_context_data(**kwargs)
        previous, next = get_previous_and_next_group_waiting_for_feedback(
            self.request.user, self.object)
        context['previous_group_waiting_for_feedback'] = previous
        context['next_group_waiting_for_feedback'] = next
        return context
@@ -525,24 +525,80 @@
 ious = None%0A
+    if groups.filter(pk=current_group.pk).exists():%0A    
     for grou
@@ -618,16 +618,20 @@
         
+  
+  
 if use_n
@@ -635,16 +635,20 @@
 e_next:%0A
+    
         
@@ -676,16 +676,20 @@
         
+    
 break%0A%0A 
@@ -691,24 +691,28 @@
 ak%0A%0A        
+ 
+   
 if group == 
@@ -734,24 +734,28 @@
             
+    
 use_next = T
@@ -758,16 +758,20 @@
  = True%0A
+    
         
@@ -780,32 +780,36 @@
 se:%0A            
+    
 previous = group
@@ -805,24 +805,121 @@
 ous = group%0A
+    else:%0A        groups = list(groups)%0A        if len(groups) %3E 0:%0A            next = groups%5B0%5D%0A
     return p

Make todolist show the next