[3129] | 1 | from ploneorg.kudobounty.config import FORM_ID |
---|
| 2 | from ploneorg.kudobounty.config import TOPIC_ID |
---|
[3150] | 3 | from ploneorg.kudobounty.config import CONTAINER_ID |
---|
| 4 | from ploneorg.kudobounty.config import CONTAINER_TITLE |
---|
[3129] | 5 | |
---|
| 6 | from Products.CMFCore.utils import getToolByName |
---|
[3150] | 7 | from Products.CMFPlone.utils import _createObjectByType |
---|
| 8 | from Products.ATContentTypes.lib import constraintypes |
---|
| 9 | |
---|
[3129] | 10 | from Products.GenericSetup.context import TarballExportContext, TarballImportContext |
---|
| 11 | from Products.GenericSetup.interfaces import IFilesystemExporter, IFilesystemImporter |
---|
| 12 | |
---|
| 13 | CREATE_SCRIPT_BODY = """ |
---|
| 14 | portal = context.portal_url.getPortalObject() |
---|
| 15 | formProcessor = portal.restrictedTraverse('@@processBountyForm') |
---|
| 16 | formProcessor() |
---|
| 17 | return {} |
---|
| 18 | """ |
---|
| 19 | |
---|
[3150] | 20 | def createTopic(container, wftool, logger): |
---|
[3129] | 21 | """ |
---|
[3150] | 22 | Located in: /bounty-mission/aggregator |
---|
[3129] | 23 | Item Type = ["Bounty Program Submission",] |
---|
| 24 | state = ['published',] |
---|
| 25 | sort_on = "creation" |
---|
| 26 | """ |
---|
[3150] | 27 | topic = getattr(container, TOPIC_ID, None) |
---|
| 28 | if topic is None: |
---|
| 29 | # Add criteria |
---|
| 30 | _createObjectByType('Topic', container, id=TOPIC_ID, |
---|
| 31 | title=CONTAINER_TITLE) |
---|
| 32 | topic = getattr(container, TOPIC_ID, None) |
---|
| 33 | crit = topic.addCriterion('Type','ATPortalTypeCriterion') |
---|
| 34 | crit.setValue(["Bounty Program Submission",]) |
---|
| 35 | crit = topic.addCriterion('review_state','ATSelectionCriterion') |
---|
| 36 | crit.setValue("published") |
---|
| 37 | crit = topic.addCriterion('created','ATSortCriterion') |
---|
| 38 | topic.setLayout('folder_summary_view') |
---|
| 39 | topic.unmarkCreationFlag() |
---|
[3129] | 40 | |
---|
[3150] | 41 | if wftool.getInfoFor(topic, 'review_state') != 'published': |
---|
| 42 | wftool.doActionFor(topic, 'publish') |
---|
| 43 | |
---|
[3159] | 44 | logger.info("Bounty submissions aggregator added") |
---|
| 45 | else: |
---|
| 46 | logger.info("Bounty submissions aggregator already exist at %s" % \ |
---|
| 47 | topic.absolute_url()) |
---|
[3150] | 48 | |
---|
| 49 | def createPFGForm(context, container, wftool, logger): |
---|
[3129] | 50 | """ |
---|
| 51 | """ |
---|
| 52 | form = getattr(container, FORM_ID, None) |
---|
[3159] | 53 | if form is None: |
---|
| 54 | container.invokeFactory(id=FORM_ID, type_name="FormFolder", |
---|
| 55 | title="Bounty Submission Form") |
---|
| 56 | form = getattr(container, FORM_ID) |
---|
| 57 | # cleanup form and import data from the archive |
---|
| 58 | form.manage_delObjects(ids=form.objectIds()) |
---|
| 59 | pfg_data = context.readDataFile("submissions-form.tar.gz") |
---|
| 60 | ctx = TarballImportContext(form, pfg_data) |
---|
| 61 | IFilesystemImporter(form).import_(ctx, 'structure', True) |
---|
| 62 | # Fix importing PFG via GS bug |
---|
| 63 | # - it adds extra indentation, wchich breaks the script. |
---|
| 64 | create_bounty_script = form["create-bounty-submission"] |
---|
| 65 | create_bounty_script.setScriptBody(CREATE_SCRIPT_BODY) |
---|
| 66 | # Update and pubhish the form |
---|
| 67 | form.update(**{"actionAdapter":["create-bounty-submission",],}) |
---|
| 68 | form.unmarkCreationFlag() |
---|
| 69 | form.reindexObject() |
---|
| 70 | if wftool.getInfoFor(form, 'review_state') != 'published': |
---|
| 71 | wftool.doActionFor(form, 'publish') |
---|
| 72 | logger.info("Bounty submission form created") |
---|
| 73 | else: |
---|
| 74 | logger.info("Bounty submissions form already exist at %s" % \ |
---|
| 75 | form.absolute_url()) |
---|
[3129] | 76 | |
---|
| 77 | def createStructure(context, logger): |
---|
| 78 | site = context.getSite() |
---|
[3138] | 79 | wftool = getToolByName(site, "portal_workflow") |
---|
[3129] | 80 | |
---|
[3150] | 81 | # CONTAINER |
---|
[3159] | 82 | folder = getattr(site, CONTAINER_ID, None) |
---|
| 83 | if folder is None: |
---|
[3150] | 84 | _createObjectByType('Folder', site, id=CONTAINER_ID, |
---|
| 85 | title=CONTAINER_TITLE) |
---|
| 86 | folder = getattr(site, CONTAINER_ID) |
---|
| 87 | folder.setOrdering('unordered') |
---|
| 88 | folder.setConstrainTypesMode(constraintypes.ENABLED) |
---|
| 89 | #folder.setLocallyAllowedTypes(["Bounty Program Submission"]) |
---|
| 90 | #folder.setImmediatelyAddableTypes(["Bounty Program Submission"]) |
---|
| 91 | folder.setDefaultPage(TOPIC_ID) |
---|
| 92 | folder.unmarkCreationFlag() |
---|
[3138] | 93 | |
---|
[3150] | 94 | if wftool.getInfoFor(folder, 'review_state') != 'published': |
---|
| 95 | wftool.doActionFor(folder, 'publish') |
---|
[3129] | 96 | |
---|
[3150] | 97 | logger.info("Submissions container added") |
---|
[3159] | 98 | else: |
---|
| 99 | logger.info("Submissions container already exist at %s" % \ |
---|
| 100 | folder.absolute_url()) |
---|
[3129] | 101 | |
---|
[3150] | 102 | createTopic(folder, wftool, logger) |
---|
| 103 | createPFGForm(context, folder, wftool, logger) |
---|
| 104 | |
---|
[3129] | 105 | def importVarious(context): |
---|
| 106 | """ Various import steps |
---|
| 107 | """ |
---|
| 108 | if context.readDataFile('ploneorg_kudobounty.txt') is None: |
---|
| 109 | return |
---|
| 110 | logger = context.getLogger("ploneorg.kudobounty") |
---|
| 111 | createStructure(context, logger) |
---|