def getPropertiesForUser(self, user, request=None): """ This can't use plone.api.user.get(user.getId()) as it would lead to a recursion. """ sheets = self._getPropertSheetsFromUser(user) def getProperty(id, default): for sheet in sheets: if sheet.hasProperty(id): # Return the first one that has the property. return safe_unicode(sheet.getProperty(id)) return safe_unicode(default) first = safe_unicode(getProperty('firstname', u'')) last = safe_unicode(getProperty('lastname', u'')) street = safe_unicode(getProperty('street', u'')) zip_code = safe_unicode(getProperty('zip', u'')) city = safe_unicode(getProperty('city', u'')) country = safe_unicode(getProperty('country', u'')) try: country = country and get_pycountry_name(country) or '' except KeyError: country = '' join_list = [street, u'{0} {1}'.format(zip_code, city), country] return { 'fullname': u'{0}{1}{2}'.format(first, u' ' if first and last else u'', last), 'location': u', '.join([it for it in join_list if it]), }
def getPropertiesForUser(self, user, request=None): """ This can't use plone.api.user.get(user.getId()) as it would lead to a recursion. """ sheets = self._getPropertSheetsFromUser(user) def getProperty(id, default): for sheet in sheets: if sheet.hasProperty(id): # Return the first one that has the property. return safe_unicode(sheet.getProperty(id)) return safe_unicode(default) first = safe_unicode(getProperty("firstname", u"")) last = safe_unicode(getProperty("lastname", u"")) street = safe_unicode(getProperty("street", u"")) zip_code = safe_unicode(getProperty("zip", u"")) city = safe_unicode(getProperty("city", u"")) country = safe_unicode(getProperty("country", u"")) try: country = country and get_pycountry_name(country) or "" except KeyError: country = "" join_list = [street, u"{0} {1}".format(zip_code, city), country] return { "fullname": u"{0}{1}{2}".format( first, u" " if first and last else u"", last ), "location": u", ".join([it for it in join_list if it]), }
def location(self): street = self._getProperty('street') zip = self._getProperty('zip') city = self._getProperty('city') country = self._getProperty('country') country = country and get_pycountry_name(country) or '' join_list = [street, '{0} {1}'.format(zip, city), country] return ', '.join([it for it in join_list if it])
def getPropertiesForUser(self, user, request=None): """ This can't use plone.api.user.get(user.getId()) as it would lead to a recursion. """ sheets = self._getPropertSheetsFromUser(user) def getProperty(id, default): for sheet in sheets: if sheet.hasProperty(id): # Return the first one that has the property. return safe_unicode(sheet.getProperty(id)) return safe_unicode(default) first = safe_unicode(getProperty('firstname', u'')) last = safe_unicode(getProperty('lastname', u'')) street = safe_unicode(getProperty('street', u'')) zip_code = safe_unicode(getProperty('zip', u'')) city = safe_unicode(getProperty('city', u'')) country = safe_unicode(getProperty('country', u'')) try: country = country and get_pycountry_name(country) or '' except KeyError: country = '' join_list = [street, u'{0} {1}'.format(zip_code, city), country] return { 'fullname': u'{0}{1}{2}'.format( first, u' ' if first and last else u'', last ), 'location': u', '.join([it for it in join_list if it]), }
def country(self, country_id): # return value if no id not available i.e. if no dropdown in use try: return get_pycountry_name(country_id) except: return country_id