Example #1
0
def settings_handler(request, tag=None, course_id=None, branch=None, version_guid=None, block=None):
    """
    Course settings for dates and about pages
    GET
        html: get the page
        json: get the CourseDetails model
    PUT
        json: update the Course and About xblocks through the CourseDetails model
    """
    locator, course_module = _get_locator_and_course(course_id, branch, version_guid, block, request.user)
    if "text/html" in request.META.get("HTTP_ACCEPT", "") and request.method == "GET":
        upload_asset_url = locator.url_reverse("assets/")

        return render_to_response(
            "settings.html",
            {
                "context_course": course_module,
                "course_locator": locator,
                "lms_link_for_about_page": utils.get_lms_link_for_about_page(course_module.location),
                "course_image_url": utils.course_image_url(course_module),
                "details_url": locator.url_reverse("/settings/details/"),
                "about_page_editable": not settings.FEATURES.get("ENABLE_MKTG_SITE", False),
                "upload_asset_url": upload_asset_url,
            },
        )
    elif "application/json" in request.META.get("HTTP_ACCEPT", ""):
        if request.method == "GET":
            return JsonResponse(
                CourseDetails.fetch(locator),
                # encoder serializes dates, old locations, and instances
                encoder=CourseSettingsEncoder,
            )
        else:  # post or put, doesn't matter.
            return JsonResponse(CourseDetails.update_from_json(locator, request.json), encoder=CourseSettingsEncoder)
 def test_update_and_fetch(self):
     # # NOTE: I couldn't figure out how to validly test time setting w/ all the conversions
     jsondetails = CourseDetails.fetch(self.course_location)
     jsondetails.syllabus = "<a href='foo'>bar</a>"
     # encode - decode to convert date fields and other data which changes
     # form
     self.assertEqual(
         CourseDetails.update_from_json(jsondetails.__dict__).syllabus,
         jsondetails.syllabus, "After set syllabus"
     )
     jsondetails.overview = "Overview"
     self.assertEqual(
         CourseDetails.update_from_json(jsondetails.__dict__).overview,
         jsondetails.overview, "After set overview"
     )
     jsondetails.intro_video = "intro_video"
     self.assertEqual(
         CourseDetails.update_from_json(jsondetails.__dict__).intro_video,
         jsondetails.intro_video, "After set intro_video"
     )
     jsondetails.effort = "effort"
     self.assertEqual(
         CourseDetails.update_from_json(jsondetails.__dict__).effort,
         jsondetails.effort, "After set effort"
     )
Example #3
0
def settings_handler(request,
                     tag=None,
                     package_id=None,
                     branch=None,
                     version_guid=None,
                     block=None):
    """
    Course settings for dates and about pages
    GET
        html: get the page
        json: get the CourseDetails model
    PUT
        json: update the Course and About xblocks through the CourseDetails model
    """
    locator, course_module = _get_locator_and_course(package_id, branch,
                                                     version_guid, block,
                                                     request.user)
    if 'text/html' in request.META.get('HTTP_ACCEPT',
                                       '') and request.method == 'GET':
        upload_asset_url = locator.url_reverse('assets/')

        # see if the ORG of this course can be attributed to a 'Microsite'. In that case, the
        # course about page should be editable in Studio
        about_page_editable = not microsite.get_value_for_org(
            course_module.location.org, 'ENABLE_MKTG_SITE',
            settings.FEATURES.get('ENABLE_MKTG_SITE', False))

        short_description_editable = settings.FEATURES.get(
            'EDITABLE_SHORT_DESCRIPTION', True)

        return render_to_response(
            'settings.html', {
                'context_course':
                course_module,
                'course_locator':
                locator,
                'lms_link_for_about_page':
                utils.get_lms_link_for_about_page(course_module.location),
                'course_image_url':
                utils.course_image_url(course_module),
                'details_url':
                locator.url_reverse('/settings/details/'),
                'about_page_editable':
                about_page_editable,
                'short_description_editable':
                short_description_editable,
                'upload_asset_url':
                upload_asset_url
            })
    elif 'application/json' in request.META.get('HTTP_ACCEPT', ''):
        if request.method == 'GET':
            return JsonResponse(
                CourseDetails.fetch(locator),
                # encoder serializes dates, old locations, and instances
                encoder=CourseSettingsEncoder)
        else:  # post or put, doesn't matter.
            return JsonResponse(CourseDetails.update_from_json(
                locator, request.json, request.user),
                                encoder=CourseSettingsEncoder)
