Exemplo n.º 1
0
def thumbnail(context, request):
    api = request.api
    api.page_title = 'Profile thumbnail redirector'
    photo = context.get('photo')
    if photo is not None:
        url = thumb_url(photo, request, (300,200))
    else:
        url = api.static_url + "/img/default_user.png"
    return HTTPFound(location=url)
Exemplo n.º 2
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())
Exemplo n.º 3
0
    def find_image_url(self, ob, search='photo', default='/img/default_user.png', size=None):
        if ob is None:
            return default
        photo = find_image(ob, search)
        if photo is not None:
	    if isinstance(photo, (unicode, str)):
		# external reference thumbnail_url
            	return photo
            if size:
                return thumb_url(photo, self.request, size)
            else:
                return model_url(photo, self.request, 'dl')
        else:
            if default.startswith('/'): # absolute local url
                default = self.static_url + default
            return default
Exemplo n.º 4
0
    def __init__(self, profile, request):
        self['id'] = profile.__name__
        self['username'] = profile.__name__
        self['firstname'] = profile.firstname
        self['lastname'] = profile.lastname
        self['email'] = profile.email
        self['biography'] = profile.biography
        self['security_state'] = profile.security_state

        if hasattr(profile, 'created'):
            self['joined'] = profile.created.strftime('%Y-%m-%dT%H:%M:%SZ')

        if hasattr(profile, 'last_login_time') and profile.last_login_time is not None:
            self["last_login_time"] = profile.last_login_time.strftime('%Y-%m-%dT%H:%M:%SZ')

        if hasattr(profile, 'websites'):
            self['websites'] = profile.websites

        if hasattr(profile, 'categories'):
            self['twitter'] = profile.categories.get('twitter', '')
            self['facebook'] = profile.categories.get('facebook', '')

        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

        # Avatar
        photo = profile.get('photo')
        photo_thumb_size = request.params.get('photo_thumb_size', '220x150')
        try:
            photo_thumb_size = photo_thumb_size.split('x', 1)
            photo_thumb_size = [int(n) for n in photo_thumb_size]
        except:
            # TODO: add errorcode
            self['error'] = 'Dimensions provided in incorrect format. Should be formatted "100x100"'
            photo_thumb_size = (220,150)

        if photo is not None:
            photo_url = thumb_url(photo, request, tuple(photo_thumb_size))
        else:
            photo_url = request.api.static_url + "/img/default_user.png"
        self["photo"] = photo_url
Exemplo n.º 5
0
def get_gallery_first_thumb_url(context, request, size, default=None):
    from opencore.utilities.image import thumb_url
    gallery = context.get('gallery', {})
    if len(gallery):
        gallery_items = [item for item in gallery.values()]
        ordered_gallery = sorted(gallery_items, key=operator.attrgetter('order'))
        first_item = ordered_gallery[0]
        if getattr(first_item, 'is_image', False):
            # This is an image
            url = thumb_url(first_item, request, size)
        else:
            # This is a video
            url = first_item['thumbnail_url']
    else:
        if default:
            url = request.api.static_url + default
        else:
            url = None
    return url
Exemplo n.º 6
0
    def serialize(self, field, cstruct, readonly=False):
        if cstruct in (null, None):
            cstruct = {}
        if cstruct:
            uid = cstruct['uid']
            if not uid in self.tmpstore:
                self.tmpstore[uid] = cstruct

        template = readonly and self.readonly_template or self.template
        thumbnail_url = None
        params = dict(
                field=field, cstruct=cstruct, thumb_url=thumbnail_url,
                api=self.request.api, context=None, request=self.request
                )
        if hasattr(self, 'context') and hasattr(self, 'request'):
            # We're in an edit form as opposed to an add form
            image = self.context.get(field.name)
            if image is not None:
                params['thumb_url'] = thumb_url(image, self.request, self.thumb_size or (290, 216))
            params['context'] = self.context
        return field.renderer(template, **params)
Exemplo n.º 7
0
 def uri(self):
     if IImage.providedBy(self.context):
         return thumb_url(self.context, self.request, (75,75))    
     return model_url(self.context, self.request)
Exemplo n.º 8
0
 def thumb_url(self, request, size=(46, 46)):
     if "photo" in self:
         return thumb_url(self["photo"], request, size)
     else:
         return request.api.static_url + "/img/default_user.png"
Exemplo n.º 9
0
 def thumb_url(self, image, size=(200, 200)):
     return thumb_url(image, self.request, size)
