Bladeren bron

Make PinResource orderable by id

Update JavaScript so it orders pins, Fixes #69
tags/v1.0.0
Krzysztof Klimonda 11 jaren geleden
bovenliggende
commit
82352d6980
3 gewijzigde bestanden met toevoegingen van 8 en 2 verwijderingen
  1. +1
    -1
      pinry/api/api.py
  2. +6
    -0
      pinry/api/tests.py
  3. +1
    -1
      pinry/static/js/pinry.js

+ 1
- 1
pinry/api/api.py Bestand weergeven

@@ -80,8 +80,8 @@ class PinResource(ModelResource):

class Meta:
fields = ['id', 'url', 'description']
ordering = ['id']
queryset = Pin.objects.all()
resource_name = 'pin'
include_resource_uri = False
authorization = DjangoAuthorization()
ordering = '-published'

+ 6
- 0
pinry/api/tests.py Bestand weergeven

@@ -85,6 +85,12 @@ class PinResourceTest(ResourceTestCase):
self.assertEqual(Pin.objects.count(), 3)
self.assertEquals(Tag.objects.count(), 4)

def test_get_list_json_ordered(self):
pin = Pin.objects.latest('id')
response = self.api_client.get('/api/v1/pin/', format='json', data={'order_by': '-id'})
self.assertValidJSONResponse(response)
self.assertEqual(self.deserialize(response)['objects'][0]['id'], pin.id)

def test_get_list_json(self):
user = User.objects.get(pk=1)
image = Image.objects.get(pk=1)


+ 1
- 1
pinry/static/js/pinry.js Bestand weergeven

@@ -67,7 +67,7 @@ $(window).load(function() {
$('.spinner').css('display', 'block');

// Fetch our pins from the api using our current offset
var apiUrl = '/api/v1/pin/?format=json&ordering=-id&offset='+String(offset);
var apiUrl = '/api/v1/pin/?format=json&order_by=-id&offset='+String(offset);
if (tagFilter) apiUrl = apiUrl + '&tag=' + tagFilter;
$.get(apiUrl, function(pins) {
// Set which items are editable by the current user


Laden…
Annuleren
Opslaan