Example #4
0
def settings_handler(request,
                     tag=None,
                     course_id=None,
                     branch=None,
                     version_guid=None,
                     block=None):
    """
    Course settings for dates and about pages
    GET
        html: get the page
        json: get the CourseDetails model
    PUT
        json: update the Course and About xblocks through the CourseDetails model
    """
    locator, course_module = _get_locator_and_course(course_id, branch,
                                                     version_guid, block,
                                                     request.user)
    if 'text/html' in request.META.get('HTTP_ACCEPT',
                                       '') and request.method == 'GET':
        upload_asset_url = locator.url_reverse('assets/')

        return render_to_response(
            'settings.html', {
                'context_course':
                course_module,
                'course_locator':
                locator,
                'lms_link_for_about_page':
                utils.get_lms_link_for_about_page(course_module.location),
                'course_image_url':
                utils.course_image_url(course_module),
                'details_url':
                locator.url_reverse('/settings/details/'),
                'about_page_editable':
                not settings.FEATURES.get('ENABLE_MKTG_SITE', False),
                'upload_asset_url':
                upload_asset_url
            })
    elif 'application/json' in request.META.get('HTTP_ACCEPT', ''):
        if request.method == 'GET':
            return JsonResponse(
                CourseDetails.fetch(locator),
                # encoder serializes dates, old locations, and instances
                encoder=CourseSettingsEncoder)
        else:  # post or put, doesn't matter.
            return JsonResponse(CourseDetails.update_from_json(
                locator, request.json),
                                encoder=CourseSettingsEncoder)
    def test_update_and_fetch(self):
        details = CourseDetails.fetch(self.course_location)

        # resp s/b json from here on
        url = reverse(
            'course_settings', kwargs={'org': self.course_location.org, 'course': self.course_location.course,
                                       'name': self.course_location.name, 'section': 'details'})
        resp = self.client.get(url)
        self.compare_details_with_encoding(json.loads(
            resp.content), details.__dict__, "virgin get")

        utc = UTC()
        self.alter_field(url, details, 'start_date', datetime.datetime(
            2012, 11, 12, 1, 30, tzinfo=utc))
        self.alter_field(url, details, 'start_date', datetime.datetime(
            2012, 11, 1, 13, 30, tzinfo=utc))
        self.alter_field(url, details, 'end_date', datetime.datetime(
            2013, 2, 12, 1, 30, tzinfo=utc))
        self.alter_field(url, details, 'enrollment_start', datetime.datetime(
            2012, 10, 12, 1, 30, tzinfo=utc))

        self.alter_field(url, details, 'enrollment_end', datetime.datetime(
            2012, 11, 15, 1, 30, tzinfo=utc))
        self.alter_field(url, details, 'overview', "Overview")
        self.alter_field(url, details, 'intro_video', "intro_video")
        self.alter_field(url, details, 'effort', "effort")
    def test_update_and_fetch(self):
        details = CourseDetails.fetch(self.course_location)

        # resp s/b json from here on
        url = reverse(
            "course_settings",
            kwargs={
                "org": self.course_location.org,
                "course": self.course_location.course,
                "name": self.course_location.name,
                "section": "details",
            },
        )
        resp = self.client.get(url)
        self.compare_details_with_encoding(json.loads(resp.content), details.__dict__, "virgin get")

        utc = UTC()
        self.alter_field(url, details, "start_date", datetime.datetime(2012, 11, 12, 1, 30, tzinfo=utc))
        self.alter_field(url, details, "start_date", datetime.datetime(2012, 11, 1, 13, 30, tzinfo=utc))
        self.alter_field(url, details, "end_date", datetime.datetime(2013, 2, 12, 1, 30, tzinfo=utc))
        self.alter_field(url, details, "enrollment_start", datetime.datetime(2012, 10, 12, 1, 30, tzinfo=utc))

        self.alter_field(url, details, "enrollment_end", datetime.datetime(2012, 11, 15, 1, 30, tzinfo=utc))
        self.alter_field(url, details, "overview", "Overview")
        self.alter_field(url, details, "intro_video", "intro_video")
        self.alter_field(url, details, "effort", "effort")
    def test_update_and_fetch(self):
        details = CourseDetails.fetch(self.course_location)

        # resp s/b json from here on
        url = reverse('course_settings',
                      kwargs={
                          'org': self.course_location.org,
                          'course': self.course_location.course,
                          'name': self.course_location.name,
                          'section': 'details'
                      })
        resp = self.client.get(url)
        self.compare_details_with_encoding(json.loads(resp.content),
                                           details.__dict__, "virgin get")

        utc = UTC()
        self.alter_field(url, details, 'start_date',
                         datetime.datetime(2012, 11, 12, 1, 30, tzinfo=utc))
        self.alter_field(url, details, 'start_date',
                         datetime.datetime(2012, 11, 1, 13, 30, tzinfo=utc))
        self.alter_field(url, details, 'end_date',
                         datetime.datetime(2013, 2, 12, 1, 30, tzinfo=utc))
        self.alter_field(url, details, 'enrollment_start',
                         datetime.datetime(2012, 10, 12, 1, 30, tzinfo=utc))

        self.alter_field(url, details, 'enrollment_end',
                         datetime.datetime(2012, 11, 15, 1, 30, tzinfo=utc))
        self.alter_field(url, details, 'overview', "Overview")
        self.alter_field(url, details, 'intro_video', "intro_video")
        self.alter_field(url, details, 'effort', "effort")
 def test_virgin_fetch(self):
     details = CourseDetails.fetch(self.course_location)
     self.assertEqual(details.course_location, self.course_location,
                      "Location not copied into")
     self.assertIsNotNone(details.start_date.tzinfo)
     self.assertIsNone(
         details.end_date,
         "end date somehow initialized " + str(details.end_date))
     self.assertIsNone(
         details.enrollment_start,
         "enrollment_start date somehow initialized " +
         str(details.enrollment_start))
     self.assertIsNone(
         details.enrollment_end,
         "enrollment_end date somehow initialized " +
         str(details.enrollment_end))
     self.assertIsNone(
         details.syllabus,
         "syllabus somehow initialized" + str(details.syllabus))
     self.assertEqual(details.overview, "",
                      "overview somehow initialized" + details.overview)
     self.assertIsNone(
         details.intro_video,
         "intro_video somehow initialized" + str(details.intro_video))
     self.assertIsNone(details.effort,
                       "effort somehow initialized" + str(details.effort))