Exemplo n.º 10
0
def comments_to_display(request, profile_thumb_size=None):
    from opencore.views.people import PROFILE_THUMB_SIZE

    profile_thumb_size = profile_thumb_size or PROFILE_THUMB_SIZE

    def thumb_url(image, request, size):
        """
        Return the url for displaying the image with dimensions bounded by given
        size.
        """
        assert IImage.providedBy(image), "Cannot take thumbnail of non-image."
        return model_url(image, request, 'thumb', '%dx%d.jpg' % size)

    context = request.context
    appdates = getUtility(IAppDates)
    profiles = find_profiles(context)
    api = request.api

     # Convert comments into a digestable form for the template
    comments = []
    if 'comments' not in context:
        return comments

    for comment in context['comments'].values():
        profile = profiles.get(comment.creator)
        author_name = profile.title
        author_url = model_url(profile, request)

        newc = {}
        newc['id'] = comment.__name__
        if has_permission('edit', comment, request):
            newc['edit_url'] = model_url(comment, request, 'edit.html')
            newc['delete_url'] = model_url(comment, request, 'delete.html')
        else:
            newc['edit_url'] = None
            newc['delete_url'] = None

        # Display portrait
        photo = profile.get('photo')
        photo_url = {}
        if photo is not None:
            photo_url = thumb_url(photo, request, profile_thumb_size)
        else:
            photo_url = api.static_url + "/img/default_user.png"
        newc["portrait_url"] = photo_url

        newc['author_url'] = author_url
        newc['author_name'] = author_name
        newc['author_country'] = profile.country
        newc['author_organization'] = profile.organization

        newc['date'] = appdates(comment.created, 'longform')
        newc['timestamp'] = comment.created
        newc['text'] = comment.text
        
        
        
        if( 'IComment' not in api.get_interfaces(comment.__parent__.__parent__) ):
            # this is a level 1 comment
            newc['url'] = model_url(comment.__parent__.__parent__, request) + '#comment-' + comment.__name__
        else :
            # this is a reply
            newc['url'] = model_url(comment.__parent__.__parent__.__parent__.__parent__, request) + '#comment-' + comment.__parent__.__parent__.__name__ + '-' + comment.__name__

        # a bit crude
        if hasattr(api, 'like_count'):
            newc['nlikes'] = api.like_count(comment)

        # Fetch the attachments info
        newc['attachments'] = fetch_attachments(comment, request)

        # handle comment replies
        newc['comment_reply_url'] = model_url(comment, request, 'comment.html')
        replies = []
        if 'comments' in comment:
            for reply in comment['comments'].values():
                newr = {}
                newr['id'] = reply.__name__
                if has_permission('edit', reply, request):
                    newr['edit_url'] = model_url(reply, request, 'edit.html')
                    newr['delete_url'] = model_url(reply, request, 'delete.html')
                else:
                    newr['edit_url'] = None
                    newr['delete_url'] = None
                reply_profile = profiles.get(reply.creator)
                reply_author_name = reply_profile.title
                reply_author_url = model_url(reply_profile, request)
                # Display portrait
                reply_photo = reply_profile.get('photo')
                reply_photo_url = {}
                if reply_photo is not None:
                    reply_photo_url = thumb_url(reply_photo, request, profile_thumb_size)
                else:
                    reply_photo_url = api.static_url + "/img/default_user.png"
                newr["portrait_url"] = reply_photo_url
                newr['author_url'] = reply_author_url
                newr['author_name'] = reply_author_name
                newr['author_country'] = reply_profile.country
                newr['author_organization'] = reply_profile.organization
                newr['date'] = appdates(reply.created, 'longform')
                newr['timestamp'] = reply.created
                newr['text'] = reply.text
                # a bit crude
                if hasattr(api, 'like_count'):
                    newc['nlikes'] = api.like_count(reply)
                replies.append(newr)
            replies.sort(key=lambda x: x['timestamp'])
        newc['comment_replies'] = replies
        comments.append(newc)
    comments.sort(key=lambda x: x['timestamp'])
    return comments
Exemplo n.º 11
0
def show_members_view(context, request):
    """Default view of community members (with/without pictures)."""

    page_title = 'Community Members'
    api = request.api
    api.page_title = page_title

    # Filter the actions based on permission in the **community**
    community = find_interface(context, ICommunity)
    actions = _get_manage_actions(community, request)

    # Did we get the "show pictures" flag?
    hp = request.params.has_key('hide_pictures')
    mu = model_url(context, request)
    submenu = [
        {'label': 'Show Pictures',
         'href': mu, 'make_link': hp},
        {'label': 'Hide Pictures',
         'href': mu + '?hide_pictures', 'make_link': not(hp)},
        ]

    profiles = find_profiles(context)
    member_batch = _member_profile_batch(context, request)
    member_entries = member_batch['entries']
    moderator_names = community.moderator_names

    member_info = []
    for i in range(len(member_entries)):
        derived = {}
        entry = member_entries[i]
        derived['title'] = entry.title
        derived['href'] = model_url(entry, request)
        derived['position'] = entry.position
        derived['organization'] = entry.organization
        derived['phone'] = entry.phone
        derived['department'] = entry.department
        derived['email'] = entry.email
        derived['city'] = entry.location

        photo = entry.get('photo')
        if photo is not None:
            derived['photo_url'] = thumb_url(photo, request,
                                             PROFILE_THUMB_SIZE)
        else:
            derived['photo_url'] = api.static_url + "/img/default_user.png"

        derived['is_moderator'] = entry.__name__ in moderator_names
        # Chameleon's tal:repeat and repeat variable support for
        # things like index is pretty iffy.  Fix the entry info to
        # supply the CSS class information.
        derived['css_class'] = 'photoProfile'
        if derived['is_moderator']:
            derived['css_class'] += ' moderator'
        member_info.append(derived)

    moderator_info = []
    profiles = find_profiles(context)
    for moderator_name in moderator_names:
        if moderator_name in profiles:
            derived = {}
            profile = profiles[moderator_name]
            if not has_permission('view', profile, request):
                continue
            derived['title'] = profile.title
            derived['href'] = model_url(profile, request)
            moderator_info.append(derived)

    return render_template_to_response(
        'templates/show_members.pt',
        api=api,
        actions=actions,
        submenu=submenu,
        moderators=moderator_info,
        members=member_info,
        batch_info=member_batch,
        hide_pictures=hp,
        )