Beispiel #1
0
    def _data(self):
        """Returns a list of all pending subscription requests, adding the URL,
        description and title of the Section they're for.
        """
        query = {
            'object_provides': ISubscribableSection.__identifier__,
            'sort_on': 'sortable_title',
        }
        results = self.catalog.unrestrictedSearchResults(**query)
        all_requests = []
        for brain in results:
            section = brain.getObject()
            if getSecurityManager().checkPermission(permissions.ManagePortal,
                                                    section):
                manager = SubscriptionsManager(section)
                requests = manager.getRequests()
                for r in requests:
                    r['title'] = brain.Title
                    r['description'] = brain.Description
                    r['url'] = brain.getURL()
                    all_requests.append(r)

        if all_requests:
            all_requests.sort(self._compareRequestDates)

        return all_requests
Beispiel #2
0
class RequestSubscription(BrowserView):
    """View for requesting Section subscription.
    """
    def __init__(self, *args, **kwargs):
        super(RequestSubscription, self).__init__(*args, **kwargs)
        self.manager = SubscriptionsManager(self.context)

    def __call__(self, *args, **kwargs):
        """Handle subscription request.

        If the context is an Open Section, approve immediately.

        If the context is a Closed Section, send approval and redirect to
        "My Subscriptions" (where the request will show).
        """
        user_id = self.context.portal_membership.getAuthenticatedMember().id
        if IOpenSection.providedBy(self.context):
            message = self.manager.immediatelySubscribeMember(user_id)
            addStatus(self.request, message)
            self.request.RESPONSE.redirect(self.context.absolute_url())
        else:
            if IClosedSection.providedBy(self.context):
                message = self.manager.addRequest(user_id)
                addStatus(self.request, message)
                redirect_url = self.context.portal_url(
                ) + '/@@my-subscriptions'
                self.request.RESPONSE.redirect(redirect_url)
            else:
                message = """The folder is marked as a Subscribable
Section, but doesn't seem to be of the type Closed Section 
or Open Section."""
                raise Exception(message)
class RequestSubscription(BrowserView):
    """View for requesting Section subscription.
    """

    def __init__(self, *args, **kwargs):
        super(RequestSubscription, self).__init__(*args, **kwargs)
        self.manager = SubscriptionsManager(self.context)

    def __call__(self, *args, **kwargs):
        """Handle subscription request.

        If the context is an Open Section, approve immediately.

        If the context is a Closed Section, send approval and redirect to
        "My Subscriptions" (where the request will show).
        """
        user_id = self.context.portal_membership.getAuthenticatedMember().id
        if IOpenSection.providedBy(self.context):
            message = self.manager.immediatelySubscribeMember(user_id)
            addStatus(self.request, message)        
            self.request.RESPONSE.redirect(self.context.absolute_url())
        else:
            if IClosedSection.providedBy(self.context):
                message = self.manager.addRequest(user_id)
                addStatus(self.request, message)
                redirect_url = self.context.portal_url() + '/@@my-subscriptions'
                self.request.RESPONSE.redirect(redirect_url)
            else:
                message = """The folder is marked as a Subscribable
Section, but doesn't seem to be of the type Closed Section 
or Open Section."""
                raise Exception(message)
Beispiel #4
0
    def data(self):
        """Return a dictionary of requests and subscriptions.

        mydict = {
            'requests': [
                {   'title': '',
                    'url': '',
                    'description': '',
                },
            ],
            'subscriptions': [
                # the same...
            ],
        }
        """

        user_id = self.mtool.getAuthenticatedMember().id
        mydict = {
            'requests': [],
            'subscriptions': [],
        }
        query = {
            'object_provides': ISubscribableSection.__identifier__,
            'sort_on': 'sortable_title',
            'full_objects': True,
        }

        # Use ZCatalog so ALL results are found, this is even more
        # unrestricted than portal_catalog.unrestrictedSearchResults
        brains = ZCatalog.searchResults(self.catalog, None, **query)
        for brain in brains:
            title = brain.Title
            url = brain.getURL()
            description = brain.Description
            relative_path = brain.getPath().split('/')[2:]

            obj = self.site.unrestrictedTraverse(relative_path)
            sm = SubscriptionsManager(obj)

            if sm.checkRequestForUser(user_id):
                mydict['requests'].append({
                    'title': title,
                    'url': url,
                    'description': description,
                })
            if sm.checkSubscriptionForUser(user_id):
                mydict['subscriptions'].append({
                    'title': title,
                    'url': url,
                    'description': description,
                })

        return mydict
    def data(self):
        """Return a dictionary of requests and subscriptions.

        mydict = {
            'requests': [
                {   'title': '',
                    'url': '',
                    'description': '',
                },
            ],
            'subscriptions': [
                # the same...
            ],
        }
        """

        user_id = self.mtool.getAuthenticatedMember().id
        mydict = {
            'requests': [],
            'subscriptions': [],
        }
        query = {
            'object_provides': ISubscribableSection.__identifier__,
            'sort_on' : 'sortable_title',
            'full_objects': True,
            }

        # Use ZCatalog so ALL results are found, this is even more
        # unrestricted than portal_catalog.unrestrictedSearchResults
        brains = ZCatalog.searchResults(self.catalog, None, **query)
        for brain in brains:
            title = brain.Title
            url = brain.getURL()
            description = brain.Description
            relative_path = brain.getPath().split('/')[2:]

            obj = self.site.unrestrictedTraverse(relative_path)
            sm = SubscriptionsManager(obj)

            if sm.checkRequestForUser(user_id):
                mydict['requests'].append({
                    'title': title, 'url': url, 'description': description,
                    })
            if sm.checkSubscriptionForUser(user_id):
                mydict['subscriptions'].append({
                    'title': title, 'url': url, 'description': description,
                    })

        return mydict
    def _data(self):
        """Returns a list of all pending subscription requests, adding the URL,
        description and title of the Section they're for.
        """
        query = {"object_provides": ISubscribableSection.__identifier__, "sort_on": "sortable_title"}
        results = self.catalog.unrestrictedSearchResults(**query)
        all_requests = []
        for brain in results:
            section = brain.getObject()
            if getSecurityManager().checkPermission(permissions.ManagePortal, section):
                manager = SubscriptionsManager(section)
                requests = manager.getRequests()
                for r in requests:
                    r["title"] = brain.Title
                    r["description"] = brain.Description
                    r["url"] = brain.getURL()
                    all_requests.append(r)

        if all_requests:
            all_requests.sort(self._compareRequestDates)

        return all_requests
