FSForm.py 3.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
import Globals
from AccessControl import ClassSecurityInfo

try:
    import Products.FileSystemSite
except ImportError:
    # use CMF product
    from Products.CMFCore.CMFCorePermissions import View
    from Products.CMFCore.FSObject import FSObject
    from Products.CMFCore.DirectoryView import registerFileExtension,\
                                               registerMetaType, expandpath
else:
    # use FileSystemSite product
    from Products.FileSystemSite.Permissions import View
    from Products.FileSystemSite.FSObject import FSObject
    from Products.FileSystemSite.DirectoryView import registerFileExtension,\
                                                      registerMetaType, expandpath

from Products.Formulator.Form import ZMIForm
from Products.Formulator.XMLToForm import XMLToForm

class FSForm(FSObject, ZMIForm):
    """FSForm."""

    meta_type = 'Filesystem Formulator Form'

    manage_options = (
        (
        {'label':'Customize', 'action':'manage_main'},
        {'label':'Test', 'action':'formTest'},
        )
        )

    _updateFromFS = FSObject._updateFromFS

    security = ClassSecurityInfo()
    security.declareObjectProtected(View)

    def __init__(self, id, filepath, fullname=None, properties=None):
        FSObject.__init__(self, id, filepath, fullname, properties)

    def _createZODBClone(self):
        # not implemented yet
        return None

    def _readFile(self, reparse):
        file = open(expandpath(self._filepath), 'rb')
        try:
            data = file.read()
        finally:
            file.close()

        # update the form with the xml data
        try:
            XMLToForm(data, self)
        except:
            # bare except here, but I hope this is ok, as the
            # exception should be reraised
            # (except if the LOG raises another one ...
            # should we be more paranoid here?)
            import zLOG
            zLOG.LOG(
                'Formulator.FSForm', zLOG.ERROR,
                'error reading form from file ' +
                expandpath(self._filepath))
            raise

    #### The following is mainly taken from Form.py ACCESSORS section ###

##     def get_field_ids(self):
##         self._updateFromFS()
##         return ZMIForm.get_field_ids(self)

##     def get_fields_in_group(self, group):
##         self._updateFromFS()
##         return ZMIForm.get_fields_in_group(self, group)

##     def has_field(self, id):
##         self._updateFromFS()
##         return ZMIForm.has_field(self, id)

##     def get_field(self, id):
##         self._updateFromFS()
##         return ZMIForm.get_field(self, id)

##     def get_groups(self):
##         self._updateFromFS()
##         return ZMIForm.get_groups(self)

##     def get_form_encoding(self):
##         self._updateFromFS()
##         return ZMIForm.get_form_encoding(self)

##     def header(self):
##         self._updateFromFS()
##         return ZMIForm.header(self)

##     def get_xml(self):
##         self._updateFromFS()
##         return ZMIForm.get_xml(self)

##     def all_meta_types(self):
##         self._updateFromFS()
##         return ZMIForm.all_meta_types(self)

##     security.declareProtected('View management screens', 'get_group_rows')
##     def get_group_rows(self):
##         self._updateFromFS()
##         return ZMIForm.get_group_rows(self)

Globals.InitializeClass(FSForm)

registerFileExtension('form', FSForm)
registerMetaType('FSForm', FSForm)