예제 #1
0
def reputation_pipeline( **kwargs):
    if kwargs['is_new']:
        github_token = kwargs['social_user'].extra_data['access_token']
        reputation_points = generate_reputation_points(github_token)

        r = Reputation(reputation = reputation_points, user =  kwargs['user'])
        r.save()
예제 #2
0
def reputation_pipeline( **kwargs):
    if kwargs['is_new']:
        github_token = kwargs['social_user'].extra_data['access_token']
        reputation_points = generate_reputation_points(github_token)

        r = Reputation(reputation = reputation_points, user =  kwargs['user'])
        r.save()
예제 #3
0
    def evaluate_reputation(self, criterion=None):
        """
        Calculates the reputation for the student on all criteria or on a
        specific criterion, creating the Reputation for them if it doesn't
        already exist.

        Parameters
        ----------
        criterion : Optional[str] (default : none)
            Criterion on which to evaluate

        Returns
        -------
        float
            Evaluated reputation

        Raises
        ------
        ValueError
            If the given criterion isn't part of the list for this reputation
            type
        """
        if self.reputation is None:
            self.reputation = Reputation.create("student")
            self.save()
        return self.reputation.evaluate(criterion)[0]
예제 #4
0
def get_teacher_information(req):
    args = get_query_string_params(req, args=["id"])
    if isinstance(args, HttpResponse):
        return args
    (id_, ), _ = args

    try:
        teacher = Teacher.objects.get(pk=id_)
    except Teacher.DoesNotExist:
        return response_400(
            req,
            msg=translate("There is no teacher with that id"),
            logger_msg=("Teacher with pk {} couldn't be found.".format(id_)),
            log=logger.warning,
        )

    if teacher.reputation is None:
        teacher.reputation = Reputation.create(teacher)

    _, reputations = teacher.reputation.evaluate()

    data = {
        "username":
        teacher.user.username,
        "last_login":
        teacher.user.last_login.strftime("%Y-%m-%d %H:%M:%S")
        if teacher.user.last_login is not None else None,
        "reputations": [{
            "name": reputation["name"],
            "reputation": reputation["reputation"],
        } for reputation in reputations],
    }
    return JsonResponse(data)
예제 #5
0
def test_create__object_passed(question, assignment, teacher):
    for cls in (question, assignment, teacher):
        reputation = Reputation.create(cls)
        assert isinstance(reputation, Reputation)
        assert (
            reputation.reputation_type.type == cls.__class__.__name__.lower()
        )
예제 #6
0
    def convincing_rationale_reputation(self):
        if self.reputation is None:
            self.reputation = Reputation.create("student")
            self.save()

        return self.reputation.evaluate("convincing_rationales")[0]
예제 #7
0
def test_create__wrong_type():
    with pytest.raises(ReputationType.DoesNotExist):
        reputation = Reputation.create("StudentAssignment")
예제 #8
0
def test_create__str_passed():
    for cls in ("Question", "Assignment", "Teacher"):
        reputation = Reputation.create(cls)
        assert isinstance(reputation, Reputation)
        assert reputation.reputation_type.type == cls.lower()