Beispiel #1
0
def get_valid_objects(brains):
    """Generate a list of objects associated with valid brains."""
    for b in brains:
        try:
            obj = b.getObject()
        except KeyError:
            obj = None

        if obj is None:  # warn on broken entries in the catalog
            logger.warn('Invalid reference in the catalog: ' + b.getPath())
            continue
        yield obj
    def get_data(self, url, maxwidth=None, maxheight=None, format='json'):
        """Return the data provided by the endpoint."""

        consumer = component.getUtility(IConsumer)
        json_data = None
        try:
            json_data = consumer.get_data(
                url, maxwidth=None, maxheight=None, format='json')
        except HTTPError, e:
            if e.code == 401:
                api.portal.show_message(
                    _(u'Unauthorized request'), request=self.request, type='error')
            elif e.code == 404:
                api.portal.show_message(
                    _(u'URL not found'), request=self.request, type='error')
            else:
                logger.warn(e)
Beispiel #3
0
    def get_data(self, url, maxwidth=None, maxheight=None, format='json'):
        """Return the data provided by the endpoint."""

        consumer = component.getUtility(IConsumer)
        json_data = None
        try:
            json_data = consumer.get_data(
                url, maxwidth=None, maxheight=None, format='json')
        except HTTPError, e:
            if e.code == 401:
                api.portal.show_message(
                    _(u'Unauthorized request'), request=self.request, type='error')
            elif e.code == 404:
                api.portal.show_message(
                    _(u'URL not found'), request=self.request, type='error')
            else:
                logger.warn(e)
Beispiel #4
0
class BaseForm(DexterityExtensibleForm):
    """
    """

    tr_fields = {
        'width': 'width',
        'height': 'height',
        'description': 'IDublinCore.description',
        'title': 'IDublinCore.title',
        'html': 'embed_html'
    }

    def set_image(self, url):
        opener = urllib2.build_opener()
        try:
            response = opener.open(url)
            self.widgets['image'].url = url
            self.widgets['image'].value = ImageValueType(
                data=response.read(), filename=url.split('/')[-1])
            self.request['form.widgets.image.action'] = u'load'
        except:
            pass

    def get_data(self, url, maxwidth=None, maxheight=None, format='json'):
        """Return the data provided by the endpoint."""

        consumer = component.getUtility(IConsumer)
        json_data = None
        try:
            json_data = consumer.get_data(url,
                                          maxwidth=None,
                                          maxheight=None,
                                          format='json')
        except HTTPError, e:
            if e.code == 401:
                api.portal.show_message(_(u'Unauthorized request'),
                                        request=self.request,
                                        type='error')
            elif e.code == 404:
                api.portal.show_message(_(u'URL not found'),
                                        request=self.request,
                                        type='error')
            else:
                logger.warn(e)
        except URLError, e:
            # support offline mode
            logger.warn('offline mode')