Example #9
0
    def test_update_and_fetch(self):
        details = CourseDetails.fetch(self.course_locator)

        # resp s/b json from here on
        url = self.course_locator.url_reverse('settings/details/')
        resp = self.client.get_json(url)
        self.compare_details_with_encoding(json.loads(resp.content),
                                           details.__dict__, "virgin get")

        utc = UTC()
        self.alter_field(url, details, 'start_date',
                         datetime.datetime(2012, 11, 12, 1, 30, tzinfo=utc))
        self.alter_field(url, details, 'start_date',
                         datetime.datetime(2012, 11, 1, 13, 30, tzinfo=utc))
        self.alter_field(url, details, 'end_date',
                         datetime.datetime(2013, 2, 12, 1, 30, tzinfo=utc))
        self.alter_field(url, details, 'enrollment_start',
                         datetime.datetime(2012, 10, 12, 1, 30, tzinfo=utc))

        self.alter_field(url, details, 'enrollment_end',
                         datetime.datetime(2012, 11, 15, 1, 30, tzinfo=utc))
        self.alter_field(url, details, 'short_description',
                         "Short Description")
        self.alter_field(url, details, 'overview', "Overview")
        self.alter_field(url, details, 'intro_video', "intro_video")
        self.alter_field(url, details, 'effort', "effort")
        self.alter_field(url, details, 'course_image_name',
                         "course_image_name")
