source: products/quintagroup.pingtool/trunk/quintagroup/pingtool/browser/ping.py @ 3665

Last change on this file since 3665 was 626, checked in by crchemist, 18 years ago

Modified tests.

File size: 2.0 KB
Line 
1from Acquisition import aq_inner
2from zope.annotation.interfaces import IAnnotations
3from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
4from Products.Five import BrowserView
5from Products.CMFCore.utils import getToolByName
6
7from quintagroup.pingtool.interfaces import ISyndicationObject
8
9class RunPingView(BrowserView):
10    """A class with helper methods for use in views/templates.
11    """
12    def __call__(self):
13        context = aq_inner(self.context)
14        annotations = IAnnotations(self.context)
15        portal = getToolByName(self.context, 'portal_url').getPortalObject()
16        pp = getToolByName(portal, 'portal_pingtool', None)
17
18        if pp:
19            status, message = pp.pingFeedReader(context)
20            portal_message, ping_message = message['portal_message'], message['return_message']
21            annotations['ping_message'] = ping_message
22            state = self.get_state(status)
23            portal.plone_utils.addPortalMessage(portal_message, state)
24
25            if state == "warning":
26                self.request.response.redirect(context.absolute_url()+'/base_edit')
27            else:
28                self.request.response.redirect('@@return_ping')
29
30    def get_state(self, status):
31        if status == 'success':
32            state = 'info'
33        elif status == 'failed':
34            state = 'warning'
35        else:
36            state = 'info'
37        return state
38
39
40class CanPingView(BrowserView):
41    """A class with helper methods for use in views/templates.
42    """
43    def __call__(self):
44        return ISyndicationObject.providedBy(self.context) and \
45                  (hasattr(self.context, 'enable_ping') and self.context.enable_ping or False)
46
47
48class ReturnPingView(BrowserView):
49    """A class with helper methods for use in views/templates.
50    """
51    template = ViewPageTemplateFile('return_ping.pt')
52
53    def __call__(self):
54        annotations = IAnnotations(self.context)
55        self.ping_message = annotations['ping_message']
56        return self.template()
Note: See TracBrowser for help on using the repository browser.