simplify Device creation
authorStefan Koegl <stefan@skoegl.net>
Sat, 18 Sep 2010 17:48:00 +0000 (18 20:48 +0300)
committerStefan Koegl <stefan@skoegl.net>
Sun, 19 Sep 2010 06:06:07 +0000 (19 09:06 +0300)
mygpo/api/advanced/__init__.py
mygpo/api/advanced/auth.py
mygpo/api/advanced/episode.py
mygpo/api/models/__init__.py
mygpo/api/simple.py

index 9ba67fc..8959251 100644 (file)
@@ -71,7 +71,7 @@ def subscriptions(request, username, device_uid):
         return JsonResponse(changes)
 
     elif request.method == 'POST':
-        d, created = Device.objects.get_or_create(user=request.user, uid=device_uid, defaults = {'type': 'other', 'name': 'New Device'})
+        d, created = Device.objects.get_or_create(user=request.user, uid=device_uid)
 
         if d.deleted:
             d.deleted = False
@@ -260,7 +260,7 @@ def update_episodes(user, actions):
             raise Exception('invalid action %s' % action)
 
         if 'device' in e:
-            device, created = Device.objects.get_or_create(user=user, uid=e['device'], defaults={'name': 'Unknown', 'type': 'other'})
+            device, created = Device.objects.get_or_create(user=user, uid=e['device'])
 
             # undelete a previously deleted device
             if device.deleted:
index cc4136f..814c409 100644 (file)
@@ -35,7 +35,7 @@ def login(request, username, device_uid):
     the device is created if it doesn't already exist
     """
 
-    d, created = Device.objects.get_or_create(user=request.user, uid=device_uid, defaults = {'type': 'other', 'name': _('New Device')})
+    d, created = Device.objects.get_or_create(user=request.user, uid=device_uid)
 
     request.session['device'] = device_uid
     request.session.set_expiry(datetime.now()+timedelta(days=365))
index c8ecc07..70e4ee7 100644 (file)
@@ -131,7 +131,7 @@ def update_chapters(req, user):
 
     device = None
     if 'device' in req:
-        device, c = Device.objects.get_or_create(user=user, uid=req['device'], defaults = {'type': 'other', 'name': _('New Device')})
+        device, c = Device.objects.get_or_create(user=user, uid=req['device'])
 
     timestamp = dateutil.parser.parse(req['timestamp']) if 'timestamp' in req else datetime.now()
 
index 3698026..bd50af5 100644 (file)
@@ -378,8 +378,8 @@ class SyncGroup(models.Model):
 class Device(models.Model):
     user = models.ForeignKey(User)
     uid = models.SlugField(max_length=50)
-    name = models.CharField(max_length=100, blank=True)
-    type = models.CharField(max_length=10, choices=DEVICE_TYPES)
+    name = models.CharField(max_length=100, blank=True, default='Default Device')
+    type = models.CharField(max_length=10, choices=DEVICE_TYPES, default='other')
     sync_group = models.ForeignKey(SyncGroup, blank=True, null=True)
     deleted = models.BooleanField(default=False)
     settings = JSONField(default={})
index b75c971..5db6e62 100644 (file)
@@ -140,8 +140,7 @@ def parse_subscription(raw_post_data, format):
 
 
 def set_subscriptions(urls, user, device_uid):
-    device, created = Device.objects.get_or_create(user=user, uid=device_uid,
-        defaults = {'type': 'other', 'name': device_uid})
+    device, created = Device.objects.get_or_create(user=user, uid=device_uid)
 
     # undelete a previously deleted device
     if device.deleted: