Exemplo n.º 1
0
 def changelist_view(self, request):
     """
     Custom changelist which recreates some of the django changelist but
     with added shiny up and down buttons for reordering the list
     """
     # if someone pressed one of the up or down buttons
     if request.POST and 'action' in request.POST:
         # work out which page we're dealing with
         link_id = request.POST.get('link_id', None)
         link = Link.objects.get(pk = link_id)
         # did we press up or down?
         if 'up' in request.POST['action'].lower():
             # if up then move the page up and output a suitable message
             move_up(link)
             msg='%s moved up.' % link.title
             request.user.message_set.create(message=msg)
         else:
             # if down then move the page down and output a suitable message
             move_down(link)
             msg='%s moved down.' % link.title
             request.user.message_set.create(message=msg)
         return HttpResponseRedirect(request.path)
     # then get back to the django changelist_view
             
     
     return super(LinkAdmin, self).changelist_view(
         request, extra_context = {
             'passed_title': "bob",
         }
     )
Exemplo n.º 2
0
    def test_that_first_item_cant_be_moved_up(self):
        link = self.links[0]

        expected = 1
        actual = link.position
        self.assertEquals(expected,actual,'initial position for second link should be %s, but instead is %s' % (expected,actual))

        move_up(link)

        expected = 1
        actual = link.position
        self.assertEquals(expected,actual,'final position for second link should be %s, but instead is %s' % (expected,actual))        
Exemplo n.º 3
0
    def test_ability_to_move_up(self):
        link = self.links[1]
        
        expected = 2
        actual = link.position
        self.assertEquals(expected,actual,'initial position for second link should be %s, but instead is %s' % (expected,actual))

        move_up(link)

        expected = 1
        actual = link.position
        self.assertEquals(expected,actual,'final position for second link should be %s, but instead is %s' % (expected,actual))