Example #10
0
 def test_virgin_fetch(self):
     details = CourseDetails.fetch(self.course_locator)
     self.assertEqual(details.org, self.course.location.org,
                      "Org not copied into")
     self.assertEqual(details.course_id, self.course.location.course,
                      "Course_id not copied into")
     self.assertEqual(details.run, self.course.location.name,
                      "Course name not copied into")
     self.assertEqual(details.course_image_name, self.course.course_image)
     self.assertIsNotNone(details.start_date.tzinfo)
     self.assertIsNone(
         details.end_date,
         "end date somehow initialized " + str(details.end_date))
     self.assertIsNone(
         details.enrollment_start,
         "enrollment_start date somehow initialized " +
         str(details.enrollment_start))
     self.assertIsNone(
         details.enrollment_end,
         "enrollment_end date somehow initialized " +
         str(details.enrollment_end))
     self.assertIsNone(
         details.syllabus,
         "syllabus somehow initialized" + str(details.syllabus))
     self.assertIsNone(
         details.intro_video,
         "intro_video somehow initialized" + str(details.intro_video))
     self.assertIsNone(details.effort,
                       "effort somehow initialized" + str(details.effort))
Example #11
0
    def handle(self, *args, **options):
        '''Handle management command request'''

        if len(args) != 3:
            raise CommandError('Usage is set_course_end {0}'.format(self.args))

        try:
            end_date = pytz.timezone('Europe/Moscow').localize(
                parse_date(args[1], dayfirst=False,
                           yearfirst=True)).astimezone(pytz.utc)
        except:
            raise CommandError('Could not parse date "{0}"'.format(args[1]))
        try:
            user = User.objects.get(email=args[2])
        except:
            raise CommandError('Could not find user with email "{0}"'.format(
                args[2]))

        locator = CourseLocator.from_string(args[0])

        coursedata = CourseDetails.fetch(locator)
        old_end_date = coursedata.end_date
        coursedata.end_date = end_date
        print "Changing course {0} end date from {1} to {2}".format(
            locator, old_end_date, end_date)
        coursedata.update_from_json(locator, coursedata.__dict__, user)
Example #12
0
def settings_handler(request, tag=None, package_id=None, branch=None, version_guid=None, block=None):
    """
    Course settings for dates and about pages
    GET
        html: get the page
        json: get the CourseDetails model
    PUT
        json: update the Course and About xblocks through the CourseDetails model
    """
    locator, course_module = _get_locator_and_course(
        package_id, branch, version_guid, block, request.user
    )
    if 'text/html' in request.META.get('HTTP_ACCEPT', '') and request.method == 'GET':
        upload_asset_url = locator.url_reverse('assets/')

        # see if the ORG of this course can be attributed to a 'Microsite'. In that case, the
        # course about page should be editable in Studio
        about_page_editable = not MicrositeConfiguration.get_microsite_configuration_value_for_org(
            course_module.location.org,
            'ENABLE_MKTG_SITE',
            settings.FEATURES.get('ENABLE_MKTG_SITE', False)
        )

        short_description_editable = settings.FEATURES.get('EDITABLE_SHORT_DESCRIPTION', True)

        return render_to_response('settings.html', {
            'context_course': course_module,
            'course_locator': locator,
            'lms_link_for_about_page': utils.get_lms_link_for_about_page(course_module.location),
            'course_image_url': utils.course_image_url(course_module),
            'details_url': locator.url_reverse('/settings/details/'),
            'about_page_editable': about_page_editable,
            'short_description_editable': short_description_editable,
            'upload_asset_url': upload_asset_url
        })
    elif 'application/json' in request.META.get('HTTP_ACCEPT', ''):
        if request.method == 'GET':
            return JsonResponse(
                CourseDetails.fetch(locator),
                # encoder serializes dates, old locations, and instances
                encoder=CourseSettingsEncoder
            )
        else:  # post or put, doesn't matter.
            return JsonResponse(
                CourseDetails.update_from_json(locator, request.json, request.user),
                encoder=CourseSettingsEncoder
            )