Beispiel #7
0
 def __init__(self, *args, **kwargs):
     super(ManageSubscriptions, self).__init__(*args, **kwargs)
     self.manager = SubscriptionsManager(self.context)
     self.messages = IStatusMessage(self.request)
Beispiel #8
0
class ManageSubscriptions(BrowserView):
    """View and manage requests and subscriptions.
    """
    def __init__(self, *args, **kwargs):
        super(ManageSubscriptions, self).__init__(*args, **kwargs)
        self.manager = SubscriptionsManager(self.context)
        self.messages = IStatusMessage(self.request)

    def requests(self):
        return self.manager.getRequests()

    def subscriptions(self):
        return self.manager.getSubscriptions()

    def table_data(self):
        """Used to generate the form and parse it.
        """
        tables = {
            'requests': {
                'button_name':
                'form.button.requests',
                'columns': [
                    {
                        'id': 'approve',
                        'name': _(u'Approve request')
                    },
                    {
                        'id': 'remove',
                        'name': _(u'Remove request')
                    },
                ],
            },
            'subscriptions': {
                'button_name': 'form.button.subscriptions',
                'columns': [
                    {
                        'id': 'remove',
                        'name': _(u'Remove subscription')
                    },
                ],
            },
        }
        return tables

    def processForm(self):
        form = self.request.form
        table_data = self.table_data()
        # check for submitted form: button name should match the one in table
        # data
        button_names = [ table_data[key]['button_name'] for key in \
                                                                table_data.keys() ]
        if len(set(form.keys()) & set(button_names)) > 0:
            # process requests
            if form.has_key(table_data['requests']['button_name']):
                # approve subscription requests
                for user_id in form.get('users.id.approve', []):
                    message = self.manager.confirmSubscription(user_id)
                    addStatus(self.request, message)
                # remove subscription requests
                for user_id in form.get('users.id.remove', []):
                    message = self.manager.removeRequest(user_id)
                    addStatus(self.request, message)
            if form.has_key(table_data['subscriptions']['button_name']):
                # remove subscriptions
                for user_id in form.get('users.id.remove', []):
                    message = self.manager.removeSubscription(user_id)
                    addStatus(self.request, message)
            # redirect in order to show status message
            self.request.RESPONSE.redirect(self.request.URL)
        else:
            # no form submitted, do nothing
            pass
Beispiel #9
0
 def __init__(self, *args, **kwargs):
     super(RequestSubscription, self).__init__(*args, **kwargs)
     self.manager = SubscriptionsManager(self.context)
 def __init__(self, *args, **kwargs):
     super(RequestSubscription, self).__init__(*args, **kwargs)
     self.manager = SubscriptionsManager(self.context)
class ManageSubscriptions(BrowserView):
    """View and manage requests and subscriptions.
    """
        
    def __init__(self, *args, **kwargs):
        super(ManageSubscriptions, self).__init__(*args, **kwargs)
        self.manager = SubscriptionsManager(self.context)
        self.messages = IStatusMessage(self.request)

    def requests(self):
        return self.manager.getRequests()

    def subscriptions(self):
        return self.manager.getSubscriptions()

    def table_data(self):
        """Used to generate the form and parse it.
        """
        tables = {  
            'requests': {
                'button_name': 'form.button.requests', 
                'columns': [
                    {   'id': 'approve', 
                        'name': _(u'Approve request')},
                    {   'id': 'remove', 
                        'name': _(u'Remove request')},
                    ],
                },
            'subscriptions': {
                'button_name': 'form.button.subscriptions', 
                'columns': [
                    {   'id': 'remove', 
                        'name': _(u'Remove subscription')},
                ],
            },
        }
        return tables

    def processForm(self):
        form = self.request.form
        table_data = self.table_data()
        # check for submitted form: button name should match the one in table 
        # data
        button_names = [ table_data[key]['button_name'] for key in \
                                                                table_data.keys() ]
        if len(set(form.keys()) & set(button_names)) > 0:
            # process requests
            if form.has_key(table_data['requests']['button_name']):
                # approve subscription requests
                for user_id in form.get('users.id.approve', []):
                    message = self.manager.confirmSubscription(user_id)
                    addStatus(self.request, message)
                # remove subscription requests
                for user_id in form.get('users.id.remove', []):
                    message = self.manager.removeRequest(user_id)
                    addStatus(self.request, message)
            if form.has_key(table_data['subscriptions']['button_name']):
                # remove subscriptions
                for user_id in form.get('users.id.remove', []):
                    message = self.manager.removeSubscription(user_id)
                    addStatus(self.request, message)
            # redirect in order to show status message
            self.request.RESPONSE.redirect(self.request.URL)
        else:
            # no form submitted, do nothing
            pass
 def __init__(self, *args, **kwargs):
     super(ManageSubscriptions, self).__init__(*args, **kwargs)
     self.manager = SubscriptionsManager(self.context)
     self.messages = IStatusMessage(self.request)