allow for images that exceed maximum allowed widht or height if the total number of pixels does not exceed a limit given as the third element in the list for 'media.unauthorized_max_size'

This commit is contained in:
Helmut Merz 2011-09-22 08:51:35 +02:00
parent 9562417644
commit 2709f73f94
2 changed files with 15 additions and 7 deletions

View file

@ -48,7 +48,7 @@ from loops.browser.concept import BaseRelationView, ConceptRelationView
from loops.browser.concept import ConceptConfigureView
from loops.browser.node import NodeView, node_macros
from loops.common import adapted, NameChooser
from loops.interfaces import IBaseResource, IDocument, IMediaAsset, ITextDocument
from loops.interfaces import IBaseResource, IDocument, ITextDocument
from loops.interfaces import IMediaAsset as legacy_IMediaAsset
from loops.interfaces import ITypeConcept
from loops.media.interfaces import IMediaAsset
@ -179,13 +179,21 @@ class ResourceView(BaseView):
# if self.adapted.isProtected():
# raise Unauthorized()
context = self.context
ct = context.contentType
response = self.request.response
self.recordAccess('show', target=self.uniqueId)
if ct.startswith('image/'):
#response.setHeader('Cache-Control', 'public,max-age=86400')
response.setHeader('Cache-Control', 'max-age=86400')
adobj = adapted(context)
if IMediaAsset.providedBy(adobj):
from loops.media.browser.asset import MediaAssetView
view = MediaAssetView(context, self.request)
return view.show(useAttachment)
ti = IType(context).typeInterface
if ti is not None:
context = ti(context)
data = context.data
response = self.request.response
ct = context.contentType
if useAttachment:
filename = adapted(self.context).localFilename or getName(self.context)
filename = NameChooser(getParent(self.context)).normalizeName(filename)
@ -195,9 +203,6 @@ class ResourceView(BaseView):
if ct.startswith('text/') and not useAttachment:
response.setHeader('Content-Type', 'text/html')
return self.renderText(data, ct)
if ct.startswith('image/') and not useAttachment:
#response.setHeader('Cache-Control', 'public,max-age=86400')
response.setHeader('Cache-Control', 'max-age=86400')
response.setHeader('Content-Type', ct)
# set Last-Modified header
modified = self.modifiedRaw

View file

@ -76,9 +76,12 @@ class MediaAssetView(ResourceView):
maxSize = self.typeOptions('media.unauthorized_max_size')
if maxSize:
(w, h) = self.adapted.getImageSize(data=data)
if len(maxSize) > 2 and maxSize[2]:
if w * h <= int(maxSize[2]): # number of pixels
return True
if w > int(maxSize[0]):
return False
if len(maxSize) > 1 and h > int(maxSize[1]):
if len(maxSize) > 1 and maxSize[1] and h > int(maxSize[1]):
return False
return True