Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proof of concept: Versioning MK2 #329

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
10 changes: 5 additions & 5 deletions Products/zms/ZMSWorkflowProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,13 @@ def doAutocommit(self, lang, REQUEST):

Change workflow.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
def manage_changeWorkflow(self, lang, btn='', key='properties', REQUEST=None, RESPONSE=None):
def manage_changeWorkflow(self, lang, btn='', key='workflow_properties', REQUEST=None, RESPONSE=None):
""" ZMSWorkflowProvider.manage_changeWorkflow """
message = ''

# Version Control.
# -----------
if key == 'history':
if key == 'workflow_versioning':
old_active = self.getConfProperty('ZMS.Version.active',0)
new_active = REQUEST.get('active',0)
old_nodes = self.getConfProperty('ZMS.Version.nodes',['{$}'])
Expand All @@ -345,7 +345,7 @@ def manage_changeWorkflow(self, lang, btn='', key='properties', REQUEST=None, RE

# Properties.
# -----------
elif key == 'properties':
elif key == 'workflow_properties':
# Save.
# ------
if btn == 'BTN_SAVE':
Expand Down Expand Up @@ -383,10 +383,10 @@ def manage_changeWorkflow(self, lang, btn='', key='properties', REQUEST=None, RE
else:
filename = REQUEST['init']
self.importConf(filename)
message = self.getZMILangStr('MSG_IMPORTED')%('<i>%s</i>'%f.filename)
message = self.getZMILangStr('MSG_IMPORTED')%('<i>%s</i>'%filename)

# Return with message.
message = standard.url_quote(message)
return RESPONSE.redirect('manage_main?lang=%s&key=%s&manage_tabs_message=%s#_properties'%(lang, key, message))
return RESPONSE.redirect('manage_main?lang=%s&key=%s&manage_tabs_message=%s'%(lang, key, message))

################################################################################
26 changes: 13 additions & 13 deletions Products/zms/import/_language.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6406,19 +6406,19 @@
</Row>
<Row>
<Cell><Data ss:Type="String">TAB_WORKFLOW_ASSIGNMENT</Data></Cell>
<Cell><Data ss:Type="String">Workflow-Aktivierung</Data></Cell>
<Cell><Data ss:Type="String">Workflow Assignment</Data></Cell>
<Cell><Data ss:Type="String">Workflow Assignment</Data></Cell>
<Cell><Data ss:Type="String">Workflow Assignment</Data></Cell>
<Cell><Data ss:Type="String">Workflow Assignment</Data></Cell>
<Cell><Data ss:Type="String">Workflow Assignment</Data></Cell>
<Cell><Data ss:Type="String">Workflow Assignment</Data></Cell>
<Cell><Data ss:Type="String">Workflow Assignment</Data></Cell>
<Cell><Data ss:Type="String">Workflow Assignment</Data></Cell>
<Cell><Data ss:Type="String">Workflow Assignment</Data></Cell>
<Cell><Data ss:Type="String">Workflow Assignment</Data></Cell>
<Cell><Data ss:Type="String">Workflow Assignment</Data></Cell>
<Cell><Data ss:Type="String">Workflow Assignment</Data></Cell>
<Cell><Data ss:Type="String">Zuweisung</Data></Cell>
<Cell><Data ss:Type="String">Assignment</Data></Cell>
<Cell><Data ss:Type="String">Assignment</Data></Cell>
<Cell><Data ss:Type="String">Assignment</Data></Cell>
<Cell><Data ss:Type="String">Assignment</Data></Cell>
<Cell><Data ss:Type="String">Assignment</Data></Cell>
<Cell><Data ss:Type="String">Assignment</Data></Cell>
<Cell><Data ss:Type="String">Assignment</Data></Cell>
<Cell><Data ss:Type="String">Assignment</Data></Cell>
<Cell><Data ss:Type="String">Assignment</Data></Cell>
<Cell><Data ss:Type="String">Assignment</Data></Cell>
<Cell><Data ss:Type="String">Assignment</Data></Cell>
<Cell><Data ss:Type="String">Assignment</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="String">TAB_WORKFLOW_MODEL</Data></Cell>
Expand Down
70 changes: 68 additions & 2 deletions Products/zms/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,22 @@ def __call__(self, REQUEST=None, **kw):
decoration, data = self.get_child_nodes(self.context, content_type=True)
elif self.ids == ['get_tree_nodes']:
decoration, data = self.get_tree_nodes(self.context, content_type=True)
elif self.ids == ['get_tags']:
decoration, data = self.get_tags(self.context, content_type=True)
elif self.ids == ['get_tag']:
decoration, data = self.get_tag(self.context, content_type=True)
elif self.ids == ['body_content']:
decoration, data = self.body_content(self.context, content_type=True)
elif self.ids == [] or self.ids == ['get']:
decoration, data = self.get(self.context, content_type=True)
else:
data = {'ERROR':'Not Found','context':str(self.context),'path_to_handle':self.path_to_handle,'ids':self.ids}
REQUEST.RESPONSE.setHeader('Content-Type',decoration['content_type'])
return json.dumps(data)
ct = decoration['content_type']
REQUEST.RESPONSE.setHeader('Content-Type',ct)
REQUEST.RESPONSE.setHeader('Content-Disposition', 'inline;filename="%s.%s"'%((self.ids+['get'])[-1],ct.split('/')[-1]))
if ct == 'application/json':
return json.dumps(data)
return data
return None

@api(tag="zmsindex", pattern="/zmsindex", content_type="application/json")
Expand Down Expand Up @@ -265,3 +275,59 @@ def get_tree_nodes(self, context):
request = _get_request(context)
nodes = context.getTreeNodes(request)
return [get_attrs(x) for x in nodes]

@api(tag="version", pattern="/{path}/get_tags", method="GET", content_type="application/json")
def get_tags(self, context):
request = _get_request(context)
tags = []
version_container = context.getVersionContainer()
version_items = version_container.getVersionItems(request)
for version_item in [version_container] + version_items:
for obj_version in version_item.getObjVersions():
request.set('ZMS_VERSION_%s'%version_item.id,obj_version.id)
tags.append((obj_version.attr('master_version'), obj_version.attr('major_version'), obj_version.attr('minor_version')))
tags = reversed(sorted(list(set(tags))))
return ['r%i.%i.%i'%(x[0],x[1],x[2]) for x in tags]

@api(tag="version", pattern="/{path}/get_tag", method="GET", content_type="application/json")
def get_tag(self, context):
request = _get_request(context)
tag = [int(x) for x in request.get('tag','r0.0.0')[1:].split('.')]
data = []
version_container = context.getVersionContainer()
version_items = version_container.getVersionItems(request)
for version_item in [version_container] + version_items:
d = {}
for obj_version in version_item.getObjVersions():
request.set('ZMS_VERSION_%s'%version_item.id,obj_version.id)
d[(obj_version.attr('master_version'), obj_version.attr('major_version'), obj_version.attr('minor_version'))] = obj_version.id
tags = list(reversed(sorted(list(d.keys()))))
if version_item != version_container:
tags = [x for x in tags if list(x) <= tag]
if tags:
request.set('ZMS_VERSION_%s'%version_item.id,d[tags[0]])
attrs = get_attrs(version_item)
attrs['version_nr'] = 'r%s.%s.%s'%(tags[0][0],tags[0][1],tags[0][2])
data.append(attrs)
return data

@api(tag="version", pattern="/{path}/body_content", method="GET", content_type="text/html")
def body_content(self, context):
request = _get_request(context)
tag = [int(x) for x in request.get('tag','r0.0.0')[1:].split('.')]
version_container = context.getVersionContainer()
version_items = version_container.getVersionItems(request)
for version_item in [version_container] + version_items:
d = {}
for obj_version in version_item.getObjVersions():
request.set('ZMS_VERSION_%s'%version_item.id,obj_version.id)
d[(obj_version.attr('master_version'), obj_version.attr('major_version'), obj_version.attr('minor_version'))] = obj_version.id
tags = list(reversed(sorted(list(d.keys()))))
if version_item != version_container:
tags = [x for x in tags if list(x) <= tag]
if tags:
request.set('ZMS_VERSION_%s'%version_item.id,d[tags[0]])
html = []
html.append('<div class="%s"><h1>%s<small>%s</small></h1></div>'%(version_container.meta_id,version_container.getTitle(request),version_container.getDCDescription(request)))
html.append(version_container.getBodyContent(request))
return '\n'.join(html)
Loading
Loading