simplify API device list
authorStefan Koegl <stefan@skoegl.net>
Thu, 16 Sep 2010 17:30:59 +0000 (16 20:30 +0300)
committerStefan Koegl <stefan@skoegl.net>
Thu, 16 Sep 2010 17:30:59 +0000 (16 20:30 +0300)
mygpo/api/advanced/__init__.py

index 58285e8..ef3b45e 100644 (file)
@@ -361,18 +361,21 @@ def valid_episodeaction(type):
 @check_username
 @allowed_methods(['GET'])
 def devices(request, username):
-    devices = []
-    for d in Device.objects.filter(user=request.user, deleted=False):
-        devices.append({
-            'id': d.uid,
-            'caption': d.name,
-            'type': d.type,
-            'subscriptions': Subscription.objects.filter(device=d).count()
-        })
+    devices = Device.objects.filter(user=request.user, deleted=False)
+    devices = map(device_data, devices)
 
     return JsonResponse(devices)
 
 
+def device_data(device):
+    return {
+        'id': d.uid,
+        'caption': d.name,
+        'type': d.type,
+        'subscriptions': Subscription.objects.filter(device=d).count()
+    }
+
+
 @csrf_exempt
 @require_valid_user
 @check_username