Exemplo n.º 1
0
    def studio_submit(self, submissions, suffix=''):  # pylint: disable=unused-argument
        """
        Change the settings for this XBlock given by the Studio user
        """
        if not isinstance(submissions, dict):
            LOG.error("submissions object from Studio is not a dict - %r",
                      submissions)
            return {'result': 'error'}

        self.document_url = submissions['document_url']

        self.output_code = Filter.get_embed_code(url=self.document_url)
        self.message = "Note: Some services may require you to be signed into them to access documents stored there."
        self.message_display_state = "block"

        return {'result': 'success'}
Exemplo n.º 2
0
    def studio_submit(self, submissions, suffix=''):  # pylint: disable=unused-argument
        """
        Change the settings for this XBlock given by the Studio user
        """
        if not isinstance(submissions, dict):
            LOG.error("submissions object from Studio is not a dict - %r", submissions)
            return {
                'result': 'error'
            }

        self.document_url = submissions['document_url']

        self.output_code = Filter.get_embed_code(url=self.document_url)
        self.message = "Note: Some services may require you to be signed into them to access documents stored there."
        self.message_display_state = "block"

        return {'result': 'success'}
Exemplo n.º 3
0
    def studio_submit(self, submissions, suffix=''):  # pylint: disable=unused-argument
        """
        Change the settings for this XBlock given by the Studio user
        """
        if not isinstance(submissions, dict):
            LOG.error("submissions object from Studio is not a dict - %r",
                      submissions)
            return {'result': 'error'}

        self.document_url = submissions['document_url']
        self.reference_name = submissions['reference_name']
        self.output_model = submissions['model']

        # output model = 1 means embed the document
        if self.output_model == "1":
            self.output_code = Filter.get_embed_code(url=self.document_url)
            self.message = "Note: Some services may require you to be signed into them to access documents stored there."
            self.message_display_state = "block"

            self.model1 = "SELECTED=selected"
            self.model2 = ""
# self.model3 = ""

# output model = 2 means add a reference to the document
        if self.output_model == "2":
            self.output_code = "<a href=" + self.document_url + " target='_blank'>" + self.reference_name + "</a>"
            self.message = ""
            self.message_display_state = "none"

            self.model1 = ""
            self.model2 = "SELECTED=selected"
# self.model3 = ""

# output model = 3 means upload the document and add a reference to it
# if self.output_model == "3":
# download_url = Filter.get_download_url(self.document_url)
# reference_name = self.reference_name.encode('utf8')
# course_key = CourseKey.from_string(str(self.course_id))

# try:
# download_response = urllib2.urlopen(download_url)
# file = download_response.read()
# except:
# self.output_code = "Unable to upload the document: " + self.document_url
# return {'result': 'error'}

# ext = mimetypes.guess_extension(download_response.headers.type, strict=False)
# file_name = reference_name.replace(" ", "_") + ext
# content_loc = StaticContent.compute_location(course_key, file_name)
# sc_partial = partial(StaticContent, content_loc, file_name, download_response.headers.type)
# content = sc_partial(file)

# tempfile_path = None

# # first let's see if a thumbnail can be created
# (thumbnail_content, thumbnail_location) = contentstore().generate_thumbnail(
# content,
# tempfile_path=tempfile_path,
# )

# del_cached_content(thumbnail_location)

# # now store thumbnail location only if we could create it
# if thumbnail_content is not None:
# content.thumbnail_location = thumbnail_location

# # then commit the content
# contentstore().save(content)
# del_cached_content(content.location)

# # readback the saved content - we need the database timestamp
# readback = contentstore().find(content.location)
# locked = getattr(content, 'locked', False)

# asset_url = StaticContent.serialize_asset_key_with_slash(content.location)
# external_url = settings.LMS_BASE + asset_url

# self.output_code = "<a href="+asset_url+" target='_blank'>"+reference_name+"</a>"
# self.message = ""
# self.message_display_state = "none"

# self.model1 = ""
# self.model2 = ""
# self.model3 = "SELECTED=selected"

        return {'result': 'success'}
Exemplo n.º 4
0
    def studio_submit(self, submissions, suffix=''):  # pylint: disable=unused-argument
        """
        Change the settings for this XBlock given by the Studio user
        """
        if not isinstance(submissions, dict):
            LOG.error("submissions object from Studio is not a dict - %r", submissions)
            return {
                'result': 'error'
            }

        self.document_url = submissions['document_url']
        self.reference_name = submissions['reference_name']
        self.output_model = submissions['model']

        # output model = 1 means embed the document
        if self.output_model == "1":
            self.output_code = Filter.get_embed_code(url=self.document_url)
            self.message = "Note: Some services may require you to be signed into them to access documents stored there."
            self.message_display_state = "block"

	    self.model1 = "SELECTED=selected"
	    self.model2 = ""
	    # self.model3 = ""

        # output model = 2 means add a reference to the document
        if self.output_model == "2":
            self.output_code = "<a href="+self.document_url+" target='_blank'>"+self.reference_name+"</a>"
            self.message = ""
            self.message_display_state = "none"

	    self.model1 = ""
	    self.model2 = "SELECTED=selected"
	    # self.model3 = ""

        # output model = 3 means upload the document and add a reference to it
        # if self.output_model == "3":
            # download_url = Filter.get_download_url(self.document_url)
            # reference_name = self.reference_name.encode('utf8')
            # course_key = CourseKey.from_string(str(self.course_id))

            # try:
                # download_response = urllib2.urlopen(download_url)
                # file = download_response.read()
            # except:
                # self.output_code = "Unable to upload the document: " + self.document_url
                # return {'result': 'error'}

            # ext = mimetypes.guess_extension(download_response.headers.type, strict=False)
            # file_name = reference_name.replace(" ", "_") + ext
            # content_loc = StaticContent.compute_location(course_key, file_name)
            # sc_partial = partial(StaticContent, content_loc, file_name, download_response.headers.type)
            # content = sc_partial(file)

            # tempfile_path = None

            # # first let's see if a thumbnail can be created
            # (thumbnail_content, thumbnail_location) = contentstore().generate_thumbnail(
                # content,
                # tempfile_path=tempfile_path,
            # )

            # del_cached_content(thumbnail_location)
            
            # # now store thumbnail location only if we could create it
            # if thumbnail_content is not None:
                # content.thumbnail_location = thumbnail_location

            # # then commit the content
            # contentstore().save(content)
            # del_cached_content(content.location)

            # # readback the saved content - we need the database timestamp
            # readback = contentstore().find(content.location)
            # locked = getattr(content, 'locked', False)

            # asset_url = StaticContent.serialize_asset_key_with_slash(content.location)
            # external_url = settings.LMS_BASE + asset_url

            # self.output_code = "<a href="+asset_url+" target='_blank'>"+reference_name+"</a>"
            # self.message = ""
            # self.message_display_state = "none"

	    # self.model1 = ""
	    # self.model2 = ""
	    # self.model3 = "SELECTED=selected"

        return {'result': 'success'}