def get_or_create_content_group(store, course):
        """
        Returns the first user partition from the course which uses the
        CohortPartitionScheme, or generates one if no such partition is
        found.  The created partition is not saved to the course until
        the client explicitly creates a group within the partition and
        POSTs back.
        """
        content_group_configuration = get_cohorted_user_partition(course)
        if content_group_configuration is None:
            content_group_configuration = UserPartition(
                id=generate_int_id(MINIMUM_GROUP_ID, MYSQL_MAX_INT, GroupConfiguration.get_used_ids(course)),
                name=CONTENT_GROUP_CONFIGURATION_NAME,
                description=CONTENT_GROUP_CONFIGURATION_DESCRIPTION,
                groups=[],
                scheme_id=COHORT_SCHEME
            )
            return content_group_configuration.to_json()

        content_group_configuration = GroupConfiguration.update_partition_usage_info(
            store,
            course,
            content_group_configuration
        )
        return content_group_configuration
    def get_or_create_content_group(store, course):
        """
        Returns the first user partition from the course which uses the
        CohortPartitionScheme, or generates one if no such partition is
        found.  The created partition is not saved to the course until
        the client explicitly creates a group within the partition and
        POSTs back.
        """
        content_group_configuration = get_cohorted_user_partition(course)
        if content_group_configuration is None:
            content_group_configuration = UserPartition(
                id=generate_int_id(MINIMUM_GROUP_ID, MYSQL_MAX_INT, GroupConfiguration.get_used_ids(course)),
                name=CONTENT_GROUP_CONFIGURATION_NAME,
                description=CONTENT_GROUP_CONFIGURATION_DESCRIPTION,
                groups=[],
                scheme_id=COHORT_SCHEME
            )
            return content_group_configuration.to_json()

        content_group_configuration = GroupConfiguration.update_content_group_usage_info(
            store,
            course,
            content_group_configuration
        )
        return content_group_configuration
    def filter_dictionary(self, **kwargs):
        """ base implementation which filters via start_date """
        filter_dictionary = super(LmsSearchFilterGenerator,
                                  self).filter_dictionary(**kwargs)
        if 'user' in kwargs and 'course_id' in kwargs and kwargs['course_id']:
            user = kwargs['user']
            try:
                course_key = CourseKey.from_string(kwargs['course_id'])
            except InvalidKeyError:
                course_key = SlashSeparatedCourseKey.from_deprecated_string(
                    kwargs['course_id'])

            # Staff user looking at course as staff user
            if get_user_role(user, course_key) == 'staff':
                return filter_dictionary

            cohorted_user_partition = get_cohorted_user_partition(course_key)
            if cohorted_user_partition:
                partition_group = cohorted_user_partition.scheme.get_group_for_user(
                    course_key,
                    user,
                    cohorted_user_partition,
                )
                filter_dictionary['content_groups'] = unicode(
                    partition_group.id) if partition_group else None
        return filter_dictionary
    def _iterate_items_and_content_group_ids(course, items):
        """
        Iterate through items and content group IDs in a course.

        This will yield group IDs *only* for cohort user partitions.

        Yields: tuple of (item, group_id)
        """
        content_group_configuration = get_cohorted_user_partition(course)
        if content_group_configuration is not None:
            for item in items:
                if hasattr(item, 'group_access') and item.group_access:
                    group_ids = item.group_access.get(content_group_configuration.id, [])

                    for group_id in group_ids:
                        yield item, group_id
    def _iterate_items_and_content_group_ids(course, items):
        """
        Iterate through items and content group IDs in a course.

        This will yield group IDs *only* for cohort user partitions.

        Yields: tuple of (item, group_id)
        """
        content_group_configuration = get_cohorted_user_partition(course)
        if content_group_configuration is not None:
            for item in items:
                if hasattr(item, 'group_access') and item.group_access:
                    group_ids = item.group_access.get(
                        content_group_configuration.id, [])

                    for group_id in group_ids:
                        yield item, group_id
    def filter_dictionary(self, **kwargs):
        """ base implementation which filters via start_date """
        filter_dictionary = super(LmsSearchFilterGenerator, self).filter_dictionary(**kwargs)
        if "user" in kwargs and "course_id" in kwargs and kwargs["course_id"]:
            user = kwargs["user"]
            try:
                course_key = CourseKey.from_string(kwargs["course_id"])
            except InvalidKeyError:
                course_key = SlashSeparatedCourseKey.from_deprecated_string(kwargs["course_id"])

            # Staff user looking at course as staff user
            if get_user_role(user, course_key) == "staff":
                return filter_dictionary

            cohorted_user_partition = get_cohorted_user_partition(course_key)
            if cohorted_user_partition:
                partition_group = cohorted_user_partition.scheme.get_group_for_user(
                    course_key, user, cohorted_user_partition
                )
                filter_dictionary["content_groups"] = unicode(partition_group.id) if partition_group else None
        return filter_dictionary