예제 #1
0
    def test_get_cache_expires(self):
        # cache enabled disabled by default
        out = get_cache_expires(sys.modules[__name__])
        assert out == -1, out

        ckan.lib.cache.cache_enabled = True
        out = get_cache_expires(sys.modules[__name__])
        assert out == 1800, out

        out = get_cache_expires(self.test_get_cache_expires)
        assert out == 3600, out

        # no match, so use config default_expires
        out = get_cache_expires(ckan.lib.cache)
        assert out == 200, out
예제 #2
0
    def test_get_cache_expires(self):
        # cache enabled disabled by default
        out = get_cache_expires(sys.modules[__name__])
        assert out == -1, out

        ckan.lib.cache.cache_enabled = True
        out = get_cache_expires(sys.modules[__name__])
        assert out == 1800, out

        out = get_cache_expires(self.test_get_cache_expires)
        assert out == 3600, out

        # no match, so use config default_expires
        out = get_cache_expires(ckan.lib.cache)
        assert out == 200, out
예제 #3
0
파일: home.py 프로젝트: okfn/ckan-old
import random
import sys

from pylons import cache, config
from genshi.template import NewTextTemplate

from ckan.authz import Authorizer
from ckan.i18n import set_session_locale
from ckan.lib.search import query_for, QueryOptions, SearchError
from ckan.lib.cache import proxy_cache, get_cache_expires
from ckan.lib.base import *
import ckan.lib.stats

cache_expires = get_cache_expires(sys.modules[__name__])

class HomeController(BaseController):
    repo = model.repo   

    authorizer = Authorizer()

    @proxy_cache(expires=cache_expires)
    def index(self):
        query = query_for(model.Package)
        query.run(query='*:*', facet_by=g.facets,
                  limit=0, offset=0, username=c.user)
        c.facets = query.facets
        c.fields = []
        c.package_count = query.count
        c.latest_packages = self.authorizer.authorized_query(c.user, model.Package)\
            .join('revision').order_by(model.Revision.timestamp.desc())\
            .limit(5).all()
예제 #4
0
import sys
from datetime import datetime, timedelta

from pylons.i18n import get_lang

from ckan.lib.base import *
from ckan.lib.helpers import Page
import ckan.authz
from ckan.lib.cache import proxy_cache, get_cache_expires
cache_expires = get_cache_expires(sys.modules[__name__])


class RevisionController(BaseController):
    def __before__(self, action, **env):
        BaseController.__before__(self, action, **env)
        c.revision_change_state_allowed = (
            c.user and self.authorizer.is_authorized(
                c.user, model.Action.CHANGE_STATE, model.Revision))
        if not self.authorizer.am_authorized(c, model.Action.SITE_READ,
                                             model.System):
            abort(401, _('Not authorized to see this page'))

    def index(self):
        return self.list()

    def list(self):
        format = request.params.get('format', '')
        if format == 'atom':
            # Generate and return Atom 1.0 document.
            from webhelpers.feedgenerator import Atom1Feed
            feed = Atom1Feed(