Пример #1
0
    def reorder_pinned_topics(self, order):
        """
        Puts the pinned discussion topics in the specified order.
        All pinned topics should be included.

        :calls: `POST /api/v1/groups/:group_id/discussion_topics/reorder \
        <https://canvas.instructure.com/doc/api/discussion_topics.html#method.discussion_topics.reorder>`_

        :param order: The ids of the pinned discussion topics in the desired order.
            e.g. [104, 102, 103]
        :type order: iterable sequence of values

        :rtype: :class:`canvasapi.paginated_list.PaginatedList` of
            :class:`canvasapi.discussion_topic.DiscussionTopic`
        """
        # Convert list or tuple to comma-separated string
        if is_multivalued(order):
            order = ",".join([text_type(topic_id) for topic_id in order])

        # Check if is a string with commas
        if not isinstance(order, text_type) or "," not in order:
            raise ValueError("Param `order` must be a list, tuple, or string.")

        response = self._requester.request(
            'POST',
            'groups/{}/discussion_topics/reorder'.format(self.id),
            order=order
        )

        return response.json().get('reorder')
    def reorder_custom_columns(self, order, **kwargs):
        """
        Put the given columns in a specific order based on given parameter.

        :calls: `POST /api/v1/courses/:course_id/custom_gradebook_columns/reorder \
            <https://canvas.instructure.com/doc/api/custom_gradebook_columns.html#method.custom_gradebook_columns_api.reorder>`_

        :param order: The order the columns are supposed to be in.
        :type order: list of int

        :returns: True if successful (status code of 200)
        :rtype: bool
        """
        # Convert iterable sequence to comma-separated string
        if is_multivalued(order):
            order = ",".join([str(topic_id) for topic_id in order])

        # Check if is a string with commas
        if not isinstance(order, str) or "," not in order:
            raise ValueError("Param `order` must be a list, tuple, or string.")

        response = self._requester.request(
            "POST",
            "courses/{}/custom_gradebook_columns/reorder".format(
                self.course_id),
            _kwargs=combine_kwargs(**kwargs),
            order=order,
        )

        return response.json().get("reorder")
Пример #3
0
 def test_is_multivalued_dict(self, m):
     self.assertTrue(is_multivalued({'key': 'value'}))
Пример #4
0
 def test_is_multivalued_set_iter(self, m):
     self.assertTrue(is_multivalued(iter({'element'})))
Пример #5
0
 def test_is_multivalued_tuple_iter(self, m):
     self.assertTrue(is_multivalued(iter(('item', ))))
Пример #6
0
 def test_is_multivalued_list_iter(self, m):
     self.assertTrue(is_multivalued(iter(['item'])))
Пример #7
0
 def test_is_multivalued_list(self, m):
     self.assertTrue(is_multivalued(["item"]))
Пример #8
0
 def test_is_multivalued_zip(self, m):
     self.assertTrue(is_multivalued(zip((1, ), (2, ))))
Пример #9
0
    def test_is_multivalued_generator_call(self, m):
        def yielder():
            yield 'item'

        self.assertTrue(is_multivalued(yielder()))
Пример #10
0
 def test_is_multivalued_integer_types(self, m):
     for type in integer_types:
         self.assertFalse(is_multivalued(type(1)))
Пример #11
0
 def test_is_multivalued_bool(self, m):
     self.assertFalse(is_multivalued(False))
Пример #12
0
 def test_is_multivalued_dict_items(self, m):
     self.assertTrue(is_multivalued({"key": "value"}.items()))
Пример #13
0
 def test_is_multivalued_dict_iter(self, m):
     self.assertTrue(is_multivalued(iter({"key": "value"})))
Пример #14
0
 def test_is_multivalued_set(self, m):
     self.assertTrue(is_multivalued({"element"}))
Пример #15
0
 def test_is_multivalued_tuple(self, m):
     self.assertTrue(is_multivalued(("item",)))
Пример #16
0
 def test_is_multivalued_dict_items(self, m):
     self.assertTrue(is_multivalued(iteritems({'key': 'value'})))
Пример #17
0
 def test_is_multivalued_generator_expr(self, m):
     self.assertTrue(is_multivalued(item for item in ('item', )))
Пример #18
0
 def test_is_multivalued_str(self, m):
     self.assertFalse(is_multivalued('string'))
Пример #19
0
 def test_is_multivalued_chain(self, m):
     self.assertTrue(is_multivalued(chain((1, ), (2, ))))
Пример #20
0
 def test_is_multivalued_unicode(self, m):
     self.assertFalse(is_multivalued(u'unicode'))
Пример #21
0
 def test_is_multivalued_bytes(self, m):
     self.assertFalse(is_multivalued(b'bytes'))
Пример #22
0
 def test_is_multivalued_integer(self, m):
     self.assertFalse(is_multivalued(int(1)))