from Products.Five import BrowserView
from Products.FiveFeeds.interfaces import ISyndicationPolicy

class SyndicationView(BrowserView):

    def syndicationAllowed(self, site=False):
        """Check whether syndication is allows on the context

        Based on Plone's rssAllows.py PythonScript
        """
        policy = ISyndicationPolicy(self.context)
        allowed = True
        if not site and not policy.syndicationAllowed:
            allowed = False
        if site and not policy.siteSyndicationAllowed:
            allowed = False
        # really we should be raising an HTTP error, something that
        # rss news readers would understand
        if not allowed:
            raise ValueError, "Site syndication via RSS feeds is not " \
                  "allowed. Ask the sites system administrator to go to " \
                  "portal_syndication > Policies and enable syndication. "\
                  "Each folder then needs to have syndication enabled."
        return allowed

    def syndicatableContent(self):
        policy = ISyndicationPolicy(self.context)
        return policy.syndicatableContent

    def updateBase(self):
        """Return the date of the last update in HTML4 form as a string"""
        policy = ISyndicationPolicy(self.context)
        return policy.updateBase
