Example #1
0
    def update_learn_api(self):
        if not self.pk:
            return
        try:
            learn_model.update_course_listing(**self.get_learn_api_data())
        except:
            learn_model.add_course_listing(**self.get_learn_api_data())

        course_url = reverse('projects_show', kwargs={'slug': self.slug})
        course_lists = learn_model.get_lists_for_course(course_url)
        list_names = [ l['name'] for l in course_lists ]
        if self.not_listed or self.test:
            for list_name in list_names:
                learn_model.remove_course_from_list(course_url, list_name)
        else:
            desired_list = 'drafts'
            if not (self.under_development or self.archived):
                desired_list = 'listed'
            elif self.archived:
                desired_list = 'archived'
            possible_lists = ['drafts', 'listed', 'archived']
            possible_lists.remove(desired_list)
            for l in possible_lists:
                if l in list_names:
                    learn_model.remove_course_from_list(course_url, l)
            if desired_list not in list_names:
                learn_model.add_course_to_list(course_url, desired_list)
Example #2
0
    def update_learn_api(self):
        if not self.pk:
            return
        try:
            learn_model.update_course_listing(**self.get_learn_api_data())
        except:
            learn_model.add_course_listing(**self.get_learn_api_data())

        course_url = reverse('projects_show', kwargs={'slug': self.slug})
        course_lists = learn_model.get_lists_for_course(course_url)
        list_names = [ l['name'] for l in course_lists ]
        if self.not_listed or self.test:
            for list_name in list_names:
                learn_model.remove_course_from_list(course_url, list_name)
        else:
            desired_list = 'drafts'
            if not (self.under_development or self.archived):
                desired_list = 'listed'
            elif self.archived:
                desired_list = 'archived'
            possible_lists = ['drafts', 'listed', 'archived']
            possible_lists.remove(desired_list)
            for l in possible_lists:
                if l in list_names:
                    learn_model.remove_course_from_list(course_url, l)
            if desired_list not in list_names:
                learn_model.add_course_to_list(course_url, desired_list)
Example #3
0
    def update_learn_api(self):
        if not self.pk:
            return
        try:
            learn_model.update_course_listing(**self.get_learn_api_data())
        except:
            learn_model.add_course_listing(**self.get_learn_api_data())

        course_url = reverse("projects_show", kwargs={"slug": self.slug})
        course_lists = learn_model.get_lists_for_course(course_url)
        list_names = [l["name"] for l in course_lists]
        if self.not_listed or self.test:
            for list_name in list_names:
                learn_model.remove_course_from_list(course_url, list_name)
        else:
            desired_list = "drafts"
            if not (self.under_development or self.archived):
                desired_list = "listed"
            elif self.archived:
                desired_list = "archived"
            possible_lists = ["drafts", "listed", "archived"]
            possible_lists.remove(desired_list)
            for l in possible_lists:
                if l in list_names:
                    learn_model.remove_course_from_list(course_url, l)
            if desired_list not in list_names:
                learn_model.add_course_to_list(course_url, desired_list)
Example #4
0
def update_course_learn_api(course_uri):
    """ send updated course info to the learn API to update course listing """
    course_db = _get_course_db(course_uri)
    try:
        learn_model.update_course_listing(**get_course_learn_api_data(course_uri))
    except:
        log.error("Could not update learn index information!")
Example #5
0
def update_course_learn_api(course_uri):
    """ send updated course info to the learn API to update course listing """
    course_db = _get_course_db(course_uri)
    try:
        learn_model.update_course_listing(
            **get_course_learn_api_data(course_uri))
    except:
        log.error("Could not update learn index information!")
Example #6
0
    def test_update_course(self):
        """ test that course data gets updated """

        add_course_listing(**self.test_course)
        updated_course = {
            "title": 'New Title',
            "description": "New description",
            "data_url": "http://example.com", 
            "language": "es", 
            "thumbnail_url": "http://p2pu.org/media/new_image.png"
        }
        update_course_listing(self.test_course['course_url'] ,**updated_course)
        listed_courses = get_listed_courses()

        self.assertTrue(len(listed_courses) == 1)
        self.assertTrue(listed_courses[0].title == updated_course['title'])
        self.assertTrue(listed_courses[0].description == updated_course['description'])
        self.assertTrue(listed_courses[0].data_url == updated_course['data_url'])
        self.assertTrue(listed_courses[0].language == updated_course['language'])
        self.assertTrue(listed_courses[0].thumbnail_url == updated_course['thumbnail_url'])
