Esempio n. 1
0
def add_response_for_files(object, event):
    """If a file/image is added or deleted, add a response."""
    if isinstance(event, ObjectAddedEvent):
        parent = event.newParent
        # do not add response if attachment is migrating to DX
        checkid = object.id + '_MIGRATION_'
        if any(att.id == checkid for att in parent.getFolderContents()):
            return
        if parent.portal_type == "Issue":
            issue = parent
            new_response = Response("")
        else:
            return
    elif isinstance(event, ObjectModifiedEvent):
        if object.aq_parent.portal_type == "Issue":
            issue = object.aq_parent
            new_response = Response("")
        else:
            return
    elif isinstance(event, ObjectRemovedEvent):
        if event.oldParent.portal_type == "Issue":
            issue = event.oldParent
            new_response = Response("Attachment deleted: " + object.title)
        else:
            return

    if new_response:
        new_response.attachment = object
        new_response.mimetype =\
            api.portal.get_registry_record('poi.default_issue_mime_type')
        new_response.type = "file"
        folder = IResponseContainer(issue)
        folder.add(new_response)
Esempio n. 2
0
def add_response_for_files(object, event):
    """If a file/image is added or deleted, add a response."""
    if isinstance(event, ObjectAddedEvent):
        parent = event.newParent
        # do not add response if attachment is migrating to DX
        checkid = object.id + '_MIGRATION_'
        if any(att.id == checkid for att in parent.getFolderContents()):
            return
        if parent.portal_type == "Issue":
            issue = parent
            new_response = Response("")
        else:
            return
    elif isinstance(event, ObjectModifiedEvent):
        if object.aq_parent.portal_type == "Issue":
            issue = object.aq_parent
            new_response = Response("")
        else:
            return
    elif isinstance(event, ObjectRemovedEvent):
        if event.oldParent.portal_type == "Issue":
            issue = event.oldParent
            new_response = Response("Attachment deleted: " + object.title)
        else:
            return

    if new_response:
        new_response.attachment = object
        new_response.mimetype =\
            api.portal.get_registry_record('poi.default_issue_mime_type')
        new_response.type = "file"
        folder = IResponseContainer(issue)
        folder.add(new_response)
    def __iter__(self):
        for item in self.previous:
            keys = item.keys()
            pathkey = self.pathkey(*keys)[0]

            if not pathkey or ('poi_responses' not in keys):
                yield item; continue
            path = item[pathkey]

            obj = self.context.unrestrictedTraverse(path.lstrip('/'), None)
            if obj is None:  # path doesn't exist
                yield item; continue

            if isinstance(obj, PoiIssue):
                container = IResponseContainer(obj)
                i = 0
                for response in item['poi_responses']:
                    attachment_filename = response.pop('attachment_filename')
                    attachment_url = response.pop('attachment_url')

                    to_add = True
                    try:
                        r_obj = container[i]
                        to_add = False
                    except IndexError:
                        r_obj = Response(response.get('text',''))

                    for k, v in response.items():
                        setattr(r_obj, k, v)

                    if attachment_filename and attachment_url:
                        # import pdb; pdb.set_trace()
                        attachment = self.setAttachment(attachment_filename,
                            self.orig_plone_url + '/'.join(obj.getPhysicalPath()[2:]) + attachment_url)
                        #self.orig_plone_url + '/' + attachment_url)
                        if attachment:
                            r_obj.attachment = attachment

                    if to_add:
                        container.add(r_obj)
                    i += 1

            yield item
Esempio n. 4
0
def replace_old_with_new_responses(issue):
    if not IIssue.providedBy(issue):
        return
    responses = issue.contentValues(filter={'portal_type': 'PoiResponse'})
    folder = IResponseContainer(issue)
    try:
        request = issue.REQUEST
    except AttributeError:
        # When called via prefs_install_products_form (Plone 3.3) we
        # have no REQUEST object here.  We will use a dummy then.
        request = TestRequest()
    createview = Create(issue, request)
    path = '/'.join(issue.getPhysicalPath())
    logger.debug("Migrating %s responses for issue at %s",
                 len(responses), path)
    if not responses:
        return
    for old_response in responses:
        field = old_response.getField('response')
        text = field.getRaw(old_response)
        new_response = Response(text)
        new_response.mimetype = field.getContentType(old_response)
        new_response.creator = old_response.Creator()
        new_response.date = old_response.CreationDate()
        new_response.type = createview.determine_response_type(new_response)
        changes = old_response.getIssueChanges()
        for change in changes:
            new_response.add_change(**change)
        attachment_field = old_response.getField('attachment')
        attachment = attachment_field.getRaw(old_response)
        if attachment.get_size() > 0:
            new_response.attachment = attachment
        folder.add(new_response)
        issue._delObject(old_response.getId())
    # This seems a good time to reindex the issue for good measure.
    issue.reindexObject()
Esempio n. 5
0
def replace_old_with_new_responses(issue):
    if not IIssue.providedBy(issue):
        return
    responses = issue.contentValues(filter={'portal_type': 'PoiResponse'})
    folder = IResponseContainer(issue)
    try:
        request = issue.REQUEST
    except AttributeError:
        # When called via prefs_install_products_form (Plone 3.3) we
        # have no REQUEST object here.  We will use a dummy then.
        request = TestRequest()
    createview = Create(issue, request)
    path = '/'.join(issue.getPhysicalPath())
    logger.debug("Migrating %s responses for issue at %s", len(responses),
                 path)
    if not responses:
        return
    for old_response in responses:
        field = old_response.getField('response')
        text = field.getRaw(old_response)
        new_response = Response(text)
        new_response.mimetype = field.getContentType(old_response)
        new_response.creator = old_response.Creator()
        new_response.date = old_response.CreationDate()
        new_response.type = createview.determine_response_type(new_response)
        changes = old_response.getIssueChanges()
        for change in changes:
            new_response.add_change(**change)
        attachment_field = old_response.getField('attachment')
        attachment = attachment_field.getRaw(old_response)
        if attachment.get_size() > 0:
            new_response.attachment = attachment
        folder.add(new_response)
        issue._delObject(old_response.getId())
    # This seems a good time to reindex the issue for good measure.
    issue.reindexObject()
Esempio n. 6
0
 def add_response(self, issue, text, mimetype, attachment):
     new_response = Response(text)
     new_response.mimetype = mimetype
     new_response.attachment = attachment
     folder = IResponseContainer(issue)
     folder.add(new_response)