/[pac]/CMFGeographics/GeographicsTool.py
ViewVC logotype

Diff of /CMFGeographics/GeographicsTool.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by tvon, Sat Oct 11 06:09:21 2003 UTC revision 1.3 by tvon, Tue Oct 14 00:10:16 2003 UTC
# Line 14  class GeographicsTool(UniqueObject, Simp Line 14  class GeographicsTool(UniqueObject, Simp
14      security = ClassSecurityInfo()      security = ClassSecurityInfo()
15      plone_tool = 1      plone_tool = 1
16    
17      ###########################################################################      #security.declarePublic('getName')
18      # Country utilities      def getName(self, sheet, key, lang='en'):
19      #          """Given a key (abbreviation) and the name of a property sheet, find the matching name for the key in the property sheet.  Language argument is optional and defaults to 'en' ((english).  Case insensitive (except for lang, which must be lowercase).
20      #security.declarePublic('getCountryName')  
21      def getCountryName(self, key, lang='en'):          >>> getName('countries', 'US')
22            'UNITED STATES'
23            >>> getName('countries', 'US', 'fr')
24            'ÉTATS-UNIS'
25    """
26          prop_tool = self.geographic_properties          prop_tool = self.geographic_properties
27          for l in  prop_tool.countries.getProperty(key):          prop_sheet = getattr(prop_tool, sheet)
28    
29            for l in prop_sheet.getProperty(key):
30              if l.split('|')[0] == lang:              if l.split('|')[0] == lang:
31                  return l.split('|')[1]                  return l.split('|')[1]
32    
33      #security.declarePublic('getCountryCode')      #security.declarePublic('getCode')
34      def getCountryCode(self, name, lang='en'):      def getCode(self, sheet, name, lang='en'):
35            """Given a name and the name of a property sheet, find the matching code (abbreviation) for the name in the property sheet.  Language argument is optional and defaults to 'en' ((english).  Case insensitive (except for lang, which must be lowercase).
36    
37            >>> getCode('countries', 'United STATES')
38            'US'
39            >>> getCode('countries', 'ÉTATS-UNIS')
40            'US'
41    """
42          prop_tool = self.geographic_properties          prop_tool = self.geographic_properties
43          for id in  prop_tool.countries.propertyIds():          prop_sheet = getattr(prop_tool, sheet)
44              for l in  prop_tool.countries.getProperty(id):  
45            for id in prop_sheet.propertyIds():
46                for l in prop_sheet.getProperty(id):
47                  if l.split('|')[0] == lang:                  if l.split('|')[0] == lang:
48                      if l.split('|')[1] == name.upper():                      if l.split('|')[1].upper() == name.upper():
49                          return id                          return id
50    
     ###########################################################################  
     # USA State utilities  
     #  
     #security.declarePublic('getUSAStateName')  
     #security.declarePublic('getUSAStateAbbreviation')  
   
   
51  InitializeClass(GeographicsTool)  InitializeClass(GeographicsTool)

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26