Example #7
0
    def test_update_course(self):
        """ test that course data gets updated """

        add_course_listing(**self.test_course)
        updated_course = {
            "title": 'New Title',
            "description": "New description",
            "data_url": "http://example.com",
            "language": "es",
            "thumbnail_url": "http://p2pu.org/media/new_image.png"
        }
        update_course_listing(self.test_course['course_url'], **updated_course)
        listed_courses = get_listed_courses()

        self.assertTrue(len(listed_courses) == 1)
        self.assertTrue(listed_courses[0].title == updated_course['title'])
        self.assertTrue(
            listed_courses[0].description == updated_course['description'])
        self.assertTrue(
            listed_courses[0].data_url == updated_course['data_url'])
        self.assertTrue(
            listed_courses[0].language == updated_course['language'])
        self.assertTrue(
            listed_courses[0].thumbnail_url == updated_course['thumbnail_url'])
    def handle(self, *args, **options):
        listed = Project.objects.filter(
            not_listed=False,
            deleted=False,
            archived=False,
            test=False
        )

        # create lists for schools
        for school in School.objects.all():
            try:
                create_list(
                    school.slug, school.name, 
                    "http://p2pu.org/en/schools/{0}".format(school.slug)
                )
            except:
                pass

            try:
                create_list(
                    "{0}_featured".format(school.slug),
                    "{0} featured".format(school.name),
                    "http://p2pu.org/en/schools/{0}".format(school.slug)
                )
            except:
                pass

        # create list for listed courses
        try:
            create_list("listed", "Listed courses", "")
        except:
            pass

        # create list for draft courses
        try:
            create_list("drafts", "Draft courses", "")
        except:
            pass


        listed = listed.filter(
            Q(category=Project.CHALLENGE)
            | Q(sign_up__status=Signup.MODERATED)
            | Q(sign_up__status=Signup.NON_MODERATED)
        )

        listed = listed.order_by('created_on')

        for project in listed:
            project_tags = project.tags.all().values_list('name', flat=True)
            args = dict(
                course_url = "/en/groups/{0}/".format(project.slug),
                title = project.name,
                description = project.short_description,
                data_url = "/en/groups/{0}/data".format(project.slug),
                language = project.language,
                thumbnail_url = "http://p2pu.org{0}".format(project.get_image_url()),
                tags = project_tags
            )
            try:
                add_course_listing(**args)
            except:
                update_course_listing(**args)

            if project.under_development == True:
                try:
                    add_course_to_list(args["course_url"], "drafts")
                except:
                    pass
            else:
                try:
                    add_course_to_list(args["course_url"], "listed")
                except:
                    pass

            if project.school:
                try:
                    add_course_to_list(args['course_url'], project.school.slug)
                except:
                    pass

        # create lists
        try:
            create_list('community', "Community Picks", "")
        except:
            pass

        try:
            create_list('showcase', "Showcased", "")
        except:
            pass

        for project in listed.filter(community_featured=True):
            course_url = "/en/groups/{0}/".format(project.slug)
            try:
                add_course_to_list(course_url, 'community')
            except:
                pass

        for project in listed.filter(featured=True):
            course_url = "/en/groups/{0}/".format(project.slug)
            add_course_to_list(course_url, 'showcase')

        for school in School.objects.all():
            for project in school.featured.all():
                course_url = "/en/groups/{0}/".format(project.slug)
                list_name = "{0}_featured".format(school.slug)
                try:
                    add_course_to_list(course_url, list_name)
                except:
                    pass
Example #9
0
    def handle(self, *args, **options):
        listed = Project.objects.filter(not_listed=False,
                                        deleted=False,
                                        archived=False,
                                        test=False)

        # create lists for schools
        for school in School.objects.all():
            try:
                create_list(
                    school.slug, school.name,
                    "http://p2pu.org/en/schools/{0}".format(school.slug))
            except:
                pass

            try:
                create_list(
                    "{0}_featured".format(school.slug),
                    "{0} featured".format(school.name),
                    "http://p2pu.org/en/schools/{0}".format(school.slug))
            except:
                pass

        # create list for listed courses
        try:
            create_list("listed", "Listed courses", "")
        except:
            pass

        # create list for draft courses
        try:
            create_list("drafts", "Draft courses", "")
        except:
            pass

        listed = listed.filter(
            Q(category=Project.CHALLENGE)
            | Q(sign_up__status=Signup.MODERATED)
            | Q(sign_up__status=Signup.NON_MODERATED))

        listed = listed.order_by('created_on')

        for project in listed:
            project_tags = project.tags.all().values_list('name', flat=True)
            args = dict(course_url="/en/groups/{0}/".format(project.slug),
                        title=project.name,
                        description=project.short_description,
                        data_url="/en/groups/{0}/data".format(project.slug),
                        language=project.language,
                        thumbnail_url="http://p2pu.org{0}".format(
                            project.get_image_url()),
                        tags=project_tags)
            try:
                add_course_listing(**args)
            except:
                update_course_listing(**args)

            if project.under_development == True:
                try:
                    add_course_to_list(args["course_url"], "drafts")
                except:
                    pass
            else:
                try:
                    add_course_to_list(args["course_url"], "listed")
                except:
                    pass

            if project.school:
                try:
                    add_course_to_list(args['course_url'], project.school.slug)
                except:
                    pass

        # create lists
        try:
            create_list('community', "Community Picks", "")
        except:
            pass

        try:
            create_list('showcase', "Showcased", "")
        except:
            pass

        for project in listed.filter(community_featured=True):
            course_url = "/en/groups/{0}/".format(project.slug)
            try:
                add_course_to_list(course_url, 'community')
            except:
                pass

        for project in listed.filter(featured=True):
            course_url = "/en/groups/{0}/".format(project.slug)
            add_course_to_list(course_url, 'showcase')

        for school in School.objects.all():
            for project in school.featured.all():
                course_url = "/en/groups/{0}/".format(project.slug)
                list_name = "{0}_featured".format(school.slug)
                try:
                    add_course_to_list(course_url, list_name)
                except:
                    pass