Skip to content

Commit

Permalink
Merge pull request #451 from plomino/jean-script_id-delimiter
Browse files Browse the repository at this point in the history
Change script id delimiter so it's not an underscore
  • Loading branch information
ebrehault committed Oct 21, 2013
2 parents d077cfc + 7d4c565 commit a025203
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 49 deletions.
2 changes: 2 additions & 0 deletions Products/CMFPlomino/AppConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,5 @@
</Style>'''

MSG_SEPARATOR = '\n'

SCRIPTID_DELIMITER = '-_-'
16 changes: 8 additions & 8 deletions Products/CMFPlomino/PlominoAction.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def isHidden(self, target, context):
if self.Hidewhen:
try:
result = self.runFormulaScript(
'action_%s_%s_hidewhen' % (context.id, self.id),
SCRIPTID_DELIMITER.join(['action', context.id, self.id, 'hidewhen']),
target,
self.Hidewhen,
True,
Expand Down Expand Up @@ -180,9 +180,9 @@ def executeAction(self, target, form_id):
elif self.ActionType == "REDIRECT":
try:
redirecturl = self.runFormulaScript(
'action_%s_%s_script' % (
self.getParentNode().id,
self.id),
SCRIPTID_DELIMITER.join([
'action', self.getParentNode().id, self.id,
'script']),
target,
self.Content,
True,
Expand Down Expand Up @@ -213,9 +213,9 @@ def runScript(self, REQUEST):
plominoReturnURL = plominoContext.absolute_url()
try:
returnurl = self.runFormulaScript(
'action_%s_%s_script' % (
self.getParentNode().id,
self.id),
SCRIPTID_DELIMITER.join([
'action', self.getParentNode().id, self.id,
'script']),
plominoContext,
self.Content,
True,
Expand All @@ -232,7 +232,7 @@ def at_post_edit_script(self):
""" Standard AT post edit hook.
"""
self.cleanFormulaScripts(
'action_%s_%s' % (self.getParentNode().id, self.id))
SCRIPTID_DELIMITER.join(['action', self.getParentNode().id, self.id]))


registerType(PlominoAction, PROJECTNAME)
Expand Down
2 changes: 1 addition & 1 deletion Products/CMFPlomino/PlominoDatabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def deleteDocument(self, doc):
message = None
try:
message = self.runFormulaScript(
'form_%s_ondelete' % form.id,
SCRIPTID_DELIMITER.join(['form', form.id, 'ondelete']),
doc,
form.onDeleteDocument)
except PlominoScriptException, e:
Expand Down
3 changes: 1 addition & 2 deletions Products/CMFPlomino/PlominoDesignManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
%(formula)s
"""


def run_refreshdb(context):
# for async call
context.refreshDB()
Expand Down Expand Up @@ -799,7 +798,7 @@ def callScriptMethod(self, scriptname, funcname, *args):
``scriptname``, stored in the ``resources`` folder.
If the called function allows it, you may pass some arguments.
"""
script_id = 'script_%s_%s' % (scriptname, funcname)
script_id = SCRIPTID_DELIMITER.join(['script', scriptname, funcname])
try:
script_code = self.resources._getOb(scriptname).read()
except:
Expand Down
14 changes: 7 additions & 7 deletions Products/CMFPlomino/PlominoDocument.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def saveDocument(self, REQUEST, creation=False):
error = None
try:
error = self.runFormulaScript(
'form_%s_beforesave' % form.id,
SCRIPTID_DELIMITER.join(['form', form.id, 'beforesave']),
self,
form.getBeforeSaveDocument)
except PlominoScriptException, e:
Expand Down Expand Up @@ -463,7 +463,7 @@ def save(self, form=None, creation=False, refresh_index=True,
# Use the formula if we have one
try:
title = self.runFormulaScript(
'form_%s_title' % form.id,
SCRIPTID_DELIMITER.join(['form', form.id, 'title']),
self,
form.DocumentTitle)
if title != self.Title():
Expand Down Expand Up @@ -499,7 +499,7 @@ def save(self, form=None, creation=False, refresh_index=True,
if form and onSaveEvent:
try:
result = self.runFormulaScript(
'form_%s_onsave' % form.id,
SCRIPTID_DELIMITER.join(['form', form.id, 'onsave']),
self,
form.onSaveDocument)
if result and hasattr(self, 'REQUEST'):
Expand Down Expand Up @@ -530,7 +530,7 @@ def _onOpenDocument(self, form=None):
try:
if form.getOnOpenDocument():
onOpenDocument_error = self.runFormulaScript(
'form_%s_onopen' % form.id,
SCRIPTID_DELIMITER.join(['form', form.id, 'onopen']),
self,
form.onOpenDocument)
return onOpenDocument_error
Expand Down Expand Up @@ -604,7 +604,7 @@ def Title(self):
# Use the formula if we have one
try:
title = self.runFormulaScript(
'form_%s_title' % form.id,
SCRIPTID_DELIMITER.join(['form', form.id, 'title']),
self,
form.DocumentTitle)
if (form.getStoreDynamicDocumentTitle() and
Expand Down Expand Up @@ -672,7 +672,7 @@ def isSelectedInView(self, viewname):
try:
#result = RunFormula(self, v.SelectionFormula())
result = self.runFormulaScript(
'view_%s_selection' % v.id,
SCRIPTID_DELIMITER.join(['view', v.id, 'selection']),
self,
v.SelectionFormula)
return result
Expand Down Expand Up @@ -960,7 +960,7 @@ def generateNewId(self):
result = None
try:
result = self.runFormulaScript(
'form_%s_docid' % form.id, self, form.DocumentId)
SCRIPTID_DELIMITER.join(['form', form.id, 'docid']), self, form.DocumentId)
except PlominoScriptException, e:
e.reportError('Document id formula failed')

Expand Down
11 changes: 5 additions & 6 deletions Products/CMFPlomino/PlominoField.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,9 @@ def getFieldRender(self, form, doc, editmode, creation=False, request=None):
):
injection_position = html.index(injection_zone)
html_attributes = self.runFormulaScript(
'field_%s_%s_attributes' % (
self.getParentNode().id,
self.id,
),
SCRIPTID_DELIMITER.join([
'field', self.getParentNode().id, self.id,
'attributes']),
target,
self.HTMLAttributesFormula
)
Expand Down Expand Up @@ -387,6 +386,6 @@ def getContentType(self, fieldname=None):

@property
def formula_ids(self):
return {'Formula': "field_"+self.getParentNode().id+"_"+self.id,
'ValidationFormula': "field_"+self.getParentNode().id+"_"+self.id+"_ValidationFormula"}
return {'Formula': SCRIPTID_DELIMITER.join(["field", self.getParentNode().id, self.id]),
'ValidationFormula': SCRIPTID_DELIMITER.join(["field", self.getParentNode().id, self.id, "ValidationFormula"])}
registerType(PlominoField, PROJECTNAME)
22 changes: 10 additions & 12 deletions Products/CMFPlomino/PlominoForm.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def createDocument(self, REQUEST):
valid = ''
try:
valid = self.runFormulaScript(
'form_%s_oncreate' % self.id,
SCRIPTID_DELIMITER.join(['form', self.id, 'oncreate']),
doc,
self.onCreateDocument)
except PlominoScriptException, e:
Expand Down Expand Up @@ -790,7 +790,7 @@ def applyHideWhen(self, doc=None, silent_error=True):
else:
target = doc
result = self.runFormulaScript(
'hidewhen_%s_%s_formula' % (self.id, hidewhen.id),
SCRIPTID_DELIMITER.join(['hidewhen', self.id, hidewhen.id, 'formula']),
target,
hidewhen.Formula)
except PlominoScriptException, e:
Expand Down Expand Up @@ -878,9 +878,7 @@ def getHidewhenAsJSON(self, REQUEST, parent_form=None, validation_mode=False):
if getattr(hidewhen, 'isDynamicHidewhen', False):
try:
isHidden = self.runFormulaScript(
'hidewhen_%s_%s_formula' % (
self.id,
hidewhen.id),
SCRIPTID_DELIMITER.join(['hidewhen', self.id, hidewhen.id, 'formula']),
target,
hidewhen.Formula)
except PlominoScriptException, e:
Expand Down Expand Up @@ -999,7 +997,7 @@ def openBlankForm(self, request=None):
self.beforeCreateDocument):
try:
invalid = self.runFormulaScript(
'form_%s_beforecreate' % self.id,
SCRIPTID_DELIMITER.join(['form', self.id, 'beforecreate']),
self,
self.beforeCreateDocument)
except PlominoScriptException, e:
Expand Down Expand Up @@ -1028,7 +1026,7 @@ def openBlankForm(self, request=None):
def at_post_edit_script(self):
""" Clean up the layout before saving
"""
self.cleanFormulaScripts("form_" + self.id)
self.cleanFormulaScripts(SCRIPTID_DELIMITER.join(["form", self.id]))

security.declarePublic('getFormField')
def getFormField(self, fieldname, includesubforms=True):
Expand Down Expand Up @@ -1057,7 +1055,7 @@ def computeFieldValue(self, fieldname, target, report=True):
db = self.getParentDatabase()
try:
fieldvalue = db.runFormulaScript(
'field_%s_%s_formula' % (self.id, fieldname),
SCRIPTID_DELIMITER.join(['field', self.id, fieldname, 'formula']),
target,
field.Formula,
True,
Expand Down Expand Up @@ -1252,7 +1250,7 @@ def searchDocuments(self, REQUEST):
try:
for doc in results:
valid = self.runFormulaScript(
'form_%s_searchformula' % self.id,
SCRIPTID_DELIMITER.join(['form', self.id, 'searchformula']),
doc.getObject(),
self.SearchFormula)
if valid:
Expand Down Expand Up @@ -1364,9 +1362,9 @@ def validateInputs(self, REQUEST, doc=None):
error_msg = ''
try:
error_msg = self.runFormulaScript(
'field_%s_%s_ValidationFormula' % (
self.id,
f.id),
SCRIPTID_DELIMITER.join([
'field', self.id, f.id,
'ValidationFormula']),
tmp,
f.ValidationFormula)
except PlominoScriptException, e:
Expand Down
2 changes: 1 addition & 1 deletion Products/CMFPlomino/PlominoHidewhen.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def at_post_edit_script(self):
""" Standard AT post-edit hook.
"""
self.cleanFormulaScripts(
'hidewhen_%s_%s' % (self.getParentNode().id, self.id))
SCRIPTID_DELIMITER.join(['hidewhen', self.getParentNode().id, self.id]))


registerType(PlominoHidewhen, PROJECTNAME)
Expand Down
2 changes: 2 additions & 0 deletions Products/CMFPlomino/PlominoUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
except ImportError:
HAS_PLONE40 = False

from Products.CMFPlomino.AppConfig import SCRIPTID_DELIMITER

import logging
logger = logging.getLogger('Plomino')

Expand Down
6 changes: 3 additions & 3 deletions Products/CMFPlomino/PlominoView.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def checkBeforeOpenView(self):
try:
if self.getOnOpenView():
valid = self.runFormulaScript(
'view_%s_onopen' % self.id,
SCRIPTID_DELIMITER.join(['view', self.id, 'onopen']),
self,
self.getOnOpenView)
except PlominoScriptException, e:
Expand Down Expand Up @@ -404,7 +404,7 @@ def evaluateViewForm(self,doc):
try:
#result = RunFormula(doc, self.getFormFormula())
result = self.runFormulaScript(
'view_%s_formformula' % self.id,
SCRIPTID_DELIMITER.join(['view', self.id, 'formformula']),
doc,
self.FormFormula)
except PlominoScriptException, e:
Expand All @@ -415,7 +415,7 @@ def evaluateViewForm(self,doc):
security.declarePublic('at_post_edit_script')
def at_post_edit_script(self):
db = self.getParentDatabase()
self.cleanFormulaScripts("view_"+self.id)
self.cleanFormulaScripts(SCRIPTID_DELIMITER.join(["view", self.id]))
if not db.DoNotReindex:
self.getParentDatabase().getIndex().refresh()

Expand Down
3 changes: 2 additions & 1 deletion Products/CMFPlomino/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ class PlominoCoreUtils:
'actual_context',
'is_email',
'urlquote',
'translate']
'translate',
'SCRIPTID_DELIMITER']

component.provideUtility(PlominoCoreUtils, interfaces.IPlominoUtils)

Expand Down
6 changes: 4 additions & 2 deletions Products/CMFPlomino/fields/doclink.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from dictionaryproperty import DictionaryProperty
from Products.CMFPlomino.exceptions import PlominoScriptException
from Products.CMFPlomino.PlominoUtils import asUnicode
from Products.CMFPlomino.AppConfig import SCRIPTID_DELIMITER

class IDoclinkField(IBaseField):
""" Selection field schema
Expand Down Expand Up @@ -109,9 +110,10 @@ def getSelectionList(self, doc):
obj = doc
try:
s = self.context.runFormulaScript(
'field_%s_%s_DocumentListFormula' % (
SCRIPTID_DELIMITER.join(['field',
self.context.getParentNode().id,
self.context.id),
self.context.id,
'DocumentListFormula']),
obj,
lambda: f)
except PlominoScriptException, e:
Expand Down
3 changes: 2 additions & 1 deletion Products/CMFPlomino/fields/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
__author__ = """Eric BREHAULT <eric.brehault@makina-corpus.com>"""
__docformat__ = 'plaintext'

from Products.CMFPlomino.AppConfig import SCRIPTID_DELIMITER

def afterFieldModified(obj, event):
"""
"""
obj.cleanFormulaScripts("field_"+obj.getPhysicalPath()[-2]+"_"+obj.id)
obj.cleanFormulaScripts(SCRIPTID_DELIMITER.join(["field", obj.getPhysicalPath()[-2], obj.id]))
5 changes: 3 additions & 2 deletions Products/CMFPlomino/fields/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from Products.CMFPlomino.PlominoUtils import asUnicode

from jsonutil import jsonutil as json
from Products.CMFPlomino.AppConfig import SCRIPTID_DELIMITER


class ISelectionField(IBaseField):
Expand Down Expand Up @@ -87,9 +88,9 @@ def getSelectionList(self, doc):
obj = self.context
try:
s = self.context.runFormulaScript(
'field_%s_%s_SelectionListFormula' % (
SCRIPTID_DELIMITER.join(['field',
self.context.getParentNode().id,
self.context.id),
self.context.id, 'SelectionListFormula']),
obj,
lambda: f)
except PlominoScriptException, e:
Expand Down
6 changes: 4 additions & 2 deletions Products/CMFPlomino/tests/plomino.txt
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,8 @@ A form can define actions to take when specific events occur on a document.
... newcountry='Chile'
... plominoDocument.setItem('country', newcountry)
... """)
>>> db.cleanFormulaScripts("form_frm1")
>>> from Products.CMFPlomino.AppConfig import SCRIPTID_DELIMITER
>>> db.cleanFormulaScripts("form"+SCRIPTID_DELIMITER+"frm1")
>>> doc1.country
u'Finland'
>>> doc1.save(db.frm1)
Expand All @@ -583,7 +584,8 @@ aborted::
... return "Chile cannot be deleted"
... return None
... """)
>>> db.cleanFormulaScripts("form_frm1")
>>> from Products.CMFPlomino.AppConfig import SCRIPTID_DELIMITER
>>> db.cleanFormulaScripts("form"+SCRIPTID_DELIMITER+"frm1")
>>> doc1_id = doc1.id
>>> db.deleteDocument(doc1)
>>> db.getDocument(doc1_id) is None
Expand Down
3 changes: 2 additions & 1 deletion Products/CMFPlomino/tests/plomino_usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ Profiling::
>>> browser.getControl(name='age').value = "47"
>>> browser.getControl("Save").click()
>>> browser.open(db_url + "/profiling")
>>> "form_frmtest_title (1 times)" in browser.contents
>>> from Products.CMFPlomino.AppConfig import SCRIPTID_DELIMITER
>>> "form"+SCRIPTID_DELIMITER+"frmtest"+SCRIPTID_DELIMITER+"title (1 times)" in browser.contents
True

Replication::
Expand Down

0 comments on commit a025203

Please sign in to comment.