Esempio n. 1
0
 def grade(self,
           request,
           submission,
           no_penalties=False,
           url_name="exercise"):
     """
     Loads the exercise feedback page.
     """
     language = get_language()
     submission_url = update_url_params(
         api_reverse("submission-grader",
                     kwargs={'submission_id': submission.id}),
         get_graderauth_submission_params(submission),
     )
     url = self._build_service_url(language, request,
                                   submission.submitters.all(),
                                   submission.ordinal_number(), url_name,
                                   submission_url)
     try:
         return load_feedback_page(request,
                                   url,
                                   self,
                                   submission,
                                   no_penalties=no_penalties)
     except OSError as error:
         page = ExercisePage(self)
         msg = "Unable to grade the submission. %s: %s" % (
             error.__class__.__name__, error)
         page.errors.append(msg)
         return page
Esempio n. 2
0
    def _build_src(self):
        params = {"view_name": self.view_name}

        for k, v in self.context.items():
            params[k + "_id"] = v.id

        return update_url_params(self.plugin.service_url, params)
Esempio n. 3
0
 def sign_get_query(self, url=None):
     client = Client(self.service.consumer_key,
         client_secret=self.service.consumer_secret,
         signature_method=SIGNATURE_HMAC,
         signature_type=SIGNATURE_TYPE_QUERY)
     uri = update_url_params(url or self.service.service.url, self.parameters)
     query, headers, body = client.sign(uri, http_method="GET")
     return query
Esempio n. 4
0
File: lti.py Progetto: Vilz92/a-plus
 def sign_get_query(self, url=None):
     client = Client(self.service.consumer_key,
                     client_secret=self.service.consumer_secret,
                     signature_method=SIGNATURE_HMAC,
                     signature_type=SIGNATURE_TYPE_QUERY)
     uri = update_url_params(url or self.service.service.url,
                             self.parameters)
     query, headers, body = client.sign(uri, http_method="GET")
     return query
Esempio n. 5
0
def localized_url(path, language=None):
    base_url = settings.BASE_URL
    if base_url.endswith('/'):
        base_url = base_url[:-1]
    path = remove_query_param_from_url(path, 'hl')
    if not language:
        language = settings.LANGUAGE_CODE.split('-')[0]
    path = update_url_params(path, {'hl': language})
    return base_url + path
Esempio n. 6
0
 def _build_service_url(self, request, url_name, submission_url):
     """
     Generates complete URL with added parameters to the exercise service.
     """
     params = {
         "max_points": self.max_points,
         "submission_url": request.build_absolute_uri(submission_url),
         "post_url": request.build_absolute_uri(str(self.get_url(url_name))),
     }
     return update_url_params(self.service_url, params)
Esempio n. 7
0
 def _build_service_url(self, request, url_name, submission_url):
     """
     Generates complete URL with added parameters to the exercise service.
     """
     params = {
         "max_points": self.max_points,
         "submission_url": request.build_absolute_uri(submission_url),
         "post_url":
         request.build_absolute_uri(str(self.get_url(url_name))),
     }
     return update_url_params(self.service_url, params)
Esempio n. 8
0
 def sign_get_query(self, url=None):
     client = Client(self.service.consumer_key,
         client_secret=self.service.consumer_secret,
         signature_method=SIGNATURE_HMAC,
         signature_type=SIGNATURE_TYPE_QUERY)
     uri = update_url_params(self._get_url(url), self.parameters)
     try:
         query, headers, body = client.sign(uri, http_method="GET")
     except ValueError as e:
         raise ValueError("Invalid url %r for %r: %s" % (uri, self.service, e))
     return query
Esempio n. 9
0
 def sign_get_query(self, url=None):
     client = Client(self.service.consumer_key,
         client_secret=self.service.consumer_secret,
         signature_method=SIGNATURE_HMAC,
         signature_type=SIGNATURE_TYPE_QUERY)
     uri = update_url_params(self._get_url(url), self.parameters)
     try:
         query, headers, body = client.sign(uri, http_method="GET")
     except ValueError as e:
         raise ValueError("Invalid url %r for %r: %s" % (uri, self.service, e))
     return query
Esempio n. 10
0
 def handle_exception(self, exc):
     if isinstance(exc, TranslationNotFound):
         instance_languages = self.instance.language.strip("|").split("|")
         url = remove_query_param_from_url(self.request.get_full_path(),
                                           'hl')
         for i, lang in enumerate(instance_languages):
             instance_languages[i] = {
                 "name": get_language_info(lang)['name'],
                 "url": update_url_params(url, {'hl': lang})
             }
         return render_to_response('404.html', {
             'error_msg': str(exc),
             'languages': instance_languages
         },
                                   status=404)
     return super().handle_exception(exc)
