Mercurial > moin > 2.0
changeset 1991:38e79cd2b320
use more constants: ITEMTYPE_DEFAULT
author | Thomas Waldmann <tw AT waldmann-edv DOT de> |
---|---|
date | Tue, 12 Feb 2013 17:54:59 +0100 |
parents | 22441b6366e6 |
children | d06e56e20b91 |
files | MoinMoin/apps/frontend/views.py MoinMoin/items/__init__.py MoinMoin/items/_tests/test_Content.py MoinMoin/storage/middleware/serialization.py |
diffstat | 4 files changed, 12 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py Tue Feb 12 17:43:27 2013 +0800 +++ b/MoinMoin/apps/frontend/views.py Tue Feb 12 17:54:59 2013 +0100 @@ -52,6 +52,7 @@ from MoinMoin.items.content import content_registry from MoinMoin import user, util from MoinMoin.constants.keys import * +from MoinMoin.constants.itemtypes import ITEMTYPE_DEFAULT from MoinMoin.constants.chartypes import CHARS_UPPER, CHARS_LOWER from MoinMoin.util import crypto from MoinMoin.util.interwiki import url_for_item @@ -466,7 +467,7 @@ item_name_converted = item_name + 'converted' try: # TODO implement Content.create and use it here - converted_item = Item.create(item_name_converted, itemtype=u'default', contenttype=contenttype) + converted_item = Item.create(item_name_converted, itemtype=ITEMTYPE_DEFAULT, contenttype=contenttype) except AccessDenied: abort(403) return converted_item.content._convert(item.content.internal_representation()) @@ -481,7 +482,7 @@ After successful POST, redirects to the page. """ # XXX drawing applets don't send itemtype - itemtype = request.values.get('itemtype', u'default') + itemtype = request.values.get('itemtype', ITEMTYPE_DEFAULT) contenttype = request.values.get('contenttype') try: item = Item.create(item_name, itemtype=itemtype, contenttype=contenttype)
--- a/MoinMoin/items/__init__.py Tue Feb 12 17:43:27 2013 +0800 +++ b/MoinMoin/items/__init__.py Tue Feb 12 17:54:59 2013 +0100 @@ -261,7 +261,7 @@ # content_registry.get yet, have to patch it later. content = Content.create(contenttype) - itemtype = rev.meta.get(ITEMTYPE) or itemtype or u'default' + itemtype = rev.meta.get(ITEMTYPE) or itemtype or ITEMTYPE_DEFAULT logging.debug("Item {0!r}, got itemtype {1!r} from revision meta".format(name, itemtype)) item = item_registry.get(itemtype, name, rev=rev, content=content)
--- a/MoinMoin/items/_tests/test_Content.py Tue Feb 12 17:43:27 2013 +0800 +++ b/MoinMoin/items/_tests/test_Content.py Tue Feb 12 17:54:59 2013 +0100 @@ -19,6 +19,7 @@ from MoinMoin.items import Item from MoinMoin.items.content import Content, ApplicationXTar, Binary, Text, Image, TransformableBitmapImage, MarkupItem from MoinMoin.constants.keys import CONTENTTYPE, TAGS +from MoinMoin.constants.itemtypes import ITEMTYPE_DEFAULT class TestContent(object): @@ -73,14 +74,14 @@ creates a container and tests the content saved to the container """ item_name = u'ContainerItem1' - item = Item.create(item_name, itemtype=u'default', contenttype=u'application/x-tar') + item = Item.create(item_name, itemtype=ITEMTYPE_DEFAULT, contenttype=u'application/x-tar') filecontent = 'abcdefghij' content_length = len(filecontent) members = set(['example1.txt', 'example2.txt']) item.content.put_member('example1.txt', filecontent, content_length, expected_members=members) item.content.put_member('example2.txt', filecontent, content_length, expected_members=members) - item = Item.create(item_name, itemtype=u'default', contenttype=u'application/x-tar') + item = Item.create(item_name, itemtype=ITEMTYPE_DEFAULT, contenttype=u'application/x-tar') tf_names = set(item.content.list_members()) assert tf_names == members assert item.content.get_member('example1.txt').read() == filecontent @@ -90,7 +91,7 @@ creates two revisions of a container item """ item_name = u'ContainerItem2' - item = Item.create(item_name, itemtype=u'default', contenttype=u'application/x-tar') + item = Item.create(item_name, itemtype=ITEMTYPE_DEFAULT, contenttype=u'application/x-tar') filecontent = 'abcdefghij' content_length = len(filecontent) members = set(['example1.txt']) @@ -107,7 +108,7 @@ def test_put_member(self): item_name = u'Zip_file' - item = Item.create(item_name, itemtype=u'default', contenttype='application/zip') + item = Item.create(item_name, itemtype=ITEMTYPE_DEFAULT, contenttype='application/zip') filecontent = 'test_contents' content_length = len(filecontent) members = set(['example1.txt', 'example2.txt']) @@ -174,7 +175,7 @@ def test_data_conversion(self): item_name = u'Text_Item' - item = Item.create(item_name, u'default', u'text/plain') + item = Item.create(item_name, ITEMTYPE_DEFAULT, u'text/plain') test_text = u'This \n is \n a \n Test' # test for data_internal_to_form result = Text.data_internal_to_form(item.content, test_text)
--- a/MoinMoin/storage/middleware/serialization.py Tue Feb 12 17:43:27 2013 +0800 +++ b/MoinMoin/storage/middleware/serialization.py Tue Feb 12 17:54:59 2013 +0100 @@ -25,6 +25,7 @@ from werkzeug.wsgi import LimitedStream from MoinMoin.constants.keys import NAME, ITEMTYPE, SIZE +from MoinMoin.constants.itemtypes import ITEMTYPE_DEFAULT def serialize(backend, dst): @@ -76,7 +77,7 @@ meta[NAME] = [name, ] if ITEMTYPE not in meta: # temporary hack to upgrade serialized item files: - meta[ITEMTYPE] = u'default' + meta[ITEMTYPE] = ITEMTYPE_DEFAULT data_size = meta[SIZE] curr_pos = src.tell() limited = LimitedStream(src, data_size)