Changeset 3436 for WAeUP_SRP/base
- Timestamp:
- 15 Apr 2008, 15:26:29 (17 years ago)
- Location:
- WAeUP_SRP/base
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/base/Widgets.py
r3413 r3436 13 13 from Products.CPSSchemas.BasicWidgets import renderHtmlTag,CPSSelectWidget, CPSStringWidget 14 14 from Products.CPSSchemas.ExtendedWidgets import CPSDateTimeWidget 15 from Products.CPSSchemas.Vocabulary import Vocabulary 15 16 from Products.CPSSchemas.Widget import widgetRegistry 16 17 from Products.CPSUtil.file import PersistableFileUpload … … 765 766 766 767 widgetRegistry.register(StudyCourseWidget) 768 ###) 769 770 class VocabularyOnTheFly: ###( 771 def __init__(self, tuples): 772 """a nonpersistent vocabulary (copy from CPSSchemas.Vocabulary.Vocabulary). 773 Allowed parameter syntaxes is: 774 - Vocabulary((('foo', "Foo", 'label_foo'), ('bar', "Bar", 'label_bar'))) 775 Same as first with message ids (msgids) that can be used for i18n 776 """ 777 l = [] 778 d = {} 779 m = {} 780 # We suppose that initial vocabulary is sorted 781 # Vocabulary((('foo', "Foo", 'label_foo'), ('bar', "Bar", 'label_bar'))) 782 for k, v, msgid in tuples: 783 l.append(k) 784 d[k] = v 785 m[k] = msgid 786 self._list = l 787 self._dict = d 788 self._msgids = m 789 790 def __getitem__(self, key): 791 """Get a label for a key.""" 792 return self._dict[key] 793 794 def get(self, key, default=None): 795 """Get a label for a key, default to None.""" 796 try: 797 v = self._dict.get(key, default) 798 except TypeError: 799 # XXX temporary fix, don't know why sometime rendering try to do 800 # get([]) that returning a typeError 801 return '' 802 return v 803 804 def getMsgid(self, key, default=None): 805 """Get a msgid for a key, default to None.""" 806 return self._msgids.get(key, default) 807 808 def has_key(self, key): 809 """Test if a key is present.""" 810 return self._dict.has_key(key) 811 812 def keys(self): 813 """Get the ordered list of keys.""" 814 return self._list[:] 815 816 def items(self): 817 """Get the ordered list of (key, value).""" 818 return [(key, self._dict.get(key)) for key in self._list] 819 820 def values(self): 821 """Get the ordered list of values.""" 822 return [self._dict.get(key) for key in self._list] 823 824 def keysSortedBy(self, crit='id'): 825 """Return a keys list sorted on a criterium 826 827 Crit is one of 'id', 'label' or 'i18n'. 828 """ 829 830 if crit == 'label': 831 l = [(x[1], x[0]) for x in self.items()] 832 l.sort() 833 return [x[1] for x in l] 834 elif crit == 'i18n': 835 portal = getToolByName(self, 'portal_url').getPortalObject() 836 cpsmcat = portal.translation_service 837 l = [(cpsmcat(self.getMsgid(key)).encode('ISO-8859-15', 'ignore'), 838 key) for key in self.keys()] 839 l.sort() 840 return [x[1] for x in l] 841 else: 842 return self.keys() 843 ###) 844 845 class ApplicationCourseWidget(CPSSelectWidget): ###( 846 """ ApplicationCourse Widget""" 847 meta_type = "Application Course Widget" 848 849 def _getVocabulary(self,datastructure=None): 850 if self.REQUEST.traverse_subpath: 851 screening_type = self.REQUEST.traverse_subpath[0].upper() 852 else: 853 screening_type = 'ALL' 854 if screening_type in ("ALL","CEST","SANDWICH"): 855 application_category = screening_type 856 else: 857 application_category = "BASIC" 858 if not hasattr(self,'_v_certificates_docs'): 859 res = self.portal_catalog_real.search({'meta_type': "Certificate"}) 860 d = {} 861 for cert in res: 862 c = cert.getObject().getContent() 863 if getattr(c,'application_category',''): 864 d[cert.getId] = c 865 self._v_certificates_docs = d 866 l = [] 867 for k,d in self._v_certificates_docs.items(): 868 if application_category == "ALL": 869 l += (k,self._v_certificates_docs[k].title,k), 870 else: 871 if getattr(d,'application_category','') == application_category: 872 l += (k,self._v_certificates_docs[k].title,k), 873 #import ipdb;ipdb.set_trace() 874 return VocabularyOnTheFly(l) 875 876 InitializeClass(ApplicationCourseWidget) 877 878 widgetRegistry.register(ApplicationCourseWidget) 767 879 ###) 768 880
Note: See TracChangeset for help on using the changeset viewer.