diff --git a/server/src/uds/REST/methods/authenticators.py b/server/src/uds/REST/methods/authenticators.py index a3c2842a9..828439760 100644 --- a/server/src/uds/REST/methods/authenticators.py +++ b/server/src/uds/REST/methods/authenticators.py @@ -68,6 +68,8 @@ class Types(ModelTypeHandlerMixin, Handler): class TableInfo(ModelTableHandlerMixin, Handler): path = 'authenticators' + detail = { 'users': Users } + title = _('Current authenticators') fields = [ { 'name': {'title': _('Name'), 'visible': True } }, diff --git a/server/src/uds/REST/methods/networks.py b/server/src/uds/REST/methods/networks.py index e2e468d42..a38259d1f 100644 --- a/server/src/uds/REST/methods/networks.py +++ b/server/src/uds/REST/methods/networks.py @@ -36,7 +36,7 @@ from django.utils.translation import ugettext_lazy as _ from uds.models import Network from uds.REST import Handler, HandlerError -from uds.REST.mixins import ModelHandlerMixin, ModelTypeHandlerMixin, ModelTableHandlerMixin, ModelFakeType +from uds.REST.mixins import ModelHandlerMixin, ModelTypeHandlerMixin, ModelTableHandlerMixin import logging @@ -52,7 +52,6 @@ class Networks(ModelHandlerMixin, Handler): 'name': item.name, 'net_string': item.net_string, 'networks_count': item.transports.count(), - 'type': 'NetworkType', } class Types(ModelTypeHandlerMixin, Handler): @@ -60,7 +59,7 @@ class Types(ModelTypeHandlerMixin, Handler): # Fake mathods, to yield self on enum types and get a "fake" type for Network def enum_types(self): - yield ModelFakeType('Network', 'NetworkType', 'A description of a network', '') + return [] class TableInfo(ModelTableHandlerMixin, Handler): path = 'networks' diff --git a/server/src/uds/REST/methods/users.py b/server/src/uds/REST/methods/users.py index 324a62c43..88dc12f40 100644 --- a/server/src/uds/REST/methods/users.py +++ b/server/src/uds/REST/methods/users.py @@ -32,10 +32,10 @@ ''' from __future__ import unicode_literals -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import ugettext as _ from django.utils import formats -from uds.models import User +from uds.models import Authenticator, User from uds.REST.mixins import DetailHandler @@ -78,5 +78,21 @@ class Users(DetailHandler): except: logger.exception('En users') return { 'error': 'not found' } + + def getTitle(self): + try: + return _('Users of {0}').format(Authenticator.objects.get(pk=self._kwargs['parent_id'])) + except: + return _('Current users') + + def getFields(self): + return [ + { 'name': {'title': _('User Id'), 'visible': True } }, + { 'real_name': { 'title': _('Name') } }, + { 'comments': { 'title': _('Comments') } }, + { 'state': { 'title': _('state') } }, + { 'last_access': { 'title': _('Last access') } }, + ] + \ No newline at end of file diff --git a/server/src/uds/REST/mixins.py b/server/src/uds/REST/mixins.py index 29fd4ceee..a2bee6e87 100644 --- a/server/src/uds/REST/mixins.py +++ b/server/src/uds/REST/mixins.py @@ -38,12 +38,21 @@ import logging logger = logging.getLogger(__name__) +# Details do not have types at all +# so, right now, we only process details petitions for Handling & tables info class DetailHandler(object): def __init__(self, parentHandler, path, *args, **kwargs): self._parent = parentHandler self._path = path self._args = args self._kwargs = kwargs + + # A detail handler must also return title & fields for tables + def getTitle(self): + return '' + + def getFields(self): + return [] class ModelHandlerMixin(object): ''' @@ -61,7 +70,7 @@ class ModelHandlerMixin(object): def getItems(self, *args, **kwargs): for item in self.model.objects.filter(*args, **kwargs): - try: + try: yield self.item_as_dict(item) except: logger.exception('Exception getting item from {0}'.format(self.model)) @@ -91,7 +100,8 @@ class ModelHandlerMixin(object): item = list(self.getItems(pk=self._args[0]))[0] except: return {'error': 'not found' } - + + class ModelTypeHandlerMixin(object): ''' As With models, a lot of UDS model contains info about its class. @@ -119,10 +129,12 @@ class ModelTypeHandlerMixin(object): def get(self): return list(self.getTypes()) + class ModelTableHandlerMixin(object): authenticated = True needs_staff = True + detail = None # Fields should have id of the field, type and length # All options can be ommited @@ -135,11 +147,29 @@ class ModelTableHandlerMixin(object): fields = [] title = '' + + def processDetail(self): + logger.debug('Processing detail for table') + try: + detailCls = self.detail[self._args[1]] + args = list(self._args[2:]) + path = self._path + '/'.join(args[:2]) + detail = detailCls(self, path, parent_id = self._args[0]) + return (detail.getTitle(), detail.getFields()) + except: + return ([], '') def get(self): - # Convert to unicode fields (ugettext_lazy needs to be rendered before passing it to Json - fields = [ { 'id' : {'visible': False } } ] # Always add id column as invisible - for f in self.fields: + if len(self._args) > 1: + title, fields = self.processDetail() + else: + # Convert to unicode fields (ugettext_lazy needs to be rendered before passing it to Json + title = self.title + fields = self.fields # Always add id column as invisible + + processedFields = [{ 'id' : {'visible': False, 'sortable': False, 'searchable': False } }] + + for f in fields: for k1, v1 in f.iteritems(): dct = {} for k2, v2 in v1.iteritems(): @@ -147,16 +177,6 @@ class ModelTableHandlerMixin(object): dct[k2] = v2 else: dct[k2] = unicode(v2) - fields.append({k1: dct}) - return { 'title': unicode(self.title), 'fields': fields }; + processedFields.append({k1: dct}) + return { 'title': unicode(title), 'fields': processedFields }; - -# Fake type for models that do not needs typing -class ModelFakeType(object): - def __init__(self, name, type_, description, icon): - self._name, self._type, self._description, self._icon = name, type_, description, icon - - def name(self): return self._name - def type(self): return self._type - def description(self): return self._description - def icon(self): return self._icon diff --git a/server/src/uds/admin/urls.py b/server/src/uds/admin/urls.py index 2912ad20e..c5a1f2719 100644 --- a/server/src/uds/admin/urls.py +++ b/server/src/uds/admin/urls.py @@ -37,5 +37,6 @@ from uds import REST urlpatterns = patterns('uds.admin.views', (r'^$', 'index'), + (r'^tmpl/(?P