~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/canonical/launchpad/webapp/doc/menus.txt

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-12-24 22:30:39 UTC
  • mfrom: (14600.1.14 apocalypta-1)
  • Revision ID: launchpad@pqm.canonical.com-20111224223039-z7zbq34zfurx9gce
[rs=sinzui][no-qa] Move c.l modules to lp.

Show diffs side-by-side

added added

removed removed

Lines of Context:
568
568
== Registering menus in ZCML ==
569
569
 
570
570
First, we define a couple of interfaces, and put them in the
571
 
canonical.launchpad.ftests module.
 
571
lp.testing module.
572
572
 
573
573
    >>> class IThingHavingFacets(Interface):
574
574
    ...     pass
575
 
    >>> import canonical.launchpad.ftests
576
 
    >>> getattr(canonical.launchpad.ftests, 'IThingHavingFacets', None) is None
 
575
    >>> import lp.testing
 
576
    >>> getattr(lp.testing, 'IThingHavingFacets', None) is None
577
577
    True
578
578
 
579
 
    >>> canonical.launchpad.ftests.IThingHavingFacets = IThingHavingFacets
580
 
    >>> IThingHavingFacets.__module__ = 'canonical.launchpad.ftests'
 
579
    >>> lp.testing.IThingHavingFacets = IThingHavingFacets
 
580
    >>> IThingHavingFacets.__module__ = 'lp.testing'
581
581
 
582
582
    >>> class IThingHavingMenus(Interface):
583
583
    ...     pass
584
 
    >>> import canonical.launchpad.ftests
585
 
    >>> getattr(canonical.launchpad.ftests, 'IThingHavingMenus', None) is None
 
584
    >>> import lp.testing
 
585
    >>> getattr(lp.testing, 'IThingHavingMenus', None) is None
586
586
    True
587
587
 
588
 
    >>> canonical.launchpad.ftests.IThingHavingMenus = IThingHavingMenus
589
 
    >>> IThingHavingMenus.__module__ = 'canonical.launchpad.ftests'
 
588
    >>> lp.testing.IThingHavingMenus = IThingHavingMenus
 
589
    >>> IThingHavingMenus.__module__ = 'lp.testing'
590
590
 
591
591
Next, we define a FacetMenu subclass to be used for IThingHavingFacets,
592
592
using a usedfor class attribute to say what interface it is to be
593
 
registered for, and put it too in the canonical.launchpad.ftests module.
 
593
registered for, and put it too in the lp.testing module.
594
594
 
595
595
    >>> class FacetsForThing(Facets):
596
596
    ...     usedfor = IThingHavingFacets
606
606
    ...             summary = self.request.method
607
607
    ...         return Link(target, text, summary=summary)
608
608
 
609
 
    >>> getattr(canonical.launchpad.ftests, 'FacetsForThing', None) is None
 
609
    >>> getattr(lp.testing, 'FacetsForThing', None) is None
610
610
    True
611
611
 
612
 
    >>> canonical.launchpad.ftests.FacetsForThing = FacetsForThing
 
612
    >>> lp.testing.FacetsForThing = FacetsForThing
613
613
 
614
614
And likewise for an application menu registered for IThingHavingMenus.
615
615
 
617
617
    ...     usedfor = IThingHavingMenus
618
618
    ...     facet = 'foo'
619
619
 
620
 
    >>> getattr(canonical.launchpad.ftests, 'FooMenuForThing', None) is None
 
620
    >>> getattr(lp.testing, 'FooMenuForThing', None) is None
621
621
    True
622
622
 
623
 
    >>> canonical.launchpad.ftests.FooMenuForThing = FooMenuForThing
 
623
    >>> lp.testing.FooMenuForThing = FooMenuForThing
624
624
 
625
625
We do the same for a context menu.
626
626
 
627
627
    >>> class ContextMenuForThing(MyContextMenu):
628
628
    ...     usedfor = IThingHavingMenus
629
629
 
630
 
    >>> print getattr(canonical.launchpad.ftests, 'ContextMenuForThing', None)
 
630
    >>> print getattr(lp.testing, 'ContextMenuForThing', None)
631
631
    None
632
632
 
633
 
    >>> canonical.launchpad.ftests.ContextMenuForThing = ContextMenuForThing
 
633
    >>> lp.testing.ContextMenuForThing = ContextMenuForThing
634
634
 
635
635
Now, check that we have no IFacetMenu adapter for an IThingHavingFacets
636
636
object.
660
660
    ... <configure xmlns:browser="http://namespaces.zope.org/browser">
661
661
    ...   <include file="lib/canonical/launchpad/webapp/meta.zcml" />
662
662
    ...   <browser:menus
663
 
    ...       module="canonical.launchpad.ftests"
 
663
    ...       module="lp.testing"
664
664
    ...       classes="FacetsForThing FooMenuForThing ContextMenuForThing"
665
665
    ...       />
666
666
    ... </configure>
897
897
== Cleaning up ==
898
898
 
899
899
We're done testing the zcml, so we can clean up the
900
 
canonical.launchpad.ftests module.
 
900
lp.testing module.
901
901
 
902
 
    >>> del canonical.launchpad.ftests.FacetsForThing
903
 
    >>> del canonical.launchpad.ftests.FooMenuForThing
904
 
    >>> del canonical.launchpad.ftests.ContextMenuForThing
905
 
    >>> del canonical.launchpad.ftests.IThingHavingFacets
906
 
    >>> del canonical.launchpad.ftests.IThingHavingMenus
 
902
    >>> del lp.testing.FacetsForThing
 
903
    >>> del lp.testing.FooMenuForThing
 
904
    >>> del lp.testing.ContextMenuForThing
 
905
    >>> del lp.testing.IThingHavingFacets
 
906
    >>> del lp.testing.IThingHavingMenus
907
907
 
908
908
 
909
909
== The enabled_with_permission function decorator ==