From 2907b5c25cb374e26e988e9e413e0ac47ead961a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Tue, 1 Apr 2008 16:06:56 +0000
Subject: [PATCH] 2008-04-01 Jerome * Add utility scripts to help in writing
 domain generation scripts: BaseDomain_generateDomainFromCurrentDocument and
 BaseDomain_generateDomainFromSelection.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@20254 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 ...main_generateDomainFromCurrentDocument.xml | 189 ++++++++++++++++++
 ...BaseDomain_generateDomainFromSelection.xml | 185 +++++++++++++++++
 .../ERP5/bootstrap/erp5_core/bt/change_log    |   3 +
 product/ERP5/bootstrap/erp5_core/bt/revision  |   2 +-
 4 files changed, 378 insertions(+), 1 deletion(-)
 create mode 100644 product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BaseDomain_generateDomainFromCurrentDocument.xml
 create mode 100644 product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BaseDomain_generateDomainFromSelection.xml

diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BaseDomain_generateDomainFromCurrentDocument.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BaseDomain_generateDomainFromCurrentDocument.xml
new file mode 100644
index 0000000000..9b97ab5f9e
--- /dev/null
+++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BaseDomain_generateDomainFromCurrentDocument.xml
@@ -0,0 +1,189 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <tuple>
+        <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
+        <tuple/>
+      </tuple>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>Python_magic</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>Script_magic</string> </key>
+            <value> <int>3</int> </value>
+        </item>
+        <item>
+            <key> <string>__ac_local_roles__</string> </key>
+            <value>
+              <none/>
+            </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>_body</string> </key>
+            <value> <string>"""This script generates a domain containing only the current document.\n
+This is usefull for planning box, where a domain is always required.\n
+\n
+It\'s not supposed to be used directly, but wrapped in another script that will pass those parameters:\n
+ * script_id: the ID of the wrapper script (subdomains will be regenerated with this script);\n
+ * membership_criterion_base_category: base categories that will be set on generated domains.\n
+"""\n
+\n
+if depth != 0:\n
+  return []\n
+\n
+domain_list = []\n
+portal = context.getPortalObject()\n
+request = portal.REQUEST\n
+here = request.get(\'here\', None)\n
+if here is None:\n
+  # Sometimes the object is not in the request, when you edit for example.\n
+  here = request[\'PUBLISHED\'].aq_parent \n
+\n
+for category in (here, ):\n
+  domain = parent.generateTempDomain(id=category.getId())\n
+  domain.edit(title=category.getTitle(),\n
+              membership_criterion_base_category=membership_criterion_base_category,\n
+              membership_criterion_category=(category.getRelativeUrl(),),\n
+              domain_generator_method_id=script_id,\n
+              uid=category.getUid())\n
+                \n
+  domain_list.append(domain)\n
+\n
+return domain_list\n
+</string> </value>
+        </item>
+        <item>
+            <key> <string>_code</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>_filepath</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>_owner</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>_params</string> </key>
+            <value> <string>script_id, membership_criterion_base_category, depth, parent, **kw</string> </value>
+        </item>
+        <item>
+            <key> <string>errors</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+        <item>
+            <key> <string>func_code</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
+                </klass>
+                <tuple/>
+                <state>
+                  <dictionary>
+                    <item>
+                        <key> <string>co_argcount</string> </key>
+                        <value> <int>4</int> </value>
+                    </item>
+                    <item>
+                        <key> <string>co_varnames</string> </key>
+                        <value>
+                          <tuple>
+                            <string>script_id</string>
+                            <string>membership_criterion_base_category</string>
+                            <string>depth</string>
+                            <string>parent</string>
+                            <string>kw</string>
+                            <string>domain_list</string>
+                            <string>_getattr_</string>
+                            <string>context</string>
+                            <string>portal</string>
+                            <string>request</string>
+                            <string>None</string>
+                            <string>here</string>
+                            <string>_getitem_</string>
+                            <string>_getiter_</string>
+                            <string>category</string>
+                            <string>domain</string>
+                          </tuple>
+                        </value>
+                    </item>
+                  </dictionary>
+                </state>
+              </object>
+            </value>
+        </item>
+        <item>
+            <key> <string>func_defaults</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>BaseDomain_generateDomainFromCurrentDocument</string> </value>
+        </item>
+        <item>
+            <key> <string>warnings</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BaseDomain_generateDomainFromSelection.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BaseDomain_generateDomainFromSelection.xml
new file mode 100644
index 0000000000..3ce048b64a
--- /dev/null
+++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BaseDomain_generateDomainFromSelection.xml
@@ -0,0 +1,185 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <tuple>
+        <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
+        <tuple/>
+      </tuple>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>Python_magic</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>Script_magic</string> </key>
+            <value> <int>3</int> </value>
+        </item>
+        <item>
+            <key> <string>__ac_local_roles__</string> </key>
+            <value>
+              <none/>
+            </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>_body</string> </key>
+            <value> <string>"""This script generates a domain from selected objects in a module.\n
+\n
+It\'s not supposed to be used directly, but wrapped in another script that will pass those parameters:\n
+ * script_id: the ID of the wrapper script (subdomains will be regenerated with this script);\n
+ * selection_name: the selection name used by the listbox;\n
+ * membership_criterion_base_category: base categories that will be set on generated domains.\n
+"""\n
+\n
+if depth != 0:\n
+  return []\n
+\n
+domain_list = []\n
+portal = context.getPortalObject()\n
+category_list = portal.portal_selections.getSelectionCheckedValueList(selection_name)\n
+if not category_list:\n
+  category_list = portal.portal_selections.callSelectionFor(selection_name)\n
+\n
+for category in category_list:\n
+  domain = parent.generateTempDomain(id=category.getId())\n
+  domain.edit(title=category.getTitle(),\n
+              membership_criterion_base_category=membership_criterion_base_category,\n
+              membership_criterion_category=(category.getRelativeUrl(),),\n
+              domain_generator_method_id=script_id,\n
+              uid=category.getUid())\n
+                \n
+  domain_list.append(domain)\n
+\n
+return domain_list\n
+</string> </value>
+        </item>
+        <item>
+            <key> <string>_code</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>_filepath</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>_owner</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>_params</string> </key>
+            <value> <string>script_id, selection_name, membership_criterion_base_category, depth, parent, **kw</string> </value>
+        </item>
+        <item>
+            <key> <string>errors</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+        <item>
+            <key> <string>func_code</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
+                </klass>
+                <tuple/>
+                <state>
+                  <dictionary>
+                    <item>
+                        <key> <string>co_argcount</string> </key>
+                        <value> <int>5</int> </value>
+                    </item>
+                    <item>
+                        <key> <string>co_varnames</string> </key>
+                        <value>
+                          <tuple>
+                            <string>script_id</string>
+                            <string>selection_name</string>
+                            <string>membership_criterion_base_category</string>
+                            <string>depth</string>
+                            <string>parent</string>
+                            <string>kw</string>
+                            <string>domain_list</string>
+                            <string>_getattr_</string>
+                            <string>context</string>
+                            <string>portal</string>
+                            <string>category_list</string>
+                            <string>_getiter_</string>
+                            <string>category</string>
+                            <string>domain</string>
+                          </tuple>
+                        </value>
+                    </item>
+                  </dictionary>
+                </state>
+              </object>
+            </value>
+        </item>
+        <item>
+            <key> <string>func_defaults</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>BaseDomain_generateDomainFromSelection</string> </value>
+        </item>
+        <item>
+            <key> <string>warnings</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/product/ERP5/bootstrap/erp5_core/bt/change_log b/product/ERP5/bootstrap/erp5_core/bt/change_log
index 7c3981c5f7..f4e853ad15 100644
--- a/product/ERP5/bootstrap/erp5_core/bt/change_log
+++ b/product/ERP5/bootstrap/erp5_core/bt/change_log
@@ -1,3 +1,6 @@
+2008-04-01 Jerome
+* Add utility scripts to help in writing domain generation scripts: BaseDomain_generateDomainFromCurrentDocument and BaseDomain_generateDomainFromSelection.
+
 2008-03-28 Yusei
 * Removed causality from acquired base categories on destination_administration,
 destination_decision, destination_payment,
diff --git a/product/ERP5/bootstrap/erp5_core/bt/revision b/product/ERP5/bootstrap/erp5_core/bt/revision
index 126adfec91..fc0b67d079 100644
--- a/product/ERP5/bootstrap/erp5_core/bt/revision
+++ b/product/ERP5/bootstrap/erp5_core/bt/revision
@@ -1 +1 @@
-772
\ No newline at end of file
+774
\ No newline at end of file
-- 
2.30.9