当前位置: 首页>>代码示例>>Python>>正文


Python SP.updates方法代码示例

本文整理汇总了Python中sharepoint.xml.SP.updates方法的典型用法代码示例。如果您正苦于以下问题:Python SP.updates方法的具体用法?Python SP.updates怎么用?Python SP.updates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sharepoint.xml.SP的用法示例。


在下文中一共展示了SP.updates方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: save

# 需要导入模块: from sharepoint.xml import SP [as 别名]
# 或者: from sharepoint.xml.SP import updates [as 别名]
    def save(self):
        """
        Updates the list with changes.
        """
        # Based on the documentation at
        # http://msdn.microsoft.com/en-us/library/lists.lists.updatelistitems%28v=office.12%29.aspx

        # Note, this ends up un-namespaced. SharePoint doesn't care about
        # namespaces on this XML node, and will bork if any of these elements
        # have a namespace prefix. Likewise Method and Field in
        # SharePointRow.get_batch_method().
        batches = E.Batch(ListVersion="1", OnError="Return")
        # Here's the root element of our SOAP request.
        xml = SP.UpdateListItems(SP.listName(self.id), SP.updates(batches))

        # rows_by_batch_id contains a mapping from new rows to their batch
        # IDs, so we can set their IDs when they are returned by SharePoint.
        rows_by_batch_id, batch_id = {}, 1

        for row in self._rows:
            batch = row.get_batch_method()
            if batch is None:
                continue
            # Add the batch ID
            batch.attrib["ID"] = unicode(batch_id)
            rows_by_batch_id[batch_id] = row
            batches.append(batch)
            batch_id += 1

        for row in self._deleted_rows:
            batch = E.Method(E.Field(unicode(row.id), Name="ID"), ID=unicode(batch_id), Cmd="Delete")
            rows_by_batch_id[batch_id] = row
            batches.append(batch)
            batch_id += 1

        if len(batches) == 0:
            return

        response = self.opener.post_soap(
            LIST_WEBSERVICE, xml, soapaction="http://schemas.microsoft.com/sharepoint/soap/UpdateListItems"
        )

        for result in response.xpath(".//sp:Result", namespaces=namespaces):
            batch_id, batch_result = result.attrib["ID"].split(",")
            row = rows_by_batch_id[int(batch_id)]

            error_code = result.find("sp:ErrorCode", namespaces=namespaces)
            error_text = result.find("sp:ErrorText", namespaces=namespaces)
            if error_code is not None and error_code.text != "0x00000000":
                raise UpdateFailedError(row, batch_result, error_code.text, error_text.text)

            if batch_result in ("Update", "New"):
                row._update(result.xpath("z:row", namespaces=namespaces)[0], clear=True)
            else:
                self._deleted_rows.remove(row)

        assert not self._deleted_rows
        assert not any(row._changed for row in self.rows)
开发者ID:vpineda7,项目名称:python-sharepoint,代码行数:60,代码来源:__init__.py

示例2: set_status

# 需要导入模块: from sharepoint.xml import SP [as 别名]
# 或者: from sharepoint.xml.SP import updates [as 别名]
    def set_status(self, rows, status, comment=None):
        rows_by_batch_id, batch_id = {}, 1
        
        if isinstance(status, int):
            status = moderation_statuses[status]
        
        batches = E.Batch(ListVersion='1', OnError='Return')
        # Here's the root element of our SOAP request.
        xml = SP.UpdateListItems(SP.listName(self._list.id), SP.updates(batches))

        if comment:
            comment = E.Field(text_type(comment),
                              Name='_ModerationComment')
        
        for row in rows:
            batch = E.Method(E.Field(text_type(row.id),
                                     Name='ID'),
                             E.Field(text_type(status.value),
                                     Name='_ModerationStatus'),
                             ID=text_type(batch_id), Cmd='Moderate')
            if comment:
                batch.append(comment)
            rows_by_batch_id[batch_id] = row
            batches.append(batch)
            batch_id += 1

        response = self._list.opener.post_soap(
            LIST_WEBSERVICE, xml,
            soapaction='http://schemas.microsoft.com/sharepoint/soap/UpdateListItems')
        
        for result in response.xpath('.//sp:Result', namespaces=namespaces):
            batch_id, batch_result = result.attrib['ID'].split(',')
            row = rows_by_batch_id[int(batch_id)]

            error_code = result.find('sp:ErrorCode', namespaces=namespaces)
            error_text = result.find('sp:ErrorText', namespaces=namespaces)
            if error_code is not None and error_code.text != '0x00000000':
                raise UpdateFailedError(row, batch_result,
                                        error_code.text,
                                        error_text.text)

            if batch_result == 'Moderate':
                row._update(result.xpath('z:row', namespaces=namespaces)[0],
                            clear=True)
开发者ID:ox-it,项目名称:python-sharepoint,代码行数:46,代码来源:moderation.py

示例3: set_status

# 需要导入模块: from sharepoint.xml import SP [as 别名]
# 或者: from sharepoint.xml.SP import updates [as 别名]
    def set_status(self, rows, status, comment=None):
        rows_by_batch_id, batch_id = {}, 1

        if isinstance(status, int):
            status = moderation_statuses[status]

        batches = E.Batch(ListVersion="1", OnError="Return")
        # Here's the root element of our SOAP request.
        xml = SP.UpdateListItems(SP.listName(self._list.id), SP.updates(batches))

        if comment:
            comment = E.Field(unicode(comment), Name="_ModerationComment")

        for row in rows:
            batch = E.Method(
                E.Field(unicode(row.id), Name="ID"),
                E.Field(unicode(status.value), Name="_ModerationStatus"),
                ID=unicode(batch_id),
                Cmd="Moderate",
            )
            if comment:
                batch.append(comment)
            rows_by_batch_id[batch_id] = row
            batches.append(batch)
            batch_id += 1

        response = self._list.opener.post_soap(
            LIST_WEBSERVICE, xml, soapaction="http://schemas.microsoft.com/sharepoint/soap/UpdateListItems"
        )

        for result in response.xpath(".//sp:Result", namespaces=namespaces):
            batch_id, batch_result = result.attrib["ID"].split(",")
            row = rows_by_batch_id[int(batch_id)]

            error_code = result.find("sp:ErrorCode", namespaces=namespaces)
            error_text = result.find("sp:ErrorText", namespaces=namespaces)
            if error_code is not None and error_code.text != "0x00000000":
                raise UpdateFailedError(row, batch_result, error_code.text, error_text.text)

            if batch_result == "Moderate":
                row._update(result.xpath("z:row", namespaces=namespaces)[0], clear=True)
开发者ID:vpineda7,项目名称:python-sharepoint,代码行数:43,代码来源:moderation.py


注:本文中的sharepoint.xml.SP.updates方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。