Skip to content

Commit

Permalink
models: implement multi service support
Browse files Browse the repository at this point in the history
  • Loading branch information
ergo committed Nov 15, 2016
1 parent 3d98d8d commit f19881c
Show file tree
Hide file tree
Showing 13 changed files with 552 additions and 434 deletions.
14 changes: 14 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
Changelog
=========

2016-11-XX
----------

* Release 0.7.0
* Introduced ResourceTreeService for nested resource management
(currently only PostgreSQL support is implemented)
* added deprecation warnings

**BACKWARDS INCOMPATIBLE CHANGES**

- code reorganization that might break existing code
- _ziggurat_services is now a list


2016-07-05
----------
* Release: 0.6.8
Expand Down
23 changes: 12 additions & 11 deletions ziggurat_foundations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,32 @@ def make_passwordmanager():
return pwd_context


def ziggurat_model_init(*k, **kw):
def ziggurat_model_init(*args, **kwargs):
"""
This function handles attaching model to service if model has one specified
as `_ziggurat_service`, Also attached a proxy object holding all model
definitions that services might use
:param k:
:param kw:
:param args:
:param kwargs:
:return:
"""
models = ModelProxy()
for cls2 in k:
for cls2 in args:
setattr(models, cls2.__name__, cls2)

for cls in k:
for cls in args:
if cls.__name__ == 'User':
if kw.get('passwordmanager'):
cls.passwordmanager = kw['passwordmanager']
if kwargs.get('passwordmanager'):
cls.passwordmanager = kwargs['passwordmanager']
else:
cls.passwordmanager = make_passwordmanager()

for cls2 in k:
for cls2 in args:
setattr(models, cls2.__name__, cls2)
setattr(cls, "_ziggurat_models", models)
# if model has a manager attached attached the class also to manager
if hasattr(cls, '_ziggurat_service'):
setattr(cls._ziggurat_service, 'model', cls)
setattr(cls._ziggurat_service, 'models_proxy', models)
if hasattr(cls, '_ziggurat_services'):
for service in cls._ziggurat_services:
setattr(service, 'model', cls)
setattr(service, 'models_proxy', models)
2 changes: 1 addition & 1 deletion ziggurat_foundations/models/external_identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ExternalIdentityMixin(BaseModel):
{'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8',
})

_ziggurat_service = ExternalIdentityService
_ziggurat_services = [ExternalIdentityService]

@declared_attr
def __tablename__(self):
Expand Down
2 changes: 1 addition & 1 deletion ziggurat_foundations/models/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class GroupMixin(BaseModel):
""" base mixin for group object"""

_ziggurat_service = GroupService
_ziggurat_services = [GroupService]

__table_args__ = {'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'}

Expand Down
2 changes: 1 addition & 1 deletion ziggurat_foundations/models/group_permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class GroupPermissionMixin(BaseModel):
name='pk_groups_permissions'),
{'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'})

_ziggurat_service = GroupPermissionService
_ziggurat_services = [GroupPermissionService]

@declared_attr
def __tablename__(self):
Expand Down
4 changes: 3 additions & 1 deletion ziggurat_foundations/models/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from ziggurat_foundations.exc import ZigguratException
from ziggurat_foundations.models.base import BaseModel
from ziggurat_foundations.models.services.resource import ResourceService
from ziggurat_foundations.models.services.resource_tree import \
ResourceTreeService
from ziggurat_foundations.models.base import get_db_session

__all__ = ['ResourceMixin']
Expand All @@ -14,7 +16,7 @@
class ResourceMixin(BaseModel):
__possible_permissions__ = ()

_ziggurat_service = ResourceService
_ziggurat_services = [ResourceService, ResourceTreeService]

@declared_attr
def __tablename__(self):
Expand Down

0 comments on commit f19881c

Please sign in to comment.