Kind regards,
Etienne
class TransactionManager(object):
"""Manages create/delete/update transactions
Usage:
>>> m = TransactionManager(db)
>>> tx = m.create('BlogEntry', 5, **data)
"""
def __init__(self, db):
self.db = db
def create(self, name, oid, **kwargs):
"""override this method to customize the create transaction"""
# get the extent using extent(name)
Extent = self.db.extent(name)
tx = Extent[oid].t.create()
# update tx.__dict__ with the data in **kwargs
tx.__dict__.update(**kwargs)
# execute this transaction..
return self.db.execute(tx)
Okay cool, I seem to have misread that section in the tutorial. :)
Its working nicely. I made a simple "transaction manager" based
on it. I think using class methods would also work, but this seems
sufficient for my blog app..
Kind regards,
Etienne
class TransactionManager(object):
"""Manages create/delete/update transactions
Usage:
>>> m = TransactionManager(db)
>>> tx = m.create('BlogEntry', 5, **data)
"""
def __init__(self, db):
self.db = db
def create(self, name, oid, **kwargs):
"""override this method to customize the create transaction"""
# get the extent using extent(name)
Extent = self.db.extent(name)
tx = Extent[oid].t.create()
# update tx.__dict__ with the data in **kwargs
tx.__dict__.update(**kwargs)
# execute this transaction..
return self.db.execute(tx)
Also, how can we create a batch of new entities ?
Thanks for the replies, I appreciate your input! ;)
> As Malek pointed out, we have that covered. :)
> Though the documentation still needs improvement, you can consider
> Schevo to have been put through its paces as far as its API design.
> If you find yourself doing some low-level wrapping or management of
> Schevo objects, you may find that deeper inspection reveals that a
> solution already exists.
>
> schevo.transaction.Combination is here:
> http://github.com/gldnspud/schevo/blob/feba3e006695c4bf182e7a97e57a035278123fa6/schevo/transaction.py#L552
>
> Example usage:
>
> from schevo.transaction import Combination
> tx1 = db.Foo.t.create(name='one')
> tx2 = db.Foo.t.create(name='two')
> tx3 = db.Foo.t.create(name='three')
> combined = Combination([tx1, tx2, tx3])
> foo1, foo2, foo3 = db.execute(combined) # Executes as "all or
> nothing"
I will look into it. It seems what I'm looking for but would still
like wrapping it in a queue-like interface. :)
Also, I'm having some light problems editing entities using the
SchevoGtk app. I managed to install it, but something seems
broken when trying to edit a field value:
steiner@lisa:~/notmm-schevo/tests/blogengine$ schevo gnav blogengine.db
/home/steiner/ncvs/schevo-git/schevo/field.py:9: DeprecationWarning:
the md5 module is deprecated; use hashlib instead import md5
22:11:26 environ No en_CA translation found for domain kiwi
22:11:26 environ No en_CA translation found for domain
gazpacho Schevo 3.1b1dev-20090505 :: Database Navigator
/usr/local/lib/python2.6/site-packages/gazpacho/loader/loader.py:496:
DeprecationWarning: Use the new widget gtk.Tooltip self._tooltips =
gtk.Tooltips() /usr/local/lib/python2.6/site-packages/gazpacho/loader/loader.py:497:
DeprecationWarning: Use the new widget gtk.Tooltip
self._tooltips.enable() Opened database blogengine.db
Starting Navigator UI...
Traceback (most recent call last):
File "/home/steiner/ncvs/schevo-gtk/schevogtk2/navigator.py", line
59, in on_entity_grid__action_selected self._on_action_selected(widget,
action) File "/home/steiner/ncvs/schevo-gtk/schevogtk2/window.py", line
112, in _on_action_selected tx = action.method()
File "/home/steiner/ncvs/schevo-git/schevo/entity.py", line 547, in
t_update tx = self._Update(self, **kw)
File "/home/steiner/ncvs/schevo-git/schevo/transaction.py", line 491,
in __init__ resolve_valid_values(self)
File "/home/steiner/ncvs/schevo-git/schevo/transaction.py", line 934,
in resolve_valid_values field_names = list(tx.f)
File "/home/steiner/ncvs/schevo-git/schevo/namespace.py", line 87, in
__getattr__ return self._i._field_map[name]
KeyError: '__length_hint__'
File "/home/steiner/ncvs/schevo-git/schevo/namespace.py", line 87, in
__getattr__ return self._i._field_map[name]
KeyError: '__length_hint__'
Kind Regards
Etienne
N.B: In schevogtk2/field.py, I made several attempts to fix this, but
failed. So here's the resulting function, hoping it could still helps
someone.. :)
@optimize.do_not_optimize
def _set_field_multiline_string(container, db, field, change_cb):
if isinstance(field, schevo.field.String) and field.multiline:
value = field.value
container.expand = True
if value is UNASSIGNED:
value = ''
elif isinstance(value, unicode):
value = unicode(value)
else:
value = str(value)
widget = gtk.ScrolledWindow()
widget.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
widget.set_shadow_type(gtk.SHADOW_ETCHED_IN)
widget.props.sensitive = False
textview = gtk.TextView()
if field.monospace:
textview.modify_font(MONO_FONT)
textview.set_accepts_tab(False)
textview.set_editable(True) # set this to True for editable mode
textview.set_size_request(-1, 150)
textbuff = textview.get_buffer()
textbuff.set_text(value)
textbuff.connect('changed', change_cb, field)
widget.add(textview)
widget.show_all()
return (False, widget, textview)
else:
return (True, None, None)
I think I managed to fix the last issue I was talking about, on
updating multiline fields using the SchevoGtk2 navigator.
Moreover, I made a Mercurial repository that follows the current git
branch of SchevoGtk here:
http://joelia.gthc.org/schevo-gtk/
I hope to use it for experimenting myself with Schevo and PyGtk, and
perhaps could be useful for contributing to the main development branch
as well.
Thanks and Regards
Etienne
Moreover, I made a Mercurial repository that follows the current git
branch of SchevoGtk here:
http://joelia.gthc.org/schevo-gtk/
I hope to use it for experimenting myself with Schevo and PyGtk, and
perhaps could be useful for contributing to the main development branch
as well.