rename subscriber.users to subscriber.devices
diff --git a/xos/api/import_methods.py b/xos/api/import_methods.py
index fbcd990..ec07be6 100644
--- a/xos/api/import_methods.py
+++ b/xos/api/import_methods.py
@@ -91,7 +91,10 @@
# Only add an index_view if 1) the is not already an index view, and
# 2) we have found some methods in this directory.
if (not has_index_view) and (urlpatterns):
- urlpatterns.append(url('^' + api_path + '/$', XOSIndexViewSet.as_view({'get': 'list'}, view_urls=view_urls, subdirs=subdirs, api_path=api_path), name=api_path+"_index"))
+ # The browseable API uses the classname as the breadcrumb and page
+ # title, so try to create index views with descriptive classnames
+ viewset = type("IndexOf"+api_path.split("/")[-1].title(), (XOSIndexViewSet,), {})
+ urlpatterns.append(url('^' + api_path + '/$', viewset.as_view({'get': 'list'}, view_urls=view_urls, subdirs=subdirs, api_path=api_path), name=api_path+"_index"))
return urlpatterns
diff --git a/xos/services/cord/models.py b/xos/services/cord/models.py
index c57d9fb..48c9597 100644
--- a/xos/services/cord/models.py
+++ b/xos/services/cord/models.py
@@ -47,7 +47,7 @@
("url_filter_rules", "allow all"),
("url_filter_level", "PG"),
("cdn_enable", False),
- ("users", []),
+ ("devices", []),
("is_demo_user", False),
("uplink_speed", 1000000000), # 1 gigabit, a reasonable default?
@@ -95,58 +95,65 @@
raise Exception("invalid status %s" % value)
self.set_attribute("status", value)
- def find_user(self, uid):
- uid = int(uid)
- for user in self.users:
- if user["id"] == uid:
- return user
+ def find_device(self, mac):
+ for device in self.devices:
+ if device["mac"] == mac:
+ return device
return None
- def update_user(self, uid, **kwargs):
+ def update_device(self, mac, **kwargs):
# kwargs may be "level" or "mac"
# Setting one of these to None will cause None to be stored in the db
- uid = int(uid)
- users = self.users
- for user in users:
- if user["id"] == uid:
+ devices = self.devices
+ for device in devices:
+ if device["mac"] == mac:
for arg in kwargs.keys():
- user[arg] = kwargs[arg]
- self.users = users
- return user
- raise ValueError("User %d not found" % uid)
+ device[arg] = kwargs[arg]
+ self.devices = devices
+ return device
+ raise ValueError("Device with mac %s not found" % mac)
- def create_user(self, **kwargs):
- if "name" not in kwargs:
- raise XOSMissingField("The name field is required")
+ def create_device(self, **kwargs):
+ if "mac" not in kwargs:
+ raise XOSMissingField("The mac field is required")
- for user in self.users:
- if kwargs["name"] == user["name"]:
- raise XOSDuplicateKey("User %s already exists" % kwargs["name"])
+ if self.find_device(kwargs['mac']):
+ raise XOSDuplicateKey("Device with mac %s already exists" % kwargs["mac"])
- uids = [x["id"] for x in self.users]
- if uids:
- uid = max(uids)+1
- else:
- uid = 0
- newuser = kwargs.copy()
- newuser["id"] = uid
+ device = kwargs.copy()
- users = self.users
- users.append(newuser)
- self.users = users
+ devices = self.devices
+ devices.append(device)
+ self.devices = devices
- return newuser
+ return device
- def delete_user(self, uid):
- uid = int(uid)
- users = self.users
- for user in users:
- if user["id"]==uid:
- users.remove(user)
- self.users = users
+ def delete_device(self, mac):
+ devices = self.devices
+ for device in devices:
+ if device["mac"]==mac:
+ devices.remove(device)
+ self.devices = devices
return
- raise ValueError("Users %d not found" % uid)
+ raise ValueError("Device with mac %s not found" % mac)
+
+ #--------------------------------------------------------------------------
+ # Deprecated -- devices used to be called users
+
+ def find_user(self, uid):
+ return self.find_device(uid)
+
+ def update_user(self, uid, **kwargs):
+ return self.update_device(uid, **kwargs)
+
+ def create_user(self, **kwargs):
+ return self.create_device(**kwargs)
+
+ def delete_user(self, uid):
+ return self.delete_user(uid)
+
+ # ------------------------------------------------------------------------
@property
def services(self):
diff --git a/xos/tosca/resources/CORDUser.py b/xos/tosca/resources/CORDUser.py
index 705a895..ff2dc8f 100644
--- a/xos/tosca/resources/CORDUser.py
+++ b/xos/tosca/resources/CORDUser.py
@@ -27,7 +27,7 @@
sub = self.get_subscriber_root(throw_exception=False)
if not sub:
return []
- for user in sub.users:
+ for user in sub.devices:
if user["name"] == self.obj_name:
result.append(user)
return result
@@ -43,7 +43,7 @@
xos_args = self.get_xos_args()
sub = self.get_subscriber_root()
- sub.create_user(**xos_args)
+ sub.create_device(**xos_args)
sub.save()
self.info("Created CORDUser %s for Subscriber %s" % (self.obj_name, sub.name))