Exemplo n.º 1
0
    def data(self):
        # Get the Europe dataset
        rootdir = get_root_dir()
        data_file = os.path.join(rootdir, 'ckanext', 'offenedaten', 'data', 'eu.json')
        f = open(data_file, 'r')
        o = json.load(f)

        # Get the package count by country
        q = Session.query(
                distinct(PackageExtra.value),
                func.count(PackageExtra.value)
            ).\
                filter(PackageExtra.key == u'eu_country').\
                group_by(PackageExtra.value)

        values = dict(q.all())
        # Set the package count for each country
        
        for ft in o['features']:
            code = ft['properties']['NUTS']
            ft['properties']['packages'] = (values.get(code, 0))

        response.content_type = 'application/json'
        response.pragma = None
        response.cache_control = 'public; max-age: 3600'
        response.cache_expires(seconds=3600)
        return json.dumps(o)
Exemplo n.º 2
0
    def data(self):
        # Get the Europe dataset
        rootdir = get_root_dir()
        data_file = os.path.join(rootdir, 'ckanext', 'pdeu', 'data', 'eu.json')
        f = open(data_file, 'r')
        o = json.load(f)

        # Get the package count by country
        q = Session.query(
                distinct(PackageExtra.value),
                func.count(PackageExtra.value)
            ).\
                filter(PackageExtra.key == u'eu_country').\
                group_by(PackageExtra.value)

        values = dict(q.all())
        # Set the package count for each country

        for ft in o['features']:
            code = ft['properties']['NUTS']
            ft['properties']['packages'] = (values.get(code, 0))

        response.content_type = 'application/json'
        response.pragma = None
        response.cache_control = 'public; max-age: 3600'
        response.cache_expires(seconds=3600)
        return json.dumps(o)
Exemplo n.º 3
0
        image = ApplicationImage.by_id(id)
        handle = Image.open(StringIO(image.data))
        if not image:
            abort(404)
        response.content_type = 'image/png'
        outfh = StringIO()
        try:
            if x is not None and y is not None:
                size = (int(x), int(y))
                handle = ImageOps.fit(handle, size, Image.ANTIALIAS, 0.01, (0.0, 0.0))
        except ValueError, e:
            pass
        handle.save(outfh, 'PNG')
        response.pragma = None 
        response.cache_control = 'public; max-age: 84600'
        response.cache_expires(seconds=84600)
        return outfh.getvalue()

    def delete(self, id):
        if not self.authz.am_authorized(c, Action.PURGE, System()):
            abort(401, _('Unauthorized to delete application'))
        delete_application(id)
        return redirect('/apps')

    def edit(self, id, data={}, errors={}, error_summary={}):
        c.auth_for_update = self.authorizer.am_authorized(c, Action.CHANGE_STATE, System())
        if not c.auth_for_update:
            abort(401, _('Unauthorized to edit application'))
        c.app = Application.by_name(id)
        if c.app is None:
            abort(404)