示例#1
0
    def update_items(self, sources, fields=None):
        item_type = self.request.form.get("item_type")
        mtool = getToolByName(self.context, 'portal_membership')

        if item_type == 'pages' and PROJ_HOME in sources:
            sources.remove("project-home")

        ids = [x.split("/")[-1] for x in sources]
        brains = self.catalog(id=ids, path=self.project_path)

        snippets = {}
        objects = dict([(b.getPath(), b.getObject()) for b in brains])
        
        macro = self.template.macros['item_row']
        for old, new in zip(sources, fields):
            page = objects[old]
            if bool(mtool.checkPermission(ModifyPortalContent, page)):
                page.setTitle(new['title'])
                page.reindexObject(('Title',))

            data = dict(item=self._make_dict_and_translate(page, self.needed_values[item_type]),
                        item_type=item_type,
                        item_collection=dict(editable=self.needed_values[item_type].editable),
                        )
            
            tal_context = tal.create_tal_context(self, **data)
            path = '/'.join(page.getPhysicalPath())
            snippets[path] = {
                'html': tal.render_tal(macro, tal_context),
                'effects': 'highlight',
                'action': 'replace'
                }
        return snippets
示例#2
0
    def resort(self, sources, fields=None):
        item_type = self.request.form.get("item_type")
        if item_type not in self._portal_type:
            return False

        sort_by = self.request.form.get("sort_by")
        sort_order = self.request.form.get("sort_order", 'descending')
        items = self._resort(item_type, sort_by, sort_order)

        if sort_order == 'ascending':
            sort_order = 'descending'
        else:
            sort_order = 'ascending'

        thead_macro = self.template.macros['item_thead_snippet']
        thead_data = dict(item_type=item_type,
                          item_date_author_header=(item_type=='pages' and "Last Modified" or "Created"),
                          sort_on=sort_by,
                          sort_order=sort_order,
                          item_collection=items)
        thead_context = tal.create_tal_context(self, **thead_data)
        thead_obj = {'html': tal.render_tal(thead_macro, thead_context),
                     'effects': '',
                     'action': 'replace'
                     }

        tbody_macro = self.template.macros['item_tbody_snippet']
        tbody_data = dict(item_collection=items)
        tbody_context = tal.create_tal_context(self, **tbody_data)
        tbody_obj = {'html': tal.render_tal(tbody_macro, tbody_context, macros=self.template.macros),
                     'effects': 'highlight',
                     'action': 'replace'
                     }
        
        return {'oc-%s-tbody' % item_type: tbody_obj,
                'oc-%s-thead' % item_type: thead_obj
                }