Commit a2aba894 authored by 's avatar

Added last-modifed and HEAD support

parent 6b633d56
"""Image object"""
__version__='$Revision: 1.29 $'[11:-2]
__version__='$Revision: 1.30 $'[11:-2]
import Globals
from Globals import HTMLFile, MessageDialog
......@@ -8,7 +8,7 @@ from AccessControl.Role import RoleManager
from SimpleItem import Item_w__name__
from Persistence import Persistent
from Acquisition import Implicit
from DateTime import DateTime
class Pdata(Persistent, Implicit):
......@@ -77,18 +77,39 @@ class File(Persistent,Implicit,RoleManager,Item_w__name__):
self.__name__=id
self.title=title
self.size=len(self.data)
self.setLastModifiedHeader()
def id(self): return self.__name__
def getLastModifiedHeader(self):
"""Return a timestamp string representing the last
modification time, in a format that can used in
an HTTP header."""
if hasattr(self, 'hmod'):
return self.hmod
self.hmodified=DateTime().toZone('GMT').rfc822()
return self.hmodified
def setLastModifiedHeader(self, ts=None):
"""Set the timestamp string representing the last
modification time to the given string. The time
stamp string must be expressed in GMT, in rfc822
format. If no string is specified, a timestamp
representing the current time will be used."""
if ts: self.hmodified=ts
else: self.hmodified=DateTime().toZone('GMT').rfc822()
def index_html(self, RESPONSE):
""" """
RESPONSE['content-type']=self.content_type
RESPONSE['content-type'] =self.content_type
RESPONSE['last-modified']=self.getLastModifiedHeader()
return self.data
def manage_edit(self,title,content_type,REQUEST=None):
""" """
self.title=title
self.content_type=content_type
self.setLastModifiedHeader()
if REQUEST: return MessageDialog(
title ='Success!',
message='Your changes have been saved',
......@@ -100,16 +121,25 @@ class File(Persistent,Implicit,RoleManager,Item_w__name__):
data=file.read()
self.data=Pdata(data)
self.size=len(data)
self.setLastModifiedHeader()
if REQUEST: return MessageDialog(
title ='Success!',
message='Your changes have been saved',
action ='manage_main')
HEAD__roles__=None
def HEAD(self, REQUEST, RESPONSE):
""" """
RESPONSE['content-type'] =self.content_type
RESPONSE['last-modified']=self.getLastModifiedHeader()
return ''
PUT__roles__=['Manager']
def PUT(self, BODY, REQUEST):
'handle PUT requests'
self.data=Pdata(BODY)
self.size=len(BODY)
self.setLastModifiedHeader()
try:
type=REQUEST['CONTENT_TYPE']
if type: self.content_type=type
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment