开发者

Providing backward compatibility for a zope component

I'm working on a new release of collective.imagetags in which all the functionality that was carried by a browser view (imagetags-manage) is now moved to a new adapter (not commited yet) which provides almost the same interface that the browser view::

class IManageTags(Interface):
    """
    imagetags-manage view interface
    Tag management browser view
    """

    def get_tag(id, create_on_fail=True):
        """ Gets / creates a specific tag """

    def get_tags():
        """ Gets all the tags for the object """

    def get_sorted_tags():
        """ Sorted list of tags
        """

    def save_tag(data):
        """ Saves a tag with the passed data """

I really don't know if anybody is using this product in a project, however, I think开发者_JAVA百科 it would be a sensible idea to provide some backward compatibility mechanism, in case anyone is using the browser view methods outside the out-of-the-box functionalities.

What should I do? Keep the interface for the browser view with stub methods that relay on the new adapter? Any suggestion?


This kind of change is quite hard ! It is not question of API but of design.

  • browser views are component where you mix use/request with the context.
  • adapters are component where you don't care of the user or its request.
  • utility are component where you don't care of the context.

So you should keep your browserview and make it use the adapter, it should be enough to keep compatbility.

Upgrades are used when you make changes to the default profile. First the metadata.xml version must be an integer (1000 is often used as first stable version) Next, every changes to the profile should follow an increase of this version number and you must add an upgrade step:

<gs:upgradeStep
    title="Upgrade collective.myaddon from 1000 to 1010"
    description=""
    source="1000"
    destination="1010"
    handler=".upgrades.upgrade_1000_1010"
    profile="collective.myaddon:default"/> 


 upgrades.py
 def upgrade_1000_1010(context):
    """documentation
    """
    context.runImportStepFromProfile(default_profile, 'viewlets')
    portal_javascripts = getToolByName(context, 'portal_javascripts')
    portal_javascripts.cookResources()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