Commit e5bb0c4b authored by Vincent Bechu's avatar Vincent Bechu

[erp5_officejs_appstore_base] Add dynamic appstore

parent 929e9a83
import json
portal = context.getPortalObject()
software_product_list = portal.portal_catalog(portal_type='Software Product', validation_state='validated')
appstore_data = []
logo_url_list = []
i = 0
for software_product in software_product_list:
web_site = software_product.SoftwareProduct_getRelatedWebSite()
version = web_site.getLayoutProperty('configuration_latest_version')
web_section = web_site[version]
manifest_url = web_section.getLayoutProperty('configuration_webapp_manifest_url', default=None)
# allow to have application without web manifest
if manifest_url is not None:
manifest = portal.portal_catalog.getResultValue(reference=version + '/' + manifest_url)
if manifest is not None:
data = json.loads(manifest.getData())
src_icon = data['icons'][0]['src']
logo = portal.portal_catalog.getResultValue(reference='%' + src_icon, version=version, portal_type='File')
if logo is not None:
logo_url_list.append('appstore/' + logo.getReference())
# Future domain could be defined by user
app_domain = software_product.getFollowUpId(portal_type="Web Section")
appstore_data.append({
"int_index": str(i),
"application_image_type": 'image',
"application_image_url": logo.getReference(),
"application_toc_accept": 'true',
"application_published": 'some_date',
"application_submitted": 'other_date',
"application_description": data["description"] if "description" in data else data["name"],
"application_url": "https://%s.app.officejs.com/" % app_domain,
"application_title": data['short_name'],
"application_category": data['category'] if "category" in data else "Documents",
"application_title_i18n": "application.custom.%s.title" % app_domain,
"application_description_i18n": "application.custom.%s.description" % app_domain
})
i+=1
portal.document_module['store_officejs_data_application_sample_json'].setData(json.dumps(appstore_data))
manifest_content = portal.web_page_module['store_officejs_base_appcache'].getTextContent()
portal.web_page_module['store_officejs_appcache'].setTextContent(manifest_content.replace('${logo_list}', '\n'.join(logo_url_list)))
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Alarm_updateAppstoreWebSite</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -16,6 +16,5 @@ if not web_site:
# This is dangerous
if not web_site.getId() == context.getReference().lower():
web_site.setId(context.getReference().lower())
if batch_mode:
return web_site
......@@ -2,3 +2,6 @@ software_release = context.SoftwarePublication_getRelatedSoftwareRelease()
tag = "publish_" + software_release.getRelativeUrl()
software_release.activate(tag=tag).SoftwareRelease_publishRelatedWebDocument()
software_release.activate(after_tag=tag).publish()
software_product = software_release.getFollowUpValue(portal_type="Software Product")
if software_product.getValidationStateTitle() == 'Draft':
software_product.validate()
......@@ -54,6 +54,13 @@ if base:
base += "/"
base_length = len(base)
def extractWebManifest(file):
html = context.Base_parseHtml(file)
for tag in html:
if tag[0] == 'starttag' and tag[1] == 'link' and ('rel', 'manifest') in tag[2]:
for attribute in tag[2]:
if attribute[0] == 'href':
return attribute[1]
software_release_url = software_release.getRelativeUrl()
......@@ -87,9 +94,10 @@ for name in zip_reader.namelist():
document.getCategoryList() + ["contributor/" + software_publication.getSource()])
if url in ("index.html", "index.htm"):
default_page = document.getRelativeUrl()
web_manifest_url = extractWebManifest(document.getData())
document.activate(tag=tag).publish()
software_release.SoftwareRelease_fixRelatedWebSection(default_page=default_page)
software_release.SoftwareRelease_fixRelatedWebSection(default_page=default_page, web_manifest = web_manifest_url)
if portal.portal_workflow.isTransitionPossible(zip_file, 'publish'):
zip_file.publish()
......
......@@ -47,4 +47,6 @@ if not default_page:
web_section.setAggregate(aggregate_list[0].relative_url)
else:
web_section.setAggregate(default_page)
if web_manifest is not None:
web_section.setProperty('configuration_webapp_manifest_url', web_manifest)
return "Done"
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>default_page=""</string> </value>
<value> <string>default_page="", web_manifest=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment