Mercurial > moin-2.0-moinboot
changeset 2127:29b3dedf7a6b
Refactor Item.modify method, now it accepts extra keyword args to update the meta.
| author | Pavel Sviderski <pavel@psviderski.name> |
|---|---|
| date | Sun, 07 Jul 2013 19:54:32 +0400 |
| parents | 6998aedec89f |
| children | 21bd8d987eda |
| files | MoinMoin/items/__init__.py MoinMoin/items/_tests/test_Item.py |
| diffstat | 2 files changed, 21 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/MoinMoin/items/__init__.py Sun Jul 07 10:59:31 2013 +0200 +++ b/MoinMoin/items/__init__.py Sun Jul 07 19:54:32 2013 +0400 @@ -394,11 +394,9 @@ # just destroy this revision self.rev.item.destroy_revision(self.rev.revid) - def modify(self, meta, data, comment=u'', contenttype_guessed=None, contenttype_qs=None): - if contenttype_qs: - # we use querystring param to FORCE content type - meta[CONTENTTYPE] = contenttype_qs - + def modify(self, meta, data, comment=u'', contenttype_guessed=None, **update_meta): + meta = dict(meta) # we may get a read-only dict-like, copy it + meta.update(update_meta) return self._save(meta, data, contenttype_guessed=contenttype_guessed, comment=comment) class _ModifyForm(BaseModifyForm): @@ -730,7 +728,7 @@ meta, data, contenttype_guessed, comment = form._dump(self) contenttype_qs = request.values.get('contenttype') try: - self.modify(meta, data, comment, contenttype_guessed, contenttype_qs) + self.modify(meta, data, comment, contenttype_guessed, **{CONTENTTYPE: contenttype_qs}) except AccessDenied: abort(403) else:
--- a/MoinMoin/items/_tests/test_Item.py Sun Jul 07 10:59:31 2013 +0200 +++ b/MoinMoin/items/_tests/test_Item.py Sun Jul 07 19:54:32 2013 +0400 @@ -352,6 +352,23 @@ item.meta['test_key'] assert item.meta['another_test_key'] == another_meta['another_test_key'] assert item.content.data == another_data + # add/update meta + another_meta = { + 'test_key': 'test_value', + 'another_test_key': 'another_test_value', + } + item.modify(another_meta, another_data) + item = Item.create(name) + update_meta = { + 'another_test_key': 'updated_test_value', + 'new_test_key': 'new_test_value', + } + item.modify(another_meta, another_data, **update_meta) + item = Item.create(name) + assert item.name == u'Test_Item' + assert item.meta['test_key'] == another_meta['test_key'] + assert item.meta['another_test_key'] == update_meta['another_test_key'] + assert item.meta['new_test_key'] == update_meta['new_test_key'] coverage_modules = ['MoinMoin.items']
