Skip to content

Commit

Permalink
Extended manager.
Browse files Browse the repository at this point in the history
  • Loading branch information
timmartin19 committed Apr 24, 2015
1 parent 249a6fe commit 7af5075
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ripozo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from ripozo.decorators import apimethod, translate
from ripozo.dispatch import adapters
from ripozo.viewsets import fields
from ripozo.viewsets import fields, restmixins
from ripozo.viewsets.relationships.list_relationship import ListRelationship
from ripozo.viewsets.relationships.relationship import Relationship
from ripozo.viewsets.resource_base import ResourceBase
38 changes: 37 additions & 1 deletion ripozo/managers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,40 @@ def get_pagination_pks(self, filters):
"""
filters = filters.copy()
last_pagination_pk = filters.pop(self.pagination_pk_query_arg, None)
return last_pagination_pk, filters
return last_pagination_pk, filters

def dot_field_list_to_dict(self, fields=None):
"""
Converts a list of dot delimited fields (and related fields)
and turns it into a dictionary for example, it would transform
.. code-block:: python
>>> dot_field_list_to_dict(['id', 'value', 'related.id', 'related.related_value'])
{
'id': None,
'value': None,
'related': {
'id': None,
'related_value': None
}
}
:param list fields:
:return: A dictionary of the fields layered as to
indicate relationships.
:rtype: dict
"""
# TODO find a better fucking way
field_dict = {}
fields = fields or self.fields
for f in fields:
field_parts = f.split('.')
current = field_dict
part = field_parts.pop(0)
while len(field_parts) > 0:
current[part] = current.get(part, dict())
current = current[part]
part = field_parts.pop(0)
current[part] = None
return field_dict
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
],
classifiers=[
'Development Status :: 3 - Alpha',
'License :: Other/Proprietary License',
'License :: OSI Approved :: GNU General Public License v2 (GPLv2)',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
Expand Down

0 comments on commit 7af5075

Please sign in to comment.