if lang is not None: lang_before, lang_set = field._v_lang, 1 field.setLanguage(lang) try: handler = IImageScaleHandler(field, None) if handler is not None: image = handler.getScale(self.context, scale) finally: if lang_set: field.setLanguage(lang_before) if image is not None: return image return self.fallback(request, name) from plone.app.imaging.traverse import ImageTraverser ImageTraverser.publishTraverse = publishTraverse LOG.info("plone.app.imaging.traverse.ImageTraverser.publishTraverse patched") def scale(self, fieldname=None, scale=None, **parameters): field = self.context.getField(fieldname) if IMultilanguageField.providedBy(field): fieldname = '%s___%s___' % (fieldname, field._v_lang or field._getCurrentLanguage(getSite())) return self.__old_scale(fieldname, scale, **parameters) from plone.app.imaging.scaling import ImageScaling ImageScaling.__old_scale = ImageScaling.scale ImageScaling.scale = scale LOG.info("plone.app.imaging.scaling.ImageScaling.scale patched") except ImportError: pass
except AttributeError: encoding = 'ascii' for v in data: try: value = json.loads(v) value = value['___multilanguage___'] v = value.get(lang, '') if isinstance(v, basestring): v = v.encode(encoding) except: pass ndata.append(v) Record.__init__(self, tuple(ndata)) CatalogBrains.AbstractCatalogBrain.__old_init__ = CatalogBrains.AbstractCatalogBrain.__init__ CatalogBrains.AbstractCatalogBrain.__init__ = __new_init__ LOG.info("Products.ZCatalog.CatalogBrains.AbstractCatalogBrain.__init__ patched") # catalog monkey patch to support languageaware metadata def __new_recordify(self, object): """ turns an object into a record tuple """ record = [] # the unique id is always the first element for x in self.names: attr=getattr(object, x, MV) if(attr is not MV and safe_callable(attr)): try: attr = attr(lang='all') if isinstance(attr, dict): attr = json.dumps(dict(___multilanguage___ = attr)) except: attr = attr()
image = field.getScale(self, scale=scale) else: image = field.getScale(self) if not image: # language fallback defaultLang = field.getDefaultLang(self) if defaultLang and not defaultLang == lang: field.setLanguage(defaultLang) if scale: if scale in field.getAvailableSizes(self): image = field.getScale(self, scale=scale) else: image = field.getScale(self) if image is not None: if last and REQUEST.get('HTTP_USER_AGENT', False): _scale = scale if _scale is not None: _scale = '_'+str(_scale) else: _scale = '' REQUEST.RESPONSE.redirect(self.absolute_url()+'/'+fieldname+'___'+defaultLang+'___'+_scale) finally: field.setLanguage(lang_before) if image is not None and not isinstance(image, basestring): # image might be None or '' for empty images return image return BaseObject.__bobo_traverse__(self, REQUEST, name) from Products.ATContentTypes.content.image import ATImage ATImage.__bobo_traverse__ = __bobo_traverse__ LOG.info("Products.ATContentTypes.content.image.ATImage.__bobo_traverse__ patched")
for v in data: try: value = json.loads(v) value = value['___multilanguage___'] v = value.get(lang, '') if isinstance(v, basestring): v = v.encode(encoding) except: pass ndata.append(v) Record.__init__(self, tuple(ndata)) CatalogBrains.AbstractCatalogBrain.__old_init__ = CatalogBrains.AbstractCatalogBrain.__init__ CatalogBrains.AbstractCatalogBrain.__init__ = __new_init__ LOG.info( "Products.ZCatalog.CatalogBrains.AbstractCatalogBrain.__init__ patched") # catalog monkey patch to support languageaware metadata def __new_recordify(self, object): """ turns an object into a record tuple """ record = [] # the unique id is always the first element for x in self.names: attr = getattr(object, x, MV) if (attr is not MV and safe_callable(attr)): try: attr = attr(lang='all') if isinstance(attr, dict): attr = json.dumps(dict(___multilanguage___=attr)) except:
ATCTFileContent.__old__index_html = ATCTFileContent.index_html def __new__index_html(self, REQUEST=None, RESPONSE=None): """Make it directly viewable when entering the objects URL """ field = self.getPrimaryField() if not IBlobField.providedBy(field) and IMultilanguageField.providedBy(field): if REQUEST is None and hasattr(self, 'REQUEST'): REQUEST = self.REQUEST if REQUEST is not None and not 'lang' in REQUEST.keys(): url = REQUEST['ACTUAL_URL'] url += urlparse(url).query and '&' or '?' url += 'lang='+field._getCurrentLanguage(self) return REQUEST.response.redirect(url) return self.__old__index_html(REQUEST, RESPONSE) ATCTFileContent.index_html = __new__index_html LOG.info("Products.ATContentTypes.content.base.ATCTFileContent.index_html patched") # Archetypes ATCTFileContent post_validate monkey patch to prevent # CopyError when adding a file or image with a filename which already # exists in the folder ATCTFileContent.__old__post_validate = ATCTFileContent.post_validate def __new__post_validate(self, REQUEST=None, errors=None): """Validates upload file and id """ field = self.getPrimaryField() if IMultilanguageField.providedBy(field): lang = field._v_lang try: field.setLanguage(field.getDefaultLang(self)) REQUEST.form['%s_file' % field.__name__] = REQUEST.form.get('%s_file' % field.getName()) finally:
from Products.Archetypes.BaseObject import BaseObject from Products.ATContentTypes.content.file import ATFile from raptus.multilanguagefields.interfaces import IMultilanguageField def setImage(self, value, **kw): if kw.has_key('schema'): schema = kw['schema'] else: schema = self.Schema() kw['schema'] = schema return schema['image'].set(self, value, **kw) from plone.app.blob.mixins import ImageMixin ImageMixin.setImage = setImage LOG.info("plone.app.blob.mixins.ImageMixin.setImage patched") def setFile(self, value, **kw): if kw.has_key('schema'): schema = kw['schema'] else: schema = self.Schema() kw['schema'] = schema return schema['file'].set(self, value, **kw) ATBlob.setFile = setFile LOG.info("plone.app.blob.content.ATBlob.setFile patched") def __blob__bobo_traverse__(self, REQUEST, name): """ helper to access multilanguage image scales the old way during `unrestrictedTraverse` calls
""" field = self.getPrimaryField() if not IBlobField.providedBy(field) and IMultilanguageField.providedBy( field): if REQUEST is None and hasattr(self, 'REQUEST'): REQUEST = self.REQUEST if REQUEST is not None and not 'lang' in REQUEST.keys(): url = REQUEST['ACTUAL_URL'] url += urlparse(url).query and '&' or '?' url += 'lang=' + field._getCurrentLanguage(self) return REQUEST.response.redirect(url) return self.__old__index_html(REQUEST, RESPONSE) ATCTFileContent.index_html = __new__index_html LOG.info( "Products.ATContentTypes.content.base.ATCTFileContent.index_html patched") # Archetypes ATCTFileContent post_validate monkey patch to prevent # CopyError when adding a file or image with a filename which already # exists in the folder ATCTFileContent.__old__post_validate = ATCTFileContent.post_validate def __new__post_validate(self, REQUEST=None, errors=None): """Validates upload file and id """ field = self.getPrimaryField() if IMultilanguageField.providedBy(field): lang = field._v_lang try: field.setLanguage(field.getDefaultLang(self))