Ejemplo n.º 1
0
    def tabs(self):
        if self._tabs is None:

            found_current = False

            overview_css_class = ''

            if ( ICommunity.providedBy(self.request.context) and
                 self.request.view_name in ['','view.html'] ):
                overview_css_class = 'curr'
                found_current = True

            tabs = [
                {'url':model_url(self.context, self.request, 'view.html'),
                 'css_class':overview_css_class,
                 'name':'OVERVIEW'}
                ]

            for toolinfo in get_listitems(IToolFactory):
                toolfactory = toolinfo['component']
                if toolfactory.is_present(self.context, self.request):
                    info = {}
                    info['url'] = toolfactory.tab_url(self.context,
                                                      self.request)
                    info['css_class'] = ''
                    if not found_current:
                        if toolfactory.is_current(self.context, self.request):
                            info['css_class'] = 'curr'
                            found_current = True
                    info['name'] = toolinfo['title'].upper()
                    tabs.append(info)

            self._tabs = tabs

        return self._tabs
Ejemplo n.º 2
0
def redirect_community_view(context, request):
    assert ICommunity.providedBy(context), str(type(context))

    default_tool = getattr(context, 'default_tool', None)
    if not default_tool:
        default_tool = 'view.html'
    return HTTPFound(location=model_url(context, request, default_tool))
Ejemplo n.º 3
0
def community_recent_items_ajax_view(context, request):
    assert ICommunity.providedBy(context), str(type(context))

    recent_items = []
    recent_items_batch = get_recent_items_batch(context, request, 5)
    for item in recent_items_batch["entries"]:
        adapted = getMultiAdapter((item, request), IGridEntryInfo)
        recent_items.append(adapted)

    return {'items': recent_items}
Ejemplo n.º 4
0
def community_members_ajax_view(context, request):
    assert ICommunity.providedBy(context), str(type(context))

    members = []
    members_batch = get_members_batch(context, request, 5)
    for item in members_batch:
        adapted = getMultiAdapter((item, request), IGridEntryInfo)
        adapted.moderator = item.__name__ in context.moderator_names
        members.append(adapted)

    return {'items': members}
Ejemplo n.º 5
0
    def __call__(self):

        # Either terms or at least one topic must be provided to guard
        # against abuses.
        has_topic = self.request.params.get('topics')
        has_terms = self.request.params.get('body')
        has_country = self.request.params.get('country')

        if not(has_topic or has_terms or has_country):
            msg = "Expected at least one search term, a topic or a country, returning HTTP 404"
            log.error(msg)
            return not_found(self.context, self.request)

        # Get the name of the tab or assume it's a 'General' one in case
        # the parameter's missing.
        tab = self.request.params.get('tab')
        if not tab:
            tab = 'general'

        if not tab in self.tabs_allowed:
            msg = "GET 'tab' must be one of %s not [%s], returning HTTP 404" % (
                self.tabs_allowed, tab)
            log.error(msg)
            return not_found(self.context, self.request)

        page_title = 'Search results'

        api = self.request.api
        api.page_title = page_title
        if ICommunity.providedBy(self.context):
            layout = api.community_layout
            community = self.context.title
        else:
            layout = api.generic_layout
            community = None

        batch = None
        terms = ()
        error = None

        try:
            search_interfaces = self.tabs_to_interfaces[tab]
            batch, terms = get_batch(self.context, self.request, search_interfaces,
                                     self.pre_batch_filter)
        except ParseError, e:
            error = 'Error: %s' % e
Ejemplo n.º 6
0
def show_community_view(context, request):
    assert ICommunity.providedBy(context), str(type(context))

    user = authenticated_userid(request)
    page_title = 'View Community ' + context.title
    api = request.api
    api.page_title = page_title

    # provide client data for rendering current tags in the tagbox
    tagquery = getMultiAdapter((context, request), ITagQuery)
    client_json_data = {'tagbox': {'docid': tagquery.docid,
                                   'records': tagquery.tagswithcounts,
                                  },
                       }

    # Filter the actions based on permission
    actions = []
    if has_permission(MODERATE, context, request):
        actions.append(('Edit', 'edit.html'))

    # If user has permission to see this view then has permission to join.
    if not(user in context.member_names or user in context.moderator_names):
        actions.append(('Join', 'join.html'))

    if has_permission(DELETE_COMMUNITY, context, request):
        actions.append(('Delete', 'delete.html'))

    recent_items = []
    recent_items_batch = get_recent_items_batch(context, request)
    for item in recent_items_batch["entries"]:
        adapted = getMultiAdapter((item, request), IGridEntryInfo)
        recent_items.append(adapted)

    feed_url = model_url(context, request, "atom.xml")

    return {'api': api,
            'actions': actions,
            'recent_items': recent_items,
            'batch_info': recent_items_batch,
            'head_data': convert_to_script(client_json_data),
            'feed_url': feed_url,
           }
Ejemplo n.º 7
0
def related_communities_ajax_view(context, request):
    assert ICommunity.providedBy(context), str(type(context))

    related = []
    principals = effective_principals(request)
    searcher = ICatalogSearch(context)
    search = ' OR '.join(context.title.lower().split())
    total, docids, resolver = searcher(interfaces=[ICommunity],
                                       limit=5,
                                       reverse=True,
                                       sort_index="modified_date",
                                       texts=search,
                                       allowed={'query': principals,
                                                'operator': 'or'},
                                      )
    for docid in docids:
        model = resolver(docid)
        if model is not None:
            if model is not context:
                adapted = getMultiAdapter((model, request), IGridEntryInfo)
                related.append(adapted)

    return {'items': related}
Ejemplo n.º 8
0
 def __init__(self, context, request):
     assert ICommunity.providedBy(context)
     super(CommunityAtomFeed, self).__init__(context, request)
Ejemplo n.º 9
0
def join_community_view(context, request):
    """ User sends an email to community moderator(s) asking to join
    the community.  Email contains a link to "add_existing" view, in members,
    that a moderator can use to add member to the community.

    """
    assert ICommunity.providedBy(context)

    # Get logged in user
    profiles = find_profiles(context)
    user = authenticated_userid(request)
    profile = profiles[user]

    # Handle form submission
    if "form.submitted" in request.POST:
        message = request.POST.get("message", "")
        moderators = [profiles[id] for id in context.moderator_names]
        mail = Message()
        mail["From"] = "%s <%s>" % (profile.title, profile.email)
        mail["To"] = ",".join(
            ["%s <%s>" % (p.title, p.email) for p in moderators]
        )
        mail["Subject"] = "Request to join %s community" % context.title

        body_template = get_template("templates/email_join_community.pt")
        profile_url = model_url(profile, request)
        accept_url=model_url(context, request, "members", "add_existing.html",
                             query={"user_id": user})
        body = body_template(
            message=message,
            community_title=context.title,
            person_name=profile.title,
            profile_url=profile_url,
            accept_url=accept_url
        )

        if isinstance(body, unicode):
            body = body.encode("UTF-8")

        mail.set_payload(body, "UTF-8")
        mail.set_type("text/html")

        recipients = [p.email for p in moderators]
        mailer = getUtility(IMailDelivery)
        mailer.send(profile.email, recipients, mail)

        status_message = "Your request has been sent to the moderators."
        location = model_url(context, request,
                             query={"status_message": status_message})

        return HTTPFound(location=location)

    # Show form
    page_title = "Join " + context.title
    api = request.api
    api.page_title = page_title
    return render_template_to_response(
        "templates/join_community.pt",
        api=api,
        profile=profile,
        community=context,
        post_url=model_url(context, request, "join.html"),
        formfields=api.formfields,
    )