当前位置: 首页>>代码示例>>Python>>正文


Python IProfile.providedBy方法代码示例

本文整理汇总了Python中karl.models.interfaces.IProfile.providedBy方法的典型用法代码示例。如果您正苦于以下问题:Python IProfile.providedBy方法的具体用法?Python IProfile.providedBy怎么用?Python IProfile.providedBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在karl.models.interfaces.IProfile的用法示例。


在下文中一共展示了IProfile.providedBy方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: visit

# 需要导入模块: from karl.models.interfaces import IProfile [as 别名]
# 或者: from karl.models.interfaces.IProfile import providedBy [as 别名]
    def visit(self, context):
        if IProfile.providedBy(context):
            users = find_users(context)
            person = self._get_person(context.__name__)
            person['first_last'] = ' '.join(
                (context.firstname, context.lastname))
            person['create_date'] = context.created
            person['is_staff'] = users.member_of_group(
                context.__name__, 'group.KarlStaff')
            person['location'] = context.location
            person['department'] = context.department

            tags = find_tags(context)
            person['tags'] = len(tags.getTags(users=[context.__name__]))

        elif ICommunity.providedBy(context):
            for id in context.member_names:
                self._get_person(id)['membership'] += 1
            for id in context.moderator_names:
                self._get_person(id)['communities_moderator'] += 1

        else:
            creator = getattr(context, 'creator', None)
            if creator is not None:
                person = self._get_person(creator)
                person['content_created'] += 1
                if context.created > self.one_month_ago:
                    person['created_this_month'] += 1
开发者ID:boothead,项目名称:karl,代码行数:30,代码来源:generate_stats.py

示例2: get_groups

# 需要导入模块: from karl.models.interfaces import IProfile [as 别名]
# 或者: from karl.models.interfaces.IProfile import providedBy [as 别名]
def get_groups(obj, default):
    if not IProfile.providedBy(obj):
        return default
    users = find_users(obj)
    user = users.get_by_id(obj.__name__)
    if user:
        return user.get('groups', default)
    return default
开发者ID:boothead,项目名称:karl,代码行数:10,代码来源:peopledirectory.py

示例3: __call__

# 需要导入模块: from karl.models.interfaces import IProfile [as 别名]
# 或者: from karl.models.interfaces.IProfile import providedBy [as 别名]
 def __call__(self, obj, default):
     if not IProfile.providedBy(obj):
         return default
     categories = getattr(obj, 'categories', None)
     if not categories:
         return default
     values = categories.get(self.catid)
     if not values:
         return default
     return values
开发者ID:boothead,项目名称:karl,代码行数:12,代码来源:peopledirectory.py

示例4: index_profile

# 需要导入模块: from karl.models.interfaces import IProfile [as 别名]
# 或者: from karl.models.interfaces.IProfile import providedBy [as 别名]
def index_profile(obj, event):
    """ Index profile (an IObjectAddedEvent subscriber) """
    catalog = find_peopledirectory_catalog(obj)
    if catalog is not None:
        for node in postorder(obj):
            if IProfile.providedBy(node):
                path = resource_path(node)
                docid = getattr(node, 'docid', None)
                if docid is None:
                    docid = node.docid = catalog.document_map.add(path)
                else:
                    catalog.document_map.add(path, docid)
                catalog.index_doc(docid, node)
开发者ID:hj91,项目名称:karl,代码行数:15,代码来源:subscribers.py

示例5: reindex_peopledirectory

# 需要导入模块: from karl.models.interfaces import IProfile [as 别名]
# 或者: from karl.models.interfaces.IProfile import providedBy [as 别名]
def reindex_peopledirectory(peopledir):
    catalog = peopledir.catalog
    document_map = catalog.document_map
    profiles = find_profiles(peopledir)
    for obj in profiles.values():
        if IProfile.providedBy(obj):
            path = model_path(obj)
            docid = document_map.docid_for_address(path)
            if not docid:
                docid = document_map.add(path)
                catalog.index_doc(docid, obj)
            else:
                catalog.reindex_doc(docid, obj)
开发者ID:boothead,项目名称:karl,代码行数:15,代码来源:peopledirectory.py

示例6: get_lastname_firstletter

# 需要导入模块: from karl.models.interfaces import IProfile [as 别名]
# 或者: from karl.models.interfaces.IProfile import providedBy [as 别名]
def get_lastname_firstletter(obj, default):
    if not IProfile.providedBy(obj):
        return default
    return obj.lastname[:1].upper()
开发者ID:boothead,项目名称:karl,代码行数:6,代码来源:peopledirectory.py

示例7: manage_communities_view

