Example #1
0
    def update_details(self, context, request, api, photo_thumb_size):

        # Create display values from model object

        for name in [name for name in context.__dict__.keys() if not name.startswith("_")]:
            profile_value = getattr(context, name)
            if profile_value is not None:
                # Don't produce u'None'
                self[name] = unicode(profile_value)
            else:
                self[name] = None

        # 'websites' is a tuple, so unicode(websites) is not what we want
        self["websites"] = context.websites

        # 'title' is a property, so need to access it directly
        self["title"] = context.title

        # 'created' is also a property and needs formatting too
        self['created'] = context.created.strftime('%B %d, %Y')

        if self.has_key("languages"):
            self["languages"] = context.languages

        if self.has_key("department"):
            self["department"] = context.department

        if self.get("last_login_time"):
            stamp = context.last_login_time.strftime('%Y-%m-%dT%H:%M:%SZ')
            self["last_login_time"] = stamp

        if self.has_key("country"):
            # translate from country code to country name
            country_code = self["country"]
            country = countries.as_dict.get(country_code, u'')
            self["country"] = country

        # Display portrait
        photo = context.get('photo')
        display_photo = {}
        if photo is not None:
            display_photo["url"] = thumb_url(photo, request, photo_thumb_size)
        else:
            display_photo["url"] = api.static_url + "/img/default_user.png"
        self["photo"] = display_photo

        if get_setting(context, 'twitter_search_id'):
            # assume it's a social app
            social = social_category(context, None)
            if social:
                self.update(social.ids())
Example #2
0
 def __init__(self, context, request):
     super(EditProfileFormController, self).__init__(context, request)
     self.social_category = social_category(context, None)
     if not self.social_category:
         # the social category is lazily instantiated
         self.social_category = context.categories['social'] = SocialCategory()