162 def update_dal(self, d, followup_method, get_method, cache=None,
164 """Sets each attribute defined in the DAL object 'd', with the value.
166 This method will update the ConfigObject attributes and its
167 relationships recursively, cooperatively with the Configuration class.
168 The recursion is implemented in a very easy way in these terms.
172 d -- This is the DAL object you are trying to set this
175 followup_method -- The Configuration method to call for the recursion.
176 This one varies with the type of change you are performing (adding or
179 get_method -- The Configuration method to call for retrieving objects
180 from the associated database.
182 cache -- This is a cache that may be set by the Configuration object if
183 necessary. Users should *never* set this variable. This variable is
184 there to handle recursions gracefully.
186 recurse -- This is a boolean flag that indicates if you want to enable
187 recursion or not in the update. If set to 'True' (the default), I'll
188 recurse until all objects in the tree are updated. Otherwise, I'll not
189 recurse at all and just make sure my attributes and relationships are
190 set to what you determine they should be. Please note that if you
191 decide to update relationships, that the objects to which you are
192 pointing to should be available in the database (directly or indirectly
193 through includes) if you choose to do this non-recursively.
197 if hasattr(d, k)
and getattr(d, k)
is not None:
198 self[k] = getattr(d, k)
200 for k, v
in self.
__schema__[
'relation'].items():
201 if not hasattr(d, k):
206 if not getattr(d, k):
214 for i
in getattr(d, k):
215 if cache
and i.fullName()
in cache:
216 val.append(cache[i.fullName()])
218 val.append(followup_method(
219 i, cache=cache, recurse=recurse))
221 val.append(get_method(i.className(), i.id))
227 if cache
and i.fullName()
in cache:
228 self[k] = cache[i.fullName()]
230 self[k] = followup_method(
231 i, cache=cache, recurse=recurse)
233 self[k] = get_method(i.className(), i.id)
238 """Returns a DAL representation of myself and my descendents.
240 In this implementation, we by-pass the type checking facility to gain
241 in time and because we know that if the ConfigObject was set, it must
242 conform to OKS in any case.
245 for k
in dobj.oksTypes():
246 cache[k][self.UID()] = dobj
249 setattr(dobj.__class__, a,
250 property(dalproperty._return_attribute(a, dobj, self[a]),
251 dalproperty._assign_attribute(a)))
256 if self.
__schema__[
'relation'][r][
'multivalue']:
258 getter = dalproperty. \
259 _return_relation(r, multi=
True, cache=cache,
260 data=data, dalobj=dobj)
264 getter = dalproperty. \
265 _return_relation(r, cache=cache,
266 data=data, dalobj=dobj)
268 setattr(dobj.__class__, r,
270 dalproperty._assign_relation(r)))