Example #13
0
def settings_handler(request, course_key_string):
    """
    Course settings for dates and about pages
    GET
        html: get the page
        json: get the CourseDetails model
    PUT
        json: update the Course and About xblocks through the CourseDetails model
    """
    course_key = CourseKey.from_string(course_key_string)
    course_module = _get_course_module(course_key, request.user)
    if "text/html" in request.META.get("HTTP_ACCEPT", "") and request.method == "GET":
        upload_asset_url = reverse_course_url("assets_handler", course_key)

        # see if the ORG of this course can be attributed to a 'Microsite'. In that case, the
        # course about page should be editable in Studio
        about_page_editable = not microsite.get_value_for_org(
            course_module.location.org, "ENABLE_MKTG_SITE", settings.FEATURES.get("ENABLE_MKTG_SITE", False)
        )

        short_description_editable = settings.FEATURES.get("EDITABLE_SHORT_DESCRIPTION", True)

        return render_to_response(
            "settings.html",
            {
                "context_course": course_module,
                "course_locator": course_key,
                "lms_link_for_about_page": utils.get_lms_link_for_about_page(course_key),
                "course_image_url": utils.course_image_url(course_module),
                "details_url": reverse_course_url("settings_handler", course_key),
                "about_page_editable": about_page_editable,
                "short_description_editable": short_description_editable,
                "upload_asset_url": upload_asset_url,
            },
        )
    elif "application/json" in request.META.get("HTTP_ACCEPT", ""):
        if request.method == "GET":
            return JsonResponse(
                CourseDetails.fetch(course_key),
                # encoder serializes dates, old locations, and instances
                encoder=CourseSettingsEncoder,
            )
        else:  # post or put, doesn't matter.
            return JsonResponse(
                CourseDetails.update_from_json(course_key, request.json, request.user), encoder=CourseSettingsEncoder
            )
 def test_update_and_fetch(self):
     jsondetails = CourseDetails.fetch(self.course.location)
     jsondetails.syllabus = "<a href='foo'>bar</a>"
     # encode - decode to convert date fields and other data which changes form
     self.assertEqual(
         CourseDetails.update_from_json(jsondetails.__dict__).syllabus,
         jsondetails.syllabus, "After set syllabus"
     )
     jsondetails.overview = "Overview"
     self.assertEqual(
         CourseDetails.update_from_json(jsondetails.__dict__).overview,
         jsondetails.overview, "After set overview"
     )
     jsondetails.intro_video = "intro_video"
     self.assertEqual(
         CourseDetails.update_from_json(jsondetails.__dict__).intro_video,
         jsondetails.intro_video, "After set intro_video"
     )
     jsondetails.effort = "effort"
     self.assertEqual(
         CourseDetails.update_from_json(jsondetails.__dict__).effort,
         jsondetails.effort, "After set effort"
     )
     jsondetails.start_date = datetime.datetime(2010, 10, 1, 0, tzinfo=UTC())
     self.assertEqual(
         CourseDetails.update_from_json(jsondetails.__dict__).start_date,
         jsondetails.start_date
     )
     jsondetails.course_image_name = "an_image.jpg"
     self.assertEqual(
         CourseDetails.update_from_json(jsondetails.__dict__).course_image_name,
         jsondetails.course_image_name
     )
 def test_virgin_fetch(self):
     details = CourseDetails.fetch(self.course.location)
     self.assertEqual(details.course_location, self.course.location, "Location not copied into")
     self.assertIsNotNone(details.start_date.tzinfo)
     self.assertIsNone(details.end_date, "end date somehow initialized " + str(details.end_date))
     self.assertIsNone(details.enrollment_start, "enrollment_start date somehow initialized " + str(details.enrollment_start))
     self.assertIsNone(details.enrollment_end, "enrollment_end date somehow initialized " + str(details.enrollment_end))
     self.assertIsNone(details.syllabus, "syllabus somehow initialized" + str(details.syllabus))
     self.assertIsNone(details.intro_video, "intro_video somehow initialized" + str(details.intro_video))
     self.assertIsNone(details.effort, "effort somehow initialized" + str(details.effort))
