Changeset c7c3dea in tailbone


Ignore:
Timestamp:
06/22/20 18:26:43 (7 weeks ago)
Author:
Lance Edgar <lance@…>
Branches:
master
Children:
c1a2bb9
Parents:
bb11263
Message:

Improve support for composite key in master view

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tailbone/views/master.py

    rbb11263 rc7c3dea  
    24762476
    24772477    def get_row_grid_key(self):
    2478         return '{}.{}'.format(self.get_grid_key(), self.request.matchdict[self.get_model_key()])
     2478        model_key = self.get_model_key(as_tuple=True)
     2479        key = '.'.join([self.get_grid_key()] +
     2480                       [self.request.matchdict[k] for k in model_key])
     2481        return key
    24792482
    24802483    def get_grid_actions(self):
     
    28762879            for i, model_key in enumerate(model_keys):
    28772880                key = self.request.matchdict[model_key]
     2881                if self.key_is_integer(model_key):
     2882                    key = int(key)
    28782883                query = query.filter(getattr(self.model_class, model_key) == key)
    28792884            try:
    28802885                obj = query.one()
    2881             except NoResultFound:
     2886            except orm.exc.NoResultFound:
    28822887                raise self.notfound()
    28832888
     
    28892894
    28902895        return obj
     2896
     2897    def key_is_integer(self, model_key):
     2898
     2899        # inspect model class to determine if model_key is numeric
     2900        cls = self.get_model_class(error=False)
     2901        if cls:
     2902            attr = getattr(cls, model_key)
     2903            if isinstance(attr.type, sa.Integer):
     2904                return True
     2905
     2906        # do not assume integer by default
     2907        return False
    28912908
    28922909    def get_instance_title(self, instance):
Note: See TracChangeset for help on using the changeset viewer.