Esempio n. 11
0
 def grade(self, request, submission, no_penalties=False, url_name="exercise"):
     """
     Loads the exercise feedback page.
     """
     language = get_language()
     submission_url = update_url_params(
         api_reverse("submission-grader", kwargs={
             'submission_id': submission.id
         }),
         get_graderauth_submission_params(submission),
     )
     url = self._build_service_url(
         language, request, submission.submitters.all(),
         submission.ordinal_number(), url_name, submission_url
     )
     return load_feedback_page(
         request, url, self, submission, no_penalties=no_penalties
     )
Esempio n. 12
0
 def _build_service_url(self, language, request, students, ordinal_number,
                        url_name, submission_url):
     """
     Generates complete URL with added parameters to the exercise service.
     """
     uid_str = '-'.join(sorted(
         str(profile.user.id) for profile in students)) if students else ''
     return update_url_params(
         self.service_url, {
             "max_points": self.max_points,
             "max_submissions": self.max_submissions,
             "submission_url": request.build_absolute_uri(submission_url),
             "post_url": request.build_absolute_uri(
                 str(self.get_url(url_name))),
             "uid": uid_str,
             "ordinal_number": ordinal_number,
             "lang": language,
         })
Esempio n. 13
0
 def _build_service_url(self, language, request, students, ordinal_number, url_name, submission_url):
     """
     Generates complete URL with added parameters to the exercise service.
     """
     uid_str = '-'.join(sorted(str(profile.user.id) for profile in students)) if students else ''
     auri = (
         settings.OVERRIDE_SUBMISSION_HOST + submission_url
         if settings.OVERRIDE_SUBMISSION_HOST
         else request.build_absolute_uri(submission_url)
     )
     return update_url_params(pick_localized(self.service_url, language), {
         "max_points": self.max_points,
         "max_submissions": self.max_submissions,
         "submission_url": auri,
         "post_url": request.build_absolute_uri(str(self.get_url(url_name))),
         "uid": uid_str,
         "ordinal_number": ordinal_number,
         "lang": language,
     })
Esempio n. 14
0
 def get_load_url(self, language, request, students, url_name="exercise"):
     if self.id:
         if request.user.is_authenticated:
             user = request.user
             submission_count = self.get_submissions_for_student(
                 user.userprofile, exclude_errors=True).count()
         else:
             user = None
             submission_count = 0
         # Make grader async URL for the currently authenticated user.
         # The async handler will handle group selection at submission time.
         submission_url = update_url_params(
             api_reverse("exercise-grader", kwargs={'exercise_id':
                                                    self.id}),
             get_graderauth_exercise_params(self, user),
         )
         return self._build_service_url(language, request, students,
                                        submission_count + 1, url_name,
                                        submission_url)
     return super().get_load_url(language, request, students, url_name)
Esempio n. 15
0
 def get_load_url(self, language, request, students, url_name="exercise"):
     if self.id:
         if request.user.is_authenticated():
             user = request.user
             submission_count = self.get_submissions_for_student(user.userprofile).count()
         else:
             user = None
             submission_count = 0
         # Make grader async URL for the currently authenticated user.
         # The async handler will handle group selection at submission time.
         submission_url = update_url_params(
             api_reverse("exercise-grader", kwargs={
                 'exercise_id': self.id
             }),
             get_graderauth_exercise_params(self, user),
         )
         return self._build_service_url(
             language, request, students,
             submission_count + 1, url_name, submission_url
         )
     return super().get_load_url(language, request, students, url_name)
Esempio n. 16
0
 def _build_src(self):
     params = {
         "course_instance_id": self.course_instance.id,
         "user_profile_id": self.user_profile.id
     }
     return update_url_params(self.tab.content_url, params)
Esempio n. 17
0
 def get_load_url(self, language, request, students, url_name="exercise"):
     return update_url_params(pick_localized(self.service_url, language), {
         'lang': language,
     })
Esempio n. 18
0
 def _build_src(self):
     params = {
         "course_instance_id": self.course_instance.id,
         "user_profile_id": self.user_profile.id
     }
     return update_url_params(self.tab.content_url, params)
Esempio n. 19
0
 def _build_src(self):
     params = {"view_name": self.view_name}
     for k, v in list(self.context.items()):
         if v is not None:
             params[k + "_id"] = v.id
     return update_url_params(self.plugin.service_url, params)
Esempio n. 20
0
 def get_load_url(self, language, request, students, url_name="exercise"):
     return update_url_params(self.get_service_url(language), {
         'lang': language,
     })