コード例 #1
0
def get_content_links(obj):
    refs = set()
    if ILayoutAware.providedBy(obj):
        behavior_data = ILayoutAware(obj)
        # get data from tile data
        annotations = IAnnotations(obj)
        for key in annotations.keys():
            if key.startswith(ANNOTATIONS_KEY_PREFIX):
                data = annotations[key]
                refs |= get_tile_data_links(obj, data)
        if not behavior_data.contentLayout and behavior_data.content:
            dom = fromstring(behavior_data.content)
            for el in dom.cssselect('.mosaic-text-tile .mosaic-tile-content'):
                links = extractLinks(tostring(el))
                refs |= li.getObjectsFromLinks(obj, links)
    try:
        # scan more than just this we probably should...
        value = obj.text.raw
        links = extractLinks(value)
        refs |= li.getObjectsFromLinks(obj, links)
    except AttributeError:
        pass

    if getattr(obj, 'image'):
        if IReferenceNamedImage.providedBy(obj.image):
            sub_obj = uuidToObject(obj.image.reference)
            if sub_obj:
                objid = get_ref(obj)
                if objid:
                    refs.add(RelationValue(objid))
    return refs
コード例 #2
0
 def get_referenced_image(self, obj):
     if IReferenceNamedImage.providedBy(obj.image):
         catalog = api.portal.get_tool('portal_catalog')
         brains = catalog.unrestrictedSearchResults(
             UID=self.context.image.reference)
         if len(brains) > 0:
             return brains[0].getObject()
コード例 #3
0
    def toFieldValue(self, value):
        widget = self.widget
        req = widget.request
        action = req.get(widget.name + '.action')

        if action == 'remove':
            return self.field.missing_value

        if value is None or value == '':
            return self.get_missing_image()

        if action not in ('nochange', ):
            value = self.getImage(value)

        if not value:
            # another attempt to safe guard
            return self.get_missing_image()

        if not IReferenceNamedImage.providedBy(value):
            # set focal point data
            try:
                fp = [
                    float(req.form.get(widget.name + '.focalX')),
                    float(req.form.get(widget.name + '.focalY'))
                ]
                value.focal_point = fp
                self.widget.context._image_focal_point = fp  # backup in case other doesn't save
            except:
                pass
        return value
コード例 #4
0
ファイル: test_imaging.py プロジェクト: tkimnguyen/castle.cms
 def test_save_image_reference(self):
     context = api.content.create(type='Document', title='foobar2',
                                  container=self.portal)
     widget = self._get_widget()
     converter = self._get_converter(widget)
     result = converter.toFieldValue('reference:' + IUUID(context))
     self.assertTrue(IReferenceNamedImage.providedBy(result))
コード例 #5
0
    def test_add_reference_image(self):
        self.page_obj.text = RichTextValue('''
<p>
<img src="resolveuid/{}/@@images/image/large" />
</p>
        '''.format(self.img_uid),
                                           mimeType='text/html',
                                           outputMimeType='text/html')
        lead.check_lead_image(self.page_obj)
        self.assertTrue(IReferenceNamedImage.providedBy(self.page_obj.image))
        self.assertEquals(self.page_obj.image.reference, self.img_uid)
コード例 #6
0
ファイル: files.py プロジェクト: rnunez80/castle.cms
 def publishTraverse(self, request, name):
     if name == 'image':
         if IReferenceNamedImage.providedBy(self.context.image):
             # auth not setup yet, we just redirect and assume we'll figure the rest out
             catalog = api.portal.get_tool('portal_catalog')
             brains = catalog.unrestrictedSearchResults(
                 UID=self.context.image.reference)
             if len(brains) > 0:
                 brain = brains[0]
                 url = request.ACTUAL_URL.replace(
                     self.context.absolute_url(), brain.getURL())
                 request.response.redirect(url)
                 view = EmptyRedirect(self.context, self.request)
                 return view.__of__(self.context)
     return super(CastleImageScaling, self).publishTraverse(request, name)
コード例 #7
0
 def pattern_options(self):
     result = {
         'reference': None,
         'id': self.id,
         'title': self.title,
         'required': self.required,
         'allow_nochange': self.allow_nochange,
         'name': self.name,
         'disabled': self.disabled,
         'maxlength': self.maxlength
     }
     is_string = isinstance(self.value, basestring)
     if (IReferenceNamedImage.providedBy(self.value)
             or (is_string and self.value.startswith('reference:'))):
         result.update(self.get_reference_options())
     else:
         result.update(self.get_image_options())
     return json.dumps(result)
コード例 #8
0
def get_image_info(brain):
    image_info = None
    if IContentListingObject.providedBy(brain):
        brain = brain._brain
    if IDexterityContent.providedBy(brain):
        obj = brain
        try:
            image = obj.image
            if IReferenceNamedImage.providedBy(image):
                uid = image.reference
                brain = uuidToCatalogBrain(uid)
                if brain:
                    return get_image_info(brain)
                else:
                    return
            width, height = image.getImageSize()
            image_info = {'width': width, 'height': height}
            try:
                image_info['focal_point'] = image.focal_point
            except:
                try:
                    image_info['focal_point'] = obj._image_focal_point
                except:
                    image_info['focal_point'] = [width / 2, height / 2]
        except AttributeError:
            pass
    else:
        try:
            image_info = brain.image_info
            if 'reference' in image_info:
                uid = image_info['reference']
                brain = uuidToCatalogBrain(uid)
                if brain:
                    return get_image_info(brain)
        except:
            pass

    return image_info
コード例 #9
0
ファイル: indexers.py プロジェクト: tkimnguyen/castle.cms
def image_info(obj):
    try:
        image = obj.image
        if IReferenceNamedImage.providedBy(image):
            data = {'reference': image.reference}
        else:
            width, height = image.getImageSize()
            data = {
                'width': width,
                'height': height,
                'focal_point': [width / 2, height / 2]
            }

            try:
                data['focal_point'] = image.focal_point
            except AttributeError:
                try:
                    data['focal_point'] = obj._image_focal_point
                except Exception:
                    pass
        return data
    except AttributeError:
        pass