Ejemplo n.º 1
0
def jquery_edit_preferred_view(context, request):
    request.response_headerlist = [('Cache-Control',
        'max-age=0, no-cache, no-store, private, must-revalidate')]
    communities_folder = find_communities(context)
    communities = get_my_communities(communities_folder,
                                     request,
                                     ignore_preferred=True)
    preferred = get_preferred_communities(communities_folder, request)
    return { 'my_communities': communities,
             'preferred': preferred }
Ejemplo n.º 2
0
def jquery_list_preferred_view(context, request):
    request.response_headerlist = [('Cache-Control',
        'max-age=0, no-cache, no-store, private, must-revalidate')]
    communities_folder = find_communities(context)
    communities = get_my_communities(communities_folder, request)
    preferred = get_preferred_communities(communities_folder, request)
    return { 'my_communities': communities,
             'preferred': preferred,
             'show_all': False,
             'profile': None,
             'status_message': None}
Ejemplo n.º 3
0
def jquery_set_preferred_view(context, request):
    request.response_headerlist = [('Cache-Control',
        'max-age=0, no-cache, no-store, private, must-revalidate')]
    communities_folder = find_communities(context)
    communities = request.params.getall('preferred[]')
    set_preferred_communities(communities_folder, request, communities)
    updated_communities = get_my_communities(communities_folder, request)
    return { 'my_communities': updated_communities,
             'preferred': communities,
             'show_all': False,
             'profile': None,
             'status_message': 'Set preferred communities.'}
Ejemplo n.º 4
0
def get_user_home(context, request):
    # Respect user's home_path, if set
    home, extra_path = _get_user_home_path(context, request)
    if home is not None:
        return home, extra_path

    # If user is member of only one community, home is that community
    communities = find_communities(context)
    community_names = get_user_community_names(context, request)
    if len(community_names) == 1:
        community = communities.get(community_names.pop(), None)
        if community is not None:
            return community, []

    return communities, []
Ejemplo n.º 5
0
    def __call__(self):

        profile_details = getUtility(IProfileDict, name='profile-details')
        profile_details.update_details(self.context, self.request, self.api,
                                       self.photo_thumb_size)

        context = self.context
        request = self.request
        api = self.api

        # provide client data for rendering current tags in the tagbox
        client_json_data = dict(
            tagbox = get_tags_client_data(context, request),
            )

        # Get communities this user is a member of, along with moderator info
        #
        communities = {}
        communities_folder = find_communities(context)
        user_info = find_users(context).get_by_id(context.__name__)
        if user_info is not None:
            for group in user_info["groups"]:
                if group.startswith("group.community:"):
                    unused, community_name, role = group.split(":")
                    if (communities.has_key(community_name) and
                        role != "moderators"):
                        continue

                    community = communities_folder.get(community_name, None)
                    if community is None:
                        continue

                    if has_permission('view', community, request):
                        communities[community_name] = {
                            "title": community.title,
                            "moderator": role == "moderators",
                            "url": model_url(community, request),
                        }

        communities = communities.values()
        communities.sort(key=lambda x:x["title"])

        preferred_communities = []
        my_communities = None
        name = context.__name__
        # is this the current user's profile?
        if authenticated_userid(request) == name:
            preferred_communities = get_preferred_communities(communities_folder,
                                                              request)
            my_communities = get_my_communities(communities_folder, request)

        tagger = find_tags(context)
        if tagger is None:
            tags = ()
        else:
            tags = []
            names = tagger.getTags(users=[context.__name__])
            for name, count in sorted(tagger.getFrequency(names,
                                                          user=context.__name__),
                                      key=lambda x: x[1],
                                      reverse=True,
                                     )[:10]:
                tags.append({'name': name, 'count': count})



        self.profile = profile_details
        self.communities = communities
        self.my_communities = my_communities or []
        self.preferred_communities = preferred_communities
        self.tags = tags
        self.actions = get_profile_actions(context,request)
        self.head_data = convert_to_script(client_json_data)
        return self.make_response()