@@ -60,26 +60,20 @@ def flush_models(includes = None, excludes = None):
60
60
61
61
def register (model , backend = None , ignore_duplicates = True ,
62
62
local_thread = False , ** params ):
63
- '''The low level function for registering a :class:`stdnet.orm. StdModel`
64
- classes with a :class:`stdnet.backends. BackendDataServer` data server.
63
+ '''The low level function for registering a :class:`StdModel`
64
+ classes with a :class:`stdnet.BackendDataServer` data server.
65
65
66
- :parameter model: a :class:`stdnet.orm. StdModel` class . Must be provided.
66
+ :parameter model: a :class:`StdModel`. Must be provided.
67
67
68
68
:parameter backend: a backend connection string.
69
69
For example::
70
70
71
71
redis://localhost:8080?db=6&prefix=bla.
72
72
73
73
Default ``settings.DEFAULT_BACKEND``.
74
-
74
+
75
75
:parameter params: optional parameters which can be used to override the
76
76
connection string parameters.
77
-
78
- :parameter timeout: timeout in seconds for keys persistence.
79
- If not provided it is calculated from the
80
- connection string.
81
-
82
- Default ``None``.
83
77
84
78
**Usage**
85
79
@@ -90,7 +84,7 @@ def register(model, backend = None, ignore_duplicates = True,
90
84
orm.register(Author, 'redis://my.host.name:6379/?db=1')
91
85
orm.register(Book, 'redis://my.host.name:6379/?db=2')
92
86
orm.register(MyOtherModel,
93
- 'redis://my.host.name:6379/?db=2&keyprefix=differentprefix')
87
+ 'redis://my.host.name:6379/?db=2&keyprefix=differentprefix. ')
94
88
95
89
``my.host.name`` can be ``localhost`` or an ip address or a domain name,
96
90
while ``db`` indicates the database number (very useful for separating data
@@ -130,17 +124,17 @@ def unregister(model = None):
130
124
131
125
132
126
def registered_models ():
133
- '''Iterator over registered models'''
127
+ '''An iterator over registered models'''
134
128
return (m for m in _GLOBAL_REGISTRY )
135
129
136
130
137
131
def model_iterator (application ):
138
- '''\
139
- Returns a generatotr of :class:`stdnet.orm.StdModel` classes found
140
- in the ``models`` module of an ``application`` dotted path.
132
+ '''A generator of :class:`StdModel` classes found in *application*.
141
133
142
- :parameter application: An iterable over python dotted-paths
143
- where models are defined.
134
+ :parameter application: A python dotted path or an iterable over python
135
+ dotted-paths where models are defined.
136
+
137
+ Only models defined in these paths are considered.
144
138
145
139
For example::
146
140
@@ -164,13 +158,12 @@ def model_iterator(application):
164
158
try :
165
159
mod_models = import_module ('.models' ,application )
166
160
except ImportError :
167
- raise StopIteration
168
-
169
- label = getattr (mod_models ,'app_label' ,label )
161
+ mod_models = mod
162
+ label = getattr (mod_models , 'app_label' , label )
170
163
for name in dir (mod_models ):
171
- model = getattr (mod_models ,name )
172
- meta = getattr (model ,'_meta' ,None )
173
- if isinstance (model ,StdNetType ) and meta :
164
+ model = getattr (mod_models , name )
165
+ meta = getattr (model , '_meta' , None )
166
+ if isinstance (model , StdNetType ) and meta :
174
167
if not meta .abstract and meta .app_label == label :
175
168
yield model
176
169
@@ -182,21 +175,18 @@ def register_application_models(applications,
182
175
'''\
183
176
A higher level registration functions for group of models located
184
177
on application modules.
185
-
186
- It uses the :func:`stdnet.orm.model_iterator` function to iterate
187
- through all :class:`stdnet.orm.StdModel` models available in ``applications``
188
- and register them using the :func:`stdnet.orm.register` low
189
- level function.
178
+ It uses the :func:`model_iterator` function to iterate
179
+ through all :class:`StdModel` models available in ``applications``
180
+ and register them using the :func:`register` low level function.
190
181
191
182
:parameter applications: A String or a list of strings which represent
192
- python dotted paths to modules containing
193
- a ``models`` module where models are implemented.
183
+ python dotted paths where models are implemented.
194
184
:parameter models: Optional list of models to include. If not provided
195
185
all models found in *applications* will be included.
196
186
:parameter app_defaults: optional dictionary which specify a model and/or
197
187
application backend connection string.
198
188
:parameter default: The default connection string.
199
- :rtype: a generator over registered models
189
+ :rtype: A generator over registered :class:`StdModel`.
200
190
201
191
For example::
202
192
0 commit comments