Ejemplo n.º 1
0
    def item_new(self, login_bundle, atom_tag, data):
        """Create a new topic, comment, or workspace page. Return atom_tag of new item.

        Parameters:

            atom_tag:       atom_tag of container of new item. Should be
                            either a Discussions tag, a topic tag, or a
                            Workspace tag, like this:

                            tag:ned.com:/group/group_name/news/
                            tag:ned.com:/group/group_name/news/23/
                            tag:ned.com:/group/group_name/ws/

                            Depending on the atom_tag, this function will
                            either create a new discussion topic, a new
                            comment within a discussion, or a new workspace
                            page.

            data:           struct containing:

                                title:  title of new item (ignored for comments)
                                text:   text of new item
        """
        user = self._check_login(login_bundle)
        obj = self._get_blog_or_wiki(user, atom_tag)

        api = adapt(obj, INewItemAPI, None)
        if not api:
            raise xmlrpclib.Fault(FAULT_INVALID_ITEM, 'Cannot create a new item here.')

        api.set_user(user)
        item = api.new_item(data)
        return api.atom_id()
Ejemplo n.º 2
0
    def item_edit(self, login_bundle, atom_tag, data):
        """Edit an item's data. Item may be a topic, comment, or workspace page.

        Valid fields in data are:

            title:      new title of item
            text:       new text of item

        Fields not provided are left unchanged. Editing a workspace page creates
        a new revision and ignores 'title' field.
        """
        user = self._check_login(login_bundle)
        obj = lookup_atom_id(atom_tag)
        api = adapt(obj, IItemAPI, None)
        if api:
            api.set_user(user)
            api.edit_item(data)
            return True

        raise xmlrpclib.Fault(FAULT_INVALID_ITEM, 'Cannot edit this type of item.')
Ejemplo n.º 3
0
    def item_data(self, login_bundle, atom_tag, fields):
        """Return struct containing requested fields for specified item.

        Parameters:
            atom_tag:        atom_tag of item.
            fields: array of requested information:
                feedback:   extended feedback information
                text:       full raw (reStructuredText) text
                html:       html of item text

        Returns:
            struct of requested information (fields) as well as:
                atom_tag:       atom_tag of item
                title:          title of item
                author:         author of item
                created:        date item created
                modified:       date item modifed (only if modified)
                feedback_score: feedback score of item
                comment_count:  number of comments (only if item is a discussion topic)
                revision_count: number of revisions (only if item is a workspace page)

        For example, if fields is an empty array, the returned struct will
        include all of the above fields, but not the detailed feedback, nor
        the actual text of the item itself.
        """
        user = self._check_login(login_bundle)
        obj = lookup_atom_id(atom_tag)
        if not obj:
            raise xmlrpclib.Fault(FAULT_INVALID_ITEM, 'Invalid atom_tag.')

        api = adapt(obj, IItemAPI, None)
        if api:
            api.set_user(user)
            return api.get_item(fields)

        raise xmlrpclib.Fault(FAULT_INVALID_ITEM, 'Could not dispatch to API.')