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")
def test_is_multivalued_dict(self, m): self.assertTrue(is_multivalued({'key': 'value'}))
def test_is_multivalued_set_iter(self, m): self.assertTrue(is_multivalued(iter({'element'})))
def test_is_multivalued_tuple_iter(self, m): self.assertTrue(is_multivalued(iter(('item', ))))
def test_is_multivalued_list_iter(self, m): self.assertTrue(is_multivalued(iter(['item'])))
def test_is_multivalued_list(self, m): self.assertTrue(is_multivalued(["item"]))
def test_is_multivalued_zip(self, m): self.assertTrue(is_multivalued(zip((1, ), (2, ))))
def test_is_multivalued_generator_call(self, m): def yielder(): yield 'item' self.assertTrue(is_multivalued(yielder()))
def test_is_multivalued_integer_types(self, m): for type in integer_types: self.assertFalse(is_multivalued(type(1)))
def test_is_multivalued_bool(self, m): self.assertFalse(is_multivalued(False))
def test_is_multivalued_dict_items(self, m): self.assertTrue(is_multivalued({"key": "value"}.items()))
def test_is_multivalued_dict_iter(self, m): self.assertTrue(is_multivalued(iter({"key": "value"})))
def test_is_multivalued_set(self, m): self.assertTrue(is_multivalued({"element"}))
def test_is_multivalued_tuple(self, m): self.assertTrue(is_multivalued(("item",)))
def test_is_multivalued_dict_items(self, m): self.assertTrue(is_multivalued(iteritems({'key': 'value'})))
def test_is_multivalued_generator_expr(self, m): self.assertTrue(is_multivalued(item for item in ('item', )))
def test_is_multivalued_str(self, m): self.assertFalse(is_multivalued('string'))
def test_is_multivalued_chain(self, m): self.assertTrue(is_multivalued(chain((1, ), (2, ))))
def test_is_multivalued_unicode(self, m): self.assertFalse(is_multivalued(u'unicode'))
def test_is_multivalued_bytes(self, m): self.assertFalse(is_multivalued(b'bytes'))
def test_is_multivalued_integer(self, m): self.assertFalse(is_multivalued(int(1)))