Example #16
0
def settings_handler(request, tag=None, course_id=None, branch=None, version_guid=None, block=None):
    """
    Course settings for dates and about pages
    GET
        html: get the page
        json: get the CourseDetails model
    PUT
        json: update the Course and About xblocks through the CourseDetails model
    """
    locator = BlockUsageLocator(course_id=course_id, branch=branch, version_guid=version_guid, usage_id=block)
    if not has_access(request.user, locator):
        raise PermissionDenied()

    if 'text/html' in request.META.get('HTTP_ACCEPT', '') and request.method == 'GET':
        course_old_location = loc_mapper().translate_locator_to_location(locator)
        course_module = modulestore().get_item(course_old_location)

        upload_asset_url = locator.url_reverse('assets/')

        return render_to_response('settings.html', {
            'context_course': course_module,
            'course_locator': locator,
            'lms_link_for_about_page': utils.get_lms_link_for_about_page(course_old_location),
            'course_image_url': utils.course_image_url(course_module),
            'details_url': locator.url_reverse('/settings/details/'),
            'about_page_editable': not settings.FEATURES.get(
                'ENABLE_MKTG_SITE', False
            ),
            'upload_asset_url': upload_asset_url
        })
    elif 'application/json' in request.META.get('HTTP_ACCEPT', ''):
        if request.method == 'GET':
            return JsonResponse(
                CourseDetails.fetch(locator),
                # encoder serializes dates, old locations, and instances
                encoder=CourseSettingsEncoder
            )
        else:  # post or put, doesn't matter.
            return JsonResponse(
                CourseDetails.update_from_json(locator, request.json),
                encoder=CourseSettingsEncoder
            )
Example #17
0
 def test_encoder(self):
     details = CourseDetails.fetch(self.course.id)
     jsondetails = json.dumps(details, cls=CourseSettingsEncoder)
     jsondetails = json.loads(jsondetails)
     self.assertEqual(jsondetails['course_image_name'], self.course.course_image)
     self.assertIsNone(jsondetails['end_date'], "end date somehow initialized ")
     self.assertIsNone(jsondetails['enrollment_start'], "enrollment_start date somehow initialized ")
     self.assertIsNone(jsondetails['enrollment_end'], "enrollment_end date somehow initialized ")
     self.assertIsNone(jsondetails['syllabus'], "syllabus somehow initialized")
     self.assertIsNone(jsondetails['intro_video'], "intro_video somehow initialized")
     self.assertIsNone(jsondetails['effort'], "effort somehow initialized")
 def test_encoder(self):
     details = CourseDetails.fetch(self.course.location)
     jsondetails = json.dumps(details, cls=CourseSettingsEncoder)
     jsondetails = json.loads(jsondetails)
     self.assertTupleEqual(Location(jsondetails['course_location']), self.course.location, "Location !=")
     self.assertIsNone(jsondetails['end_date'], "end date somehow initialized ")
     self.assertIsNone(jsondetails['enrollment_start'], "enrollment_start date somehow initialized ")
     self.assertIsNone(jsondetails['enrollment_end'], "enrollment_end date somehow initialized ")
     self.assertIsNone(jsondetails['syllabus'], "syllabus somehow initialized")
     self.assertIsNone(jsondetails['intro_video'], "intro_video somehow initialized")
     self.assertIsNone(jsondetails['effort'], "effort somehow initialized")
Example #19
0
 def test_update_and_fetch(self):
     # # NOTE: I couldn't figure out how to validly test time setting w/ all the conversions
     jsondetails = CourseDetails.fetch(self.course_location)
     jsondetails.syllabus = "<a href='foo'>bar</a>"
     # encode - decode to convert date fields and other data which changes form
     self.assertEqual(
         CourseDetails.update_from_json(jsondetails.__dict__).syllabus,
         jsondetails.syllabus, "After set syllabus")
     jsondetails.overview = "Overview"
     self.assertEqual(
         CourseDetails.update_from_json(jsondetails.__dict__).overview,
         jsondetails.overview, "After set overview")
     jsondetails.intro_video = "intro_video"
     self.assertEqual(
         CourseDetails.update_from_json(jsondetails.__dict__).intro_video,
         jsondetails.intro_video, "After set intro_video")
     jsondetails.effort = "effort"
     self.assertEqual(
         CourseDetails.update_from_json(jsondetails.__dict__).effort,
         jsondetails.effort, "After set effort")
 def test_encoder(self):
     details = CourseDetails.fetch(self.course.location)
     jsondetails = json.dumps(details, cls=CourseSettingsEncoder)
     jsondetails = json.loads(jsondetails)
     self.assertTupleEqual(Location(jsondetails["course_location"]), self.course.location, "Location !=")
     self.assertEqual(jsondetails["course_image_name"], self.course.course_image)
     self.assertIsNone(jsondetails["end_date"], "end date somehow initialized ")
     self.assertIsNone(jsondetails["enrollment_start"], "enrollment_start date somehow initialized ")
     self.assertIsNone(jsondetails["enrollment_end"], "enrollment_end date somehow initialized ")
     self.assertIsNone(jsondetails["syllabus"], "syllabus somehow initialized")
     self.assertIsNone(jsondetails["intro_video"], "intro_video somehow initialized")
     self.assertIsNone(jsondetails["effort"], "effort somehow initialized")