# 需要导入模块: from karl.models.interfaces import IProfile [as 别名]
# 或者: from karl.models.interfaces.IProfile import providedBy [as 别名]
def manage_communities_view(context, request):
    assert IProfile.providedBy(context)

    page_title = 'Manage Communities'
    api = TemplateAPI(context, request, page_title)

    users = find_users(context)
    communities_folder = find_communities(context)
    userid = context.__name__

    # Handle cancel
    if request.params.get("form.cancel", False):
        return HTTPFound(location=resource_url(context, request))

    # Handle form submission
    if request.params.get("form.submitted", False):
        for key in request.params:
            if key.startswith("leave_"):
                community_name = key[6:]
                community = communities_folder[community_name]

                # Not concerned about catching this exception, since checkbox
                # should not have been displayed in form unless user allowed
                # to leave.  Assert merely guards integrity of the system.
                assert may_leave(userid, community)

                if userid in community.moderator_names:
                    users.remove_group(userid, community.moderators_group_name)
                if userid in community.member_names:
                    users.remove_group(userid, community.members_group_name)

            elif key.startswith("alerts_pref_"):
                community_name = key[12:]
                preference = int(request.params.get(key))
                context.set_alerts_preference(community_name, preference)

        context.alert_attachments = request.params.get('attachments', 'link')

        path = resource_url(context, request)
        msg = '?status_message=Community+preferences+updated.'
        return HTTPFound(location=path+msg)

    # XXX Iterating over every community in the system isn't a particularly
    #     efficient solution.  Should use catalog.
    communities = []
    for community in communities_folder.values():
        if (userid in community.member_names or
            userid in community.moderator_names):
            alerts_pref = context.get_alerts_preference(community.__name__)
            display_community = {
                'name': community.__name__,
                'title': community.title,
                'alerts_pref': [
                    { "value": IProfile.ALERT_IMMEDIATELY,
                      "label": "Immediately",
                      "selected": alerts_pref == IProfile.ALERT_IMMEDIATELY,
                    },
                    { "value": IProfile.ALERT_DIGEST,
                      "label": "Digest",
                      "selected": alerts_pref == IProfile.ALERT_DIGEST,
                    },
                    { "value": IProfile.ALERT_NEVER,
                      "label": "Never",
                      "selected": alerts_pref == IProfile.ALERT_NEVER,
                    }],
                'may_leave': may_leave(userid, community),
            }
            communities.append(display_community)

    if len(communities) > 1:
        communities.sort(key=lambda x: x["title"])

    return render_to_response(
        'karl.views:templates/manage_communities.pt',
        dict(api=api,
             communities=communities,
             post_url=request.url,
             formfields=api.formfields,
             attachments=context.alert_attachments),
        request=request,
    )
开发者ID:claytron,项目名称:karl,代码行数:83,代码来源:people.py

示例8: get_member_name

# 需要导入模块: from karl.models.interfaces import IProfile [as 别名]
# 或者: from karl.models.interfaces.IProfile import providedBy [as 别名]
def get_member_name(object, default):
    if not IProfile.providedBy(object):
        return default
    return ('%s %s' % (object.firstname, object.lastname)).lower()
开发者ID:karlproject,项目名称:karl,代码行数:6,代码来源:site.py

示例9: get_lastfirst

# 需要导入模块: from karl.models.interfaces import IProfile [as 别名]
# 或者: from karl.models.interfaces.IProfile import providedBy [as 别名]
def get_lastfirst(object, default):
    if not IProfile.providedBy(object):
        return default
    return ("%s, %s" % (object.lastname, object.firstname)).lower()
开发者ID:hj91,项目名称:karl,代码行数:6,代码来源:site.py

示例10: batch_images

# 需要导入模块: from karl.models.interfaces import IProfile [as 别名]
# 或者: from karl.models.interfaces.IProfile import providedBy [as 别名]
def batch_images(context, request,
                 get_image_info=get_image_info, # unittest
                 get_images_batch=get_images_batch): # unittest

    include_image_url = request.params.get('include_image_url', None)
    # include_image_url is a special case.
    include_info = None
    if include_image_url is not None:
        # Note, we must use the path only, as IE submits the full domain
        # and without the next line IE would fail.
        path = urlparse.urlparse(include_image_url)[2]
        include_context = traverse(context, path)['context']
        if IImage.providedBy(include_context):
            # We have a good image to include.
            include_info = get_image_info(include_context, request)

    # Find query parameters based on the 'source' param,
    # which signifies the selection index of the source button
    # in the imagedrawer dialog.
    source = request.params.get('source')
    assert source in ('myrecent', 'thiscommunity', 'allkarl')

    if source == 'myrecent':
        creator = authenticated_userid(request)
        community_path = None
    elif source == 'thiscommunity':
        # If we're editing a profile, show that user's images
        if IProfile.providedBy(context):
            creator = context.__name__
            community = None
        else:
            creator = None
            community = find_community(context)
        # batching api requires the community path
        if community:
            community_path = resource_path(community)
        else:
            community_path = None
    else:               # All Karl
        creator = None
        community_path = None

    # batching
    # Decide start and size here, don't let the lower levels
    # apply their default. This allows us to enforce
    # a MINIMAL_BATCH size.
    batch_start = int(request.params.get('start', '0'))
    batch_size = int(request.params.get('limit', '0'))
    # there is a minimal batch size to enforce, if the client
    # does not ask for one
    # Just pass the values to lower levels where sensible
    # defaults will be applied.
    sort_index = request.params.get('sort_on', None)
    reverse = request.params.get('reverse', None)

    # XXX include_image will now be inserted in the first
    # position, as extra image.
    insert_extra = False
    if include_info is not None:
        if batch_start == 0:
            batch_size -= 1
            insert_extra = True
        else:
            batch_start -= 1

    # Enforce the minimal batch size
    batch_size = max(batch_size, MINIMAL_BATCH)

    search_params = dict(
        creator=creator,
        community=community_path,
        batch_start=batch_start,
        batch_size=batch_size,
    )
    if sort_index:
        search_params['sort_index'] = sort_index
    if reverse:
        search_params['reverse'] = bool(int(reverse))

    batch_info = get_images_batch(
        context,
        request,
        **search_params
    )

    records = [get_image_info(image, request)
               for image in batch_info['entries']]
    start = batch_info['batch_start']
    totalRecords = batch_info['total']

    # add the fake included image
    if include_info is not None:
        totalRecords += 1
        if insert_extra:
            records.insert(0, include_info)
        else:
            start += 1

    return dict(
        records = records,
#.........这里部分代码省略.........
开发者ID:araymund,项目名称:karl,代码行数:103,代码来源:imagedrawer.py


注:本文中的karl.models.interfaces.IProfile.providedBy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。