From 2b907fee32c50f164462e05b7024f24504d919eb Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Fri, 30 Oct 2009 21:31:39 +0100 Subject: [PATCH] Improvement in xhtml->odt conversion (pod) + new search param for appy root classes and param 'indexed' for fields. --- gen/__init__.py | 113 +- gen/plone25/descriptors.py | 19 +- gen/plone25/generator.py | 10 + gen/plone25/mixins/__init__.py | 7 +- gen/plone25/skin/import.pt | 3 +- gen/plone25/skin/macros.pt | 6 +- pod/test/Tests.rtf | 3177 +++++++++++++------------- pod/test/contexts/XhtmlComplex4.py | 44 + pod/test/results/xhtmlComplex4.odt | Bin 0 -> 39156 bytes pod/test/templates/XhtmlComplex4.odt | Bin 0 -> 7730 bytes pod/xhtml2odt.py | 6 +- 11 files changed, 1742 insertions(+), 1643 deletions(-) create mode 100644 pod/test/contexts/XhtmlComplex4.py create mode 100644 pod/test/results/xhtmlComplex4.odt create mode 100755 pod/test/templates/XhtmlComplex4.odt diff --git a/gen/__init__.py b/gen/__init__.py index 9fbb92f..5861997 100755 --- a/gen/__init__.py +++ b/gen/__init__.py @@ -28,11 +28,20 @@ class Import: self.columnHeaders = columnHeaders self.sortMethod = sortMethod +class Search: + '''Used for specifying a search for a given type.''' + def __init__(self, name, sortBy='title', limit=None, **fields): + self.name = name + self.sortBy = sortBy + self.limit = limit + self.fields = fields # This is a dict whose keys are indexed field + # names and whosse values are search values. + # ------------------------------------------------------------------------------ class Type: '''Basic abstract class for defining any appy type.''' def __init__(self, validator, multiplicity, index, default, optional, - editDefault, show, page, group, move, searchable, + editDefault, show, page, group, move, indexed, searchable, specificReadPermission, specificWritePermission, width, height, master, masterValue, focus): # The validator restricts which values may be defined. It can be an @@ -48,7 +57,8 @@ class Type: # strings (thus creating a dictionary of values instead of a list), # specify a type specification for the index, like Integer() or # String(). Note that this concept of "index" has nothing to do with - # the concept of "database index". + # the concept of "database index" (see fields "indexed" and + # "searchable" below). self.index is not yet used. self.index = index # Default value self.default = default @@ -68,8 +78,11 @@ class Type: # The following attribute allows to move a field back to a previous # position (useful for content types that inherit from others). self.move = move - # If specified "searchable", the field will be referenced in low-level - # indexing mechanisms for fast access and search functionalities. + # If indexed is True, a database index will be set on the field for + # fast access. + self.indexed = indexed + # If specified "searchable", the field will be added to some global + # index allowing to perform application-wide, keyword searches. self.searchable = searchable # Normally, permissions to read or write every attribute in a type are # granted if the user has the global permission to read or @@ -108,12 +121,12 @@ class Type: class Integer(Type): def __init__(self, validator=None, multiplicity=(0,1), index=None, default=None, optional=False, editDefault=False, show=True, - page='main', group=None, move=0, searchable=False, - specificReadPermission=False, specificWritePermission=False, - width=None, height=None, master=None, masterValue=None, - focus=False): + page='main', group=None, move=0, indexed=False, + searchable=False, specificReadPermission=False, + specificWritePermission=False, width=None, height=None, + master=None, masterValue=None, focus=False): Type.__init__(self, validator, multiplicity, index, default, optional, - editDefault, show, page, group, move, False, + editDefault, show, page, group, move, indexed, False, specificReadPermission, specificWritePermission, width, height, master, masterValue, focus) self.pythonType = long @@ -121,12 +134,12 @@ class Integer(Type): class Float(Type): def __init__(self, validator=None, multiplicity=(0,1), index=None, default=None, optional=False, editDefault=False, show=True, - page='main', group=None, move=0, searchable=False, - specificReadPermission=False, specificWritePermission=False, - width=None, height=None, master=None, masterValue=None, - focus=False): + page='main', group=None, move=0, indexed=False, + searchable=False, specificReadPermission=False, + specificWritePermission=False, width=None, height=None, + master=None, masterValue=None, focus=False): Type.__init__(self, validator, multiplicity, index, default, optional, - editDefault, show, page, group, move, False, + editDefault, show, page, group, move, indexed, False, specificReadPermission, specificWritePermission, width, height, master, masterValue, focus) self.pythonType = float @@ -178,12 +191,12 @@ class String(Type): XHTML = 2 def __init__(self, validator=None, multiplicity=(0,1), index=None, default=None, optional=False, editDefault=False, format=LINE, - show=True, page='main', group=None, move=0, searchable=False, - specificReadPermission=False, specificWritePermission=False, - width=None, height=None, master=None, masterValue=None, - focus=False): + show=True, page='main', group=None, move=0, indexed=False, + searchable=False, specificReadPermission=False, + specificWritePermission=False, width=None, height=None, + master=None, masterValue=None, focus=False): Type.__init__(self, validator, multiplicity, index, default, optional, - editDefault, show, page, group, move, searchable, + editDefault, show, page, group, move, indexed, searchable, specificReadPermission, specificWritePermission, width, height, master, masterValue, focus) self.format = format @@ -204,12 +217,12 @@ class String(Type): class Boolean(Type): def __init__(self, validator=None, multiplicity=(0,1), index=None, default=None, optional=False, editDefault=False, show=True, - page='main', group=None, move=0, searchable=False, - specificReadPermission=False, specificWritePermission=False, - width=None, height=None, master=None, masterValue=None, - focus=False): + page='main', group=None, move=0, indexed=False, + searchable=False, specificReadPermission=False, + specificWritePermission=False, width=None, height=None, + master=None, masterValue=None, focus=False): Type.__init__(self, validator, multiplicity, index, default, optional, - editDefault, show, page, group, move, searchable, + editDefault, show, page, group, move, indexed, searchable, specificReadPermission, specificWritePermission, width, height, master, masterValue, focus) self.pythonType = bool @@ -221,13 +234,13 @@ class Date(Type): def __init__(self, validator=None, multiplicity=(0,1), index=None, default=None, optional=False, editDefault=False, format=WITH_HOUR, startYear=time.localtime()[0]-10, - endYear=time.localtime()[0]+10, - show=True, page='main', group=None, move=0, searchable=False, + endYear=time.localtime()[0]+10, show=True, page='main', + group=None, move=0, indexed=False, searchable=False, specificReadPermission=False, specificWritePermission=False, width=None, height=None, master=None, masterValue=None, focus=False): Type.__init__(self, validator, multiplicity, index, default, optional, - editDefault, show, page, group, move, searchable, + editDefault, show, page, group, move, indexed, searchable, specificReadPermission, specificWritePermission, width, height, master, masterValue, focus) self.format = format @@ -237,12 +250,12 @@ class Date(Type): class File(Type): def __init__(self, validator=None, multiplicity=(0,1), index=None, default=None, optional=False, editDefault=False, show=True, - page='main', group=None, move=0, searchable=False, - specificReadPermission=False, specificWritePermission=False, - width=None, height=None, master=None, masterValue=None, - focus=False, isImage=False): + page='main', group=None, move=0, indexed=False, + searchable=False, specificReadPermission=False, + specificWritePermission=False, width=None, height=None, + master=None, masterValue=None, focus=False, isImage=False): Type.__init__(self, validator, multiplicity, index, default, optional, - editDefault, show, page, group, move, False, + editDefault, show, page, group, move, indexed, False, specificReadPermission, specificWritePermission, width, height, master, masterValue, focus) self.isImage = isImage @@ -253,12 +266,12 @@ class Ref(Type): editDefault=False, add=False, link=True, unlink=False, back=None, isBack=False, show=True, page='main', group=None, showHeaders=False, shownInfo=(), wide=False, select=None, - maxPerPage=30, move=0, searchable=False, + maxPerPage=30, move=0, indexed=False, searchable=False, specificReadPermission=False, specificWritePermission=False, width=None, height=None, master=None, masterValue=None, focus=False): Type.__init__(self, validator, multiplicity, index, default, optional, - editDefault, show, page, group, move, False, + editDefault, show, page, group, move, indexed, False, specificReadPermission, specificWritePermission, width, height, master, masterValue, focus) self.klass = klass @@ -283,12 +296,13 @@ class Ref(Type): class Computed(Type): def __init__(self, validator=None, multiplicity=(0,1), index=None, default=None, optional=False, editDefault=False, show=True, - page='main', group=None, move=0, searchable=False, - specificReadPermission=False, specificWritePermission=False, - width=None, height=None, method=None, plainText=True, - master=None, masterValue=None, focus=False): + page='main', group=None, move=0, indexed=False, + searchable=False, specificReadPermission=False, + specificWritePermission=False, width=None, height=None, + method=None, plainText=True, master=None, masterValue=None, + focus=False): Type.__init__(self, None, multiplicity, index, default, optional, - False, show, page, group, move, False, + False, show, page, group, move, indexed, False, specificReadPermission, specificWritePermission, width, height, master, masterValue, focus) self.method = method # The method used for computing the field value @@ -302,12 +316,13 @@ class Action(Type): tool class. An action is rendered as a button.''' def __init__(self, validator=None, multiplicity=(1,1), index=None, default=None, optional=False, editDefault=False, show=True, - page='main', group=None, move=0, searchable=False, - specificReadPermission=False, specificWritePermission=False, - width=None, height=None, action=None, result='computation', - master=None, masterValue=None, focus=False): + page='main', group=None, move=0, indexed=False, + searchable=False, specificReadPermission=False, + specificWritePermission=False, width=None, height=None, + action=None, result='computation', master=None, + masterValue=None, focus=False): Type.__init__(self, None, (0,1), index, default, optional, - False, show, page, group, move, False, + False, show, page, group, move, indexed, False, specificReadPermission, specificWritePermission, width, height, master, masterValue, focus) self.action = action # Can be a single method or a list/tuple of methods @@ -351,12 +366,12 @@ class Info(Type): (text, html...) to the user.''' def __init__(self, validator=None, multiplicity=(1,1), index=None, default=None, optional=False, editDefault=False, show=True, - page='main', group=None, move=0, searchable=False, - specificReadPermission=False, specificWritePermission=False, - width=None, height=None, master=None, masterValue=None, - focus=False): + page='main', group=None, move=0, indexed=False, + searchable=False, specificReadPermission=False, + specificWritePermission=False, width=None, height=None, + master=None, masterValue=None, focus=False): Type.__init__(self, None, (0,1), index, default, optional, - False, show, page, group, move, False, + False, show, page, group, move, indexed, False, specificReadPermission, specificWritePermission, width, height, master, masterValue, focus) diff --git a/gen/plone25/descriptors.py b/gen/plone25/descriptors.py index 09555d1..70f80c8 100644 --- a/gen/plone25/descriptors.py +++ b/gen/plone25/descriptors.py @@ -11,7 +11,7 @@ from utils import stringify import appy.gen import appy.gen.descriptors from appy.gen.po import PoMessage -from appy.gen import Date, String, State, Transition, Type +from appy.gen import Date, String, State, Transition, Type, Search from appy.gen.utils import GroupDescr, PageDescr, produceNiceMessage TABS = 4 # Number of blanks in a Python indentation. @@ -433,10 +433,10 @@ class ArchetypesClassDescriptor(ClassDescriptor): self.name = self.getClassName(klass) self.generateSchema() + @staticmethod def getClassName(klass): '''Generates the name of the corresponding Archetypes class.''' return klass.__module__.replace('.', '_') + '_' + klass.__name__ - getClassName = staticmethod(getClassName) def isAbstract(self): '''Is self.klass abstract?''' @@ -475,6 +475,21 @@ class ArchetypesClassDescriptor(ClassDescriptor): res = self.isFolder(theClass.__bases__[0]) return res + @staticmethod + def getSearches(klass): + '''Returns the list of searches that are defined on this class.''' + res = [] + if klass.__dict__.has_key('search'): + searches = klass.__dict__['search'] + if isinstance(searches, basestring): res.append(Search(searches)) + elif isinstance(searches, Search): res.append(searches) + else: + # It must be a list of searches. + for search in searches: + if isinstance(search, basestring):res.append(Search(search)) + else: res.append(search) + return res + def addGenerateDocMethod(self): m = self.methods spaces = TABS diff --git a/gen/plone25/generator.py b/gen/plone25/generator.py index 1454b40..4872212 100644 --- a/gen/plone25/generator.py +++ b/gen/plone25/generator.py @@ -675,6 +675,16 @@ class Generator(AbstractGenerator): poMsgDescr = PoMessage('%s_%d_edit_descr' % (classDescr.name, i), '', ' ') self.labels.append(poMsgDescr) + # Remember i18n labels for searches + for search in classDescr.getSearches(classDescr.klass): + searchLabelId = '%s_search_%s' % (classDescr.name, search.name) + searchDescrId = '%s_descr' % searchLabelId + for label in (searchLabelId, searchDescrId): + default = ' ' + if label == searchLabelId: default = search.name + poMsg = PoMessage(label, '', default) + poMsg.produceNiceDefault() + self.labels.append(poMsg) # Generate the resulting Archetypes class and schema. self.copyFile('ArchetypesTemplate.py', repls, destName=fileName) diff --git a/gen/plone25/mixins/__init__.py b/gen/plone25/mixins/__init__.py index 5f2e715..ffe7475 100644 --- a/gen/plone25/mixins/__init__.py +++ b/gen/plone25/mixins/__init__.py @@ -319,11 +319,10 @@ class AbstractMixin: if isinstance(fieldDescr, FieldDescr): fieldDescr = fieldDescr.__dict__ appyType = fieldDescr['appyType'] - if isEdit and (appyType['type']=='Ref') and appyType['add']: - return False + if isEdit and (appyType['type']=='Ref') and appyType['add']:return False + if isEdit and appyType['type']=='Action': return False if (fieldDescr['widgetType'] == 'backField') and \ - not self.getBRefs(fieldDescr['fieldRel']): - return False + not self.getBRefs(fieldDescr['fieldRel']): return False # Do not show field if it is optional and not selected in flavour if appyType['optional']: tool = self.getTool() diff --git a/gen/plone25/skin/import.pt b/gen/plone25/skin/import.pt index 73b39fd..85e493d 100644 --- a/gen/plone25/skin/import.pt +++ b/gen/plone25/skin/import.pt @@ -26,9 +26,10 @@ function toggleViewableElements() { var rows = cssQuery('#importedElem'); var newDisplay = 'table-row'; + if (isIe) newDisplay = 'block'; if (importedElemsShown) newDisplay = 'none'; for (var i=0; i
-
+ @@ -175,7 +176,7 @@ - + @@ -311,6 +312,7 @@ "Static" javascripts