Example #21
0
 def test_encoder(self):
     details = CourseDetails.fetch(self.course_location)
     jsondetails = json.dumps(details, cls=CourseSettingsEncoder)
     jsondetails = json.loads(jsondetails)
     self.assertTupleEqual(Location(jsondetails['course_location']), self.course_location, "Location !=")
     # Note, start_date is being initialized someplace. I'm not sure why b/c the default will make no sense.
     self.assertIsNone(jsondetails['end_date'], "end date somehow initialized ")
     self.assertIsNone(jsondetails['enrollment_start'], "enrollment_start date somehow initialized ")
     self.assertIsNone(jsondetails['enrollment_end'], "enrollment_end date somehow initialized ")
     self.assertIsNone(jsondetails['syllabus'], "syllabus somehow initialized")
     self.assertEqual(jsondetails['overview'], "", "overview somehow initialized")
     self.assertIsNone(jsondetails['intro_video'], "intro_video somehow initialized")
     self.assertIsNone(jsondetails['effort'], "effort somehow initialized")
 def test_virgin_fetch(self):
     details = CourseDetails.fetch(self.course.id)
     self.assertEqual(details.org, self.course.location.org, "Org not copied into")
     self.assertEqual(details.course_id, self.course.location.course, "Course_id not copied into")
     self.assertEqual(details.run, self.course.location.name, "Course name not copied into")
     self.assertEqual(details.course_image_name, self.course.course_image)
     self.assertIsNotNone(details.start_date.tzinfo)
     self.assertIsNone(details.end_date, "end date somehow initialized " + str(details.end_date))
     self.assertIsNone(details.enrollment_start, "enrollment_start date somehow initialized " + str(details.enrollment_start))
     self.assertIsNone(details.enrollment_end, "enrollment_end date somehow initialized " + str(details.enrollment_end))
     self.assertIsNone(details.syllabus, "syllabus somehow initialized" + str(details.syllabus))
     self.assertIsNone(details.intro_video, "intro_video somehow initialized" + str(details.intro_video))
     self.assertIsNone(details.effort, "effort somehow initialized" + str(details.effort))
 def test_update_and_fetch(self):
     jsondetails = CourseDetails.fetch(self.course.id)
     jsondetails.syllabus = "<a href='foo'>bar</a>"
     # encode - decode to convert date fields and other data which changes form
     self.assertEqual(
         CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).syllabus,
         jsondetails.syllabus, "After set syllabus"
     )
     jsondetails.short_description = "Short Description"
     self.assertEqual(
         CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).short_description,
         jsondetails.short_description, "After set short_description"
     )
     jsondetails.about_sidebar_html = "About Sidebar HTML"
     self.assertEqual(
         CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).about_sidebar_html,
         jsondetails.about_sidebar_html, "After set about_sidebar_html"
     )
     jsondetails.overview = "Overview"
     self.assertEqual(
         CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).overview,
         jsondetails.overview, "After set overview"
     )
     jsondetails.intro_video = "intro_video"
     self.assertEqual(
         CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).intro_video,
         jsondetails.intro_video, "After set intro_video"
     )
     jsondetails.effort = "effort"
     self.assertEqual(
         CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).effort,
         jsondetails.effort, "After set effort"
     )
     jsondetails.start_date = datetime.datetime(2010, 10, 1, 0, tzinfo=UTC())
     self.assertEqual(
         CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).start_date,
         jsondetails.start_date
     )
     jsondetails.course_image_name = "an_image.jpg"
     self.assertEqual(
         CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).course_image_name,
         jsondetails.course_image_name
     )
    def test_update_and_fetch(self):
        details = CourseDetails.fetch(self.course_locator)

        # resp s/b json from here on
        url = self.course_locator.url_reverse('settings/details/')
        resp = self.client.get_json(url)
        self.compare_details_with_encoding(json.loads(resp.content), details.__dict__, "virgin get")

        utc = UTC()
        self.alter_field(url, details, 'start_date', datetime.datetime(2012, 11, 12, 1, 30, tzinfo=utc))
        self.alter_field(url, details, 'start_date', datetime.datetime(2012, 11, 1, 13, 30, tzinfo=utc))
        self.alter_field(url, details, 'end_date', datetime.datetime(2013, 2, 12, 1, 30, tzinfo=utc))
        self.alter_field(url, details, 'enrollment_start', datetime.datetime(2012, 10, 12, 1, 30, tzinfo=utc))

        self.alter_field(url, details, 'enrollment_end', datetime.datetime(2012, 11, 15, 1, 30, tzinfo=utc))
        self.alter_field(url, details, 'overview', "Overview")
        self.alter_field(url, details, 'intro_video', "intro_video")
        self.alter_field(url, details, 'effort', "effort")
        self.alter_field(url, details, 'course_image_name', "course_image_name")
