コード例 #1
0
    def handle_requirements_upload(self, request, suffix=u''):
        """Handles uploading of requirements.txt"""

        _ = self.runtime.service(self, "i18n").ugettext

        log.info("Handling requirements.txt upload for course: {}, xblock: {}"\
            .format(str(self.course_id), str(self.location)))
        try:
            f = request.params['file']
            nbu.update_requirements(str(self.course_id), f)
            req = nbu.get_requirements(str(self.course_id))
            response = {'success': True, 'requirements': "<br>".join(req)}

        except Exception as e:
            raise_condition = "No File Attached"
            response = {
                'success': False,
                'error': _(raise_condition)
            } if str(e) == raise_condition else {
                'success': False,
                'error': str(e)
            }
        return Response(body=json.dumps(response),
                        content_type="application/json",
                        status=200)
    def handle_requirements_upload(self, request, suffix=u''):
        """Handles uploading of requirements.txt"""
        log.info("Handling requirements.txt upload for course: {}, xblock: {}"\
            .format(str(self.course_id), str(self.location)))
        try:
            f = request.params['file']
            nbu.update_requirements(str(self.course_id), f)
            req = nbu.get_requirements(str(self.course_id))
            response = {'success': True, 'requirements': "<br>".join(req)}

        except Exception as e:
            response = {'success': False, 'error': str(e)}

        return Response(body=json.dumps(response),
                        content_type="application/json",
                        status=200)
コード例 #3
0
    def author_view(self, context=None):
        """View shown in the CMS XBlock preview"""
        # Setup last uploaded datetime
        upload_dt = ''
        if self.nb_upload_datetime:
            dt = dateparse.parse_datetime(self.nb_upload_datetime)
            upload_dt = dt.strftime("%Y-%m-%d %H:%M:%S") + " UTC"
        req = nbu.get_requirements(str(self.course_id))

        self.init_emulation()
        fragment = Fragment()

        # HTML Template and Context
        ctx_data = {
            'title': self.display_name,
            'instructions': self.instructions,
            'requirements': req,
            'max_attempts': self.max_attempts,
            'student_attempts': self.student_attempts,
            'student_score': self.student_score,
            'max_score': "{:0.2f}".format(self.raw_possible),
            'nb_name': self.nb_name,
            'inst_disabled': '',
            'student_disabled': 'disabled',
            'nb_upload_date': upload_dt,
            'student_download_url': self._get_nb_url('student'),
            'instructor_download_url': self._get_nb_url('instructor'),
            'xblock_id': self._get_xblock_loc(),
        }

        fragment.add_content(
            loader.render_django_template(
                'templates/xblock_jupyter_graded/author_view.html',
                context=ctx_data,
                i18n_service=self.runtime.service(self, "i18n"),
            ))
        fragment.add_css(loader.load_unicode('public/css/styles.css'))
        fragment.add_javascript(loader.load_unicode('public/js/author.js'))
        fragment.add_javascript(self.get_translation_content())
        fragment.initialize_js('JupyterGradedXBlock',
                               {'xblock_id': self._get_xblock_loc()})

        return fragment