Changeset 5820 for main/waeup.sirp/trunk/src/waeup/sirp/applicants
- Timestamp:
- 9 Mar 2011, 13:41:27 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/applicants/interfaces.py
r5758 r5820 771 771 def getJAMBRegNo(): 772 772 """Return the JAMB registration no.""" 773 774 class IApplicantContainerProvider(Interface): 775 """A provider for applicants containers. 776 777 Applicants container providers are meant to be looked up as 778 utilities. This way we can find all applicant container types 779 defined somewhere. 780 781 Each applicants container provider registered as utility provides 782 one container type and one should be able to call the `factory` 783 attribute to create an instance of the requested container type. 784 785 .. THE FOLLOWING SHOULD GO INTO SPHINX DOCS (and be tested) 786 787 Samples 788 ******* 789 790 Given, you had an IApplicantsContainer implementation somewhere 791 and you would like to make it findable on request, then you would 792 normally create an appropriate provider utility like this:: 793 794 import grok 795 from waeup.sirp.applicants.interfaces import IApplicantContainerProvider 796 797 class MyContainerProvider(grok.GlobalUtility): 798 grok.implements(IApplicantContainerProvider) 799 grok.name('MyContainerProvider') # Must be unique 800 factory = MyContainer # A class implementing IApplicantsContainer 801 # or derivations thereof. 802 803 This utility would be registered on startup and could then be used 804 like this: 805 806 >>> from zope.component import getAllUtilitiesRegisteredFor 807 >>> from waeup.sirp.applicants.interfaces import ( 808 ... IApplicantContainerProvider) 809 >>> all_providers = getAllUtilitiesRegisteredFor( 810 ... IApplicantContainerProvider) 811 >>> all_providers 812 [<MyContainerProvider object at 0x...>] 813 814 You could look up this specific provider by name: 815 816 >>> from zope.component import getUtility 817 >>> p = getUtility(IApplicantContainerProvider, name='MyProvider') 818 >>> p 819 <MyContainerProvider object at 0x...> 820 821 An applicants container would then be created like this: 822 823 >>> provider = all_providers[0] 824 >>> container = provider.factory() 825 >>> container 826 <MyContainer object at 0x...> 827 828 """ 829 factory = Attribute("A class that can create instances of the " 830 "requested container type")
Note: See TracChangeset for help on using the changeset viewer.