Example #25
0
 def test_encoder(self):
     details = CourseDetails.fetch(self.course_location)
     jsondetails = json.dumps(details, cls=CourseSettingsEncoder)
     jsondetails = json.loads(jsondetails)
     self.assertTupleEqual(Location(jsondetails['course_location']),
                           self.course_location, "Location !=")
     # Note, start_date is being initialized someplace. I'm not sure why b/c the default will make no sense.
     self.assertIsNone(jsondetails['end_date'],
                       "end date somehow initialized ")
     self.assertIsNone(jsondetails['enrollment_start'],
                       "enrollment_start date somehow initialized ")
     self.assertIsNone(jsondetails['enrollment_end'],
                       "enrollment_end date somehow initialized ")
     self.assertIsNone(jsondetails['syllabus'],
                       "syllabus somehow initialized")
     self.assertEqual(jsondetails['overview'], "",
                      "overview somehow initialized")
     self.assertIsNone(jsondetails['intro_video'],
                       "intro_video somehow initialized")
     self.assertIsNone(jsondetails['effort'], "effort somehow initialized")
    def test_update_and_fetch(self):
        details = CourseDetails.fetch(self.course.id)

        # resp s/b json from here on
        url = get_url(self.course.id)
        resp = self.client.get_json(url)
        self.compare_details_with_encoding(json.loads(resp.content), details.__dict__, "virgin get")

        utc = UTC()
        self.alter_field(url, details, "start_date", datetime.datetime(2012, 11, 12, 1, 30, tzinfo=utc))
        self.alter_field(url, details, "start_date", datetime.datetime(2012, 11, 1, 13, 30, tzinfo=utc))
        self.alter_field(url, details, "end_date", datetime.datetime(2013, 2, 12, 1, 30, tzinfo=utc))
        self.alter_field(url, details, "enrollment_start", datetime.datetime(2012, 10, 12, 1, 30, tzinfo=utc))

        self.alter_field(url, details, "enrollment_end", datetime.datetime(2012, 11, 15, 1, 30, tzinfo=utc))
        self.alter_field(url, details, "short_description", "Short Description")
        self.alter_field(url, details, "overview", "Overview")
        self.alter_field(url, details, "intro_video", "intro_video")
        self.alter_field(url, details, "effort", "effort")
        self.alter_field(url, details, "course_image_name", "course_image_name")
Example #27
0
    def handle(self, *args, **options):
        '''Handle management command request'''

        if len(args) != 3:
            raise CommandError('Usage is set_course_end {0}'.format(self.args))

        try:
            end_date = pytz.timezone('Europe/Moscow').localize(parse_date(args[1],dayfirst=False,yearfirst=True)).astimezone(pytz.utc)
        except:
            raise CommandError('Could not parse date "{0}"'.format(args[1]))
        try:
            user = User.objects.get(email=args[2])
        except:
            raise CommandError('Could not find user with email "{0}"'.format(args[2]))

        locator = CourseLocator.from_string(args[0])

        coursedata = CourseDetails.fetch(locator)
        old_end_date = coursedata.end_date
        coursedata.end_date = end_date
        print "Changing course {0} end date from {1} to {2}".format(locator,old_end_date,end_date)
        coursedata.update_from_json(locator,coursedata.__dict__,user)