diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2009-01-21 17:19:39 -0700 |
---|---|---|
committer | Rob Crittenden <rcritten@redhat.com> | 2009-02-03 15:28:59 -0500 |
commit | 4febb4dd1417de8961b2ab092b0c530ca088b72a (patch) | |
tree | 419789e208d36b2332e6eb274e61365db19ccb52 | |
parent | 6e53d03c69581982d341f591bfc3a35ec7f324d9 (diff) | |
download | freeipa.git-4febb4dd1417de8961b2ab092b0c530ca088b72a.tar.gz freeipa.git-4febb4dd1417de8961b2ab092b0c530ca088b72a.tar.xz freeipa.git-4febb4dd1417de8961b2ab092b0c530ca088b72a.zip |
Started roughing out new crud base classes
-rw-r--r-- | ipalib/__init__.py | 2 | ||||
-rw-r--r-- | ipalib/crud.py | 49 | ||||
-rw-r--r-- | ipalib/frontend.py | 2 | ||||
-rw-r--r-- | ipalib/parameters.py | 5 |
4 files changed, 58 insertions, 0 deletions
diff --git a/ipalib/__init__.py b/ipalib/__init__.py index 29344e18..aa0f66cc 100644 --- a/ipalib/__init__.py +++ b/ipalib/__init__.py @@ -874,9 +874,11 @@ import plugable from backend import Backend, Context from frontend import Command, LocalOrRemote, Application from frontend import Object, Method, Property +from crud import Create, Retrieve, Update, Delete, Search from parameters import DefaultFrom, Bool, Flag, Int, Float, Bytes, Str, Password from parameters import BytesEnum, StrEnum + try: import uuid except ImportError: diff --git a/ipalib/crud.py b/ipalib/crud.py index 345fc270..bf33b7ab 100644 --- a/ipalib/crud.py +++ b/ipalib/crud.py @@ -73,6 +73,55 @@ class Find(frontend.Method): yield option +class Create(frontend.Method): + """ + Create a new entry. + """ + + +class PKQuery(frontend.Method): + """ + Base class for `Retrieve`, `Update`, and `Delete`. + """ + + def get_args(self): + yield self.obj.primary_key.clone(query=True, multivalue=True) + + +class Retrieve(PKQuery): + """ + Retrieve an entry by its primary key. + """ + + +class Update(PKQuery): + """ + Update one or more attributes on an entry. + """ + + def get_options(self): + if self.extra_options_first: + for option in super(Update, self).get_options(): + yield option + for option in self.obj.params_minus_pk(): + yield option.clone(required=False) + if not self.extra_options_first: + for option in super(Update, self).get_options(): + yield option + + +class Delete(PKQuery): + """ + Delete one or more entries. + """ + + +class Search(frontend.Method): + """ + Retrieve all entries that match a given search criteria. + """ + + class CrudBackend(backend.Backend): """ Base class defining generic CRUD backend API. diff --git a/ipalib/frontend.py b/ipalib/frontend.py index 800bb43b..77a49d8b 100644 --- a/ipalib/frontend.py +++ b/ipalib/frontend.py @@ -617,6 +617,8 @@ class Method(Attribute, Command): `Property` classes. """ __public__ = Attribute.__public__.union(Command.__public__) + extra_options_first = False + extra_args_first = False def __init__(self): super(Method, self).__init__() diff --git a/ipalib/parameters.py b/ipalib/parameters.py index 76d88347..8928df16 100644 --- a/ipalib/parameters.py +++ b/ipalib/parameters.py @@ -230,6 +230,7 @@ class Param(ReadOnly): ('create_default', callable, None), ('autofill', bool, False), ('query', bool, False), + ('attribute', bool, False), ('flags', frozenset, frozenset()), # The 'default' kwarg gets appended in Param.__init__(): @@ -791,6 +792,8 @@ class Bytes(Data): Python v3 ``(str, unicode) => (bytes, str)`` clean-up. See: http://docs.python.org/3.0/whatsnew/3.0.html + + Also see the `Str` parameter. """ type = str @@ -839,6 +842,8 @@ class Str(Data): Python v3 ``(str, unicode) => (bytes, str)`` clean-up. See: http://docs.python.org/3.0/whatsnew/3.0.html + + Also see the `Bytes` parameter. """ type = unicode |