Skip to content

Commit

Permalink
fixes #21: adds a simple OPTIONS traversal that does not rely on a da…
Browse files Browse the repository at this point in the history
…tabase. this could theoretically be improved if we want to expose different options at different endpoints, but the current design utilizes options as a global API feature
  • Loading branch information
Eric Hulser committed Dec 12, 2017
1 parent e5c716f commit 9570a7f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pyramid_orb/services/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ def get(self):
return self.__value


class OptionsService(OrbService):
def __init__(self, request, options={}, parent=None, name=None):
super(OptionsService, self).__init__(request, parent, name)
self._options = options

def __getitem__(self, key):
return self

def get(self):
return self._options

def options(self):
return self._options


class ModelService(OrbService):
""" Represents an individual database record """
def __init__(self, request, model, parent=None, record_id=None, from_collection=None, record=None, name=None):
Expand All @@ -38,6 +53,9 @@ def __init__(self, request, model, parent=None, record_id=None, from_collection=
self.actions = self.collect_actions_from_model(model)

def __getitem__(self, key):
if self.request.method.lower() == 'options':
return OptionsService(self.request, parent=self, name='options')

schema = self.model.schema()

# lookup the articles information
Expand Down

0 comments on commit 9570a7f

Please sign in to comment.