Skip to content

Commit

Permalink
Merge branch 'github-main' of github.com:plomino/Plomino into jean-ge…
Browse files Browse the repository at this point in the history
…tColumnRender

Conflicts:
	Products/CMFPlomino/PlominoColumn.py
  • Loading branch information
jean committed Sep 20, 2013
2 parents f9520b2 + c001c20 commit b917401
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 31 deletions.
1 change: 1 addition & 0 deletions Products/CMFPlomino/PlominoColumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from Products.Archetypes.atapi import *
from zope.interface import implements
import interfaces
import Missing

from Products.CMFDynamicViewFTI.browserdefault import BrowserDefaultMixin

Expand Down
1 change: 1 addition & 0 deletions Products/CMFPlomino/PlominoField.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ def processInput(self, submittedValue, doc, process_attachments, validation_mode
try:
v = adapt.processInput(submittedValue)
except Exception, e:
# TODO: Log exception
if validation_mode:
# when validating, submitted values are potentially bad
# but it must not break getHideWhens, getFormFields, etc.
Expand Down
45 changes: 27 additions & 18 deletions Products/CMFPlomino/PlominoForm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,7 @@ def getSubforms(self, doc=None, applyhidewhen=True, validation_mode=False):
r = re.compile('<span class="plominoSubformClass">([^<]+)</span>')
return [i.strip() for i in r.findall(html_content)]


security.declarePublic('readInputs')
def readInputs(self, doc, REQUEST, process_attachments=False, applyhidewhen=True, validation_mode=False):
""" Read submitted values in REQUEST and store them in document
Expand Down Expand Up @@ -1170,6 +1171,7 @@ def readInputs(self, doc, REQUEST, process_attachments=False, applyhidewhen=True
if (fieldtype in ("SELECTION", "DOCLINK", "BOOLEAN")):
doc.removeItem(fieldName)


security.declareProtected(READ_PERMISSION, 'searchDocuments')
def searchDocuments(self, REQUEST):
""" Search documents in the view matching the submitted form fields values.
Expand Down Expand Up @@ -1296,6 +1298,7 @@ def _get_js_hidden_fields(self, REQUEST, doc, validation_mode=False):
hidden_fields += subform._get_js_hidden_fields(REQUEST, doc)
return hidden_fields


security.declarePublic('validateInputs')
def validateInputs(self, REQUEST, doc=None):
"""
Expand All @@ -1313,6 +1316,16 @@ def validateInputs(self, REQUEST, doc=None):
validation_mode=True)
fields = [field for field in fields
if field.getId() not in hidden_fields]

# Temp doc for validation
db = self.getParentDatabase()
tmp = TemporaryDocument(
db,
self,
REQUEST,
doc,
validation_mode=True).__of__(db)

for f in fields:
fieldname = f.id
fieldtype = f.getFieldType()
Expand All @@ -1332,33 +1345,29 @@ def validateInputs(self, REQUEST, doc=None):
f.Title(),
PlominoTranslate("is mandatory", self)))
else:
# STEP 2: check data types
errors = errors + f.validateFormat(submittedValue)

if not errors:
# STEP 3: check validation formula
db = self.getParentDatabase()
tmp = TemporaryDocument(
db,
self,
REQUEST,
doc,
validation_mode=True).__of__(db)
for f in fields:
#
# STEP 2: check validation formula
#
# This may massage the submitted value e.g. to make it pass STEP 3
#
formula = f.getValidationFormula()
if not formula=='':
s = ''
if formula:
error_msg = ''
try:
s = self.runFormulaScript(
error_msg = self.runFormulaScript(
'field_%s_%s_ValidationFormula' % (
self.id,
f.id),
tmp,
f.ValidationFormula)
except PlominoScriptException, e:
e.reportError('%s validation formula failed' % f.id)
if s:
errors.append(s)
if error_msg:
errors.append(error_msg)
#
# STEP 3: check data types
#
errors = errors + f.validateFormat(submittedValue)

return errors

Expand Down
19 changes: 10 additions & 9 deletions Products/CMFPlomino/PlominoView.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
description_msgid=_('CMFPlomino_help_SortColumn', default="Column used to sort the view"),
i18n_domain='CMFPlomino',
),
vocabulary="_getcolumn_ids",
vocabulary="SortColumn_vocabulary",
schemata="Sorting",
),
BooleanField(
Expand Down Expand Up @@ -362,6 +362,7 @@ def getAllDocuments(self, start=1, limit=None, only_allowed=True,
def getColumns(self):
""" Get columns
"""
# TODO: why not just `return self.contentValues(filter='PlominoColumn')`?
columnslist = self.portal_catalog.search(
{'portal_type': ['PlominoColumn'],
'path': '/'.join(self.getPhysicalPath())},
Expand Down Expand Up @@ -398,7 +399,7 @@ def getActions(self, target, hide=True, parent_id=None):
return filtered

security.declarePublic('getColumn')
def getColumn(self,column_name):
def getColumn(self, column_name):
""" Get a single column
"""
return getattr(self, column_name)
Expand Down Expand Up @@ -525,16 +526,16 @@ def getColumnSums(self):
"""
sums = {}
brains = self.getAllDocuments(getObject=False)
for col in self.getColumns():
if col.DisplaySum:
indexkey = self.getIndexKey(col.getColumnName())
for column in self.getColumns():
if column.DisplaySum:
indexkey = self.getIndexKey(column.getColumnName())
values = [getattr(b, indexkey) for b in brains]
try:
s = sum([v for v in values if v is not None])
s = sum([v for v in values if v])
except:
logger.error('PlominoView', exc_info=True)
s = 0
sums[col.id] = s
sums[column.id] = column.getColumnRender(s)
return sums

def makeArray(self, brains, columns):
Expand Down Expand Up @@ -783,8 +784,8 @@ def getIndexKey(self, columnName):
key = ''
return key

def _getcolumn_ids(self):
return [''] + [c.id for c in self.getColumns()]
def SortColumn_vocabulary(self):
return [''] + [c.id for c in self.getColumns()]

registerType(PlominoView, PROJECTNAME)
# end of class PlominoView
1 change: 1 addition & 0 deletions Products/CMFPlomino/fields/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def format_value(self, v):
str_v = str(v)
return str_v


for f in getFields(INumberField).values():
setattr(NumberField, f.getName(), DictionaryProperty(f, 'parameters'))

Expand Down
10 changes: 6 additions & 4 deletions Products/CMFPlomino/skins/cmfplomino_templates/view_macros.pt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
<tal:sums tal:define="sums python:here.getColumnSums();"
tal:condition="python:test(len(sums)>0)">
<tr><th>Total</th>
<tal:block tal:repeat="c python:here.getColumns()">
<th tal:condition="not: c/HiddenColumn|nothing">
<tal:sum tal:condition="python:test(c.id in sums)" tal:content="python:sums[c.id]">sum</tal:sum></th>
</tal:block>
<tal:column repeat="column python:here.getColumns()">
<th tal:condition="not: column/HiddenColumn|nothing">
<tal:sum condition="python:test(column.id in sums)"
content="python:sums[column.id]">sum</tal:sum>
</th>
</tal:column>
</tr>
</tal:sums>
</tal:sums-macro>

0 comments on commit b917401

Please sign in to comment.