Exemplo n.º 1
0
    def remove_points(self,
                      points,
                      submission_date,
                      message,
                      related_object=None):
        """
    Removes points from the user. Note that this method does not save the profile.  
    If the submission date is the same as the last_awarded_submission field, we rollback 
    to a previously completed task.
    """
        # Log the transaction.
        transaction = PointsTransaction(
            user=self.user,
            points=points * -1,
            submission_date=submission_date,
            message=message,
        )
        if related_object:
            transaction.related_object = related_object

        transaction.save()

        # Invalidate info bar cache.
        invalidate_info_bar_cache(self.user)

        if self._is_canopy_activity(related_object):
            self.canopy_karma -= points
        else:
            self.points -= points

            current_round = self._get_round(submission_date)
            # If we have a round, then update the scoreboard entry.  Otherwise, this just counts towards overall.
            if current_round:
                try:
                    entry = ScoreboardEntry.objects.get(
                        profile=self, round_name=current_round)
                    entry.points -= points
                    if entry.last_awarded_submission == submission_date:
                        # Need to find the previous update.
                        entry.last_awarded_submission = self._last_submitted_before(
                            submission_date)

                    entry.save()
                except ObjectDoesNotExist:
                    # This should not happen once the competition is rolling.
                    raise InvalidRoundException(
                        "Attempting to remove points from a round when the user has no points in that round."
                    )

            if self.last_awarded_submission == submission_date:
                self.last_awarded_submission = self._last_submitted_before(
                    submission_date)
Exemplo n.º 2
0
  def remove_points(self, points, submission_date, message, related_object=None):
    """
    Removes points from the user. Note that this method does not save the profile.  
    If the submission date is the same as the last_awarded_submission field, we rollback 
    to a previously completed task.
    """
    # Log the transaction.
    transaction = PointsTransaction(
        user=self.user,
        points=points * -1,
        submission_date=submission_date,
        message=message,
    )
    if related_object:
      transaction.related_object = related_object
    
    transaction.save()
    
    # Invalidate info bar cache.
    invalidate_info_bar_cache(self.user)

    if self._is_canopy_activity(related_object):
        self.canopy_karma -= points
    else:
        self.points -= points
    
        current_round = self._get_round(submission_date)
        # If we have a round, then update the scoreboard entry.  Otherwise, this just counts towards overall.
        if current_round:
          try:
            entry = ScoreboardEntry.objects.get(profile=self, round_name=current_round)
            entry.points -= points
            if entry.last_awarded_submission == submission_date:
              # Need to find the previous update.
              entry.last_awarded_submission = self._last_submitted_before(submission_date)

            entry.save()
          except ObjectDoesNotExist:
            # This should not happen once the competition is rolling.
            raise InvalidRoundException("Attempting to remove points from a round when the user has no points in that round.")

        if self.last_awarded_submission == submission_date:
          self.last_awarded_submission = self._last_submitted_before(submission_date)
Exemplo n.º 3
0
    def add_points(self,
                   points,
                   submission_date,
                   message,
                   related_object=None):
        """
    Adds points based on the point value of the submitted object.
    Note that this method does not save the profile.
    """
        # Create a transaction first.
        transaction = PointsTransaction(
            user=self.user,
            points=points,
            submission_date=submission_date,
            message=message,
        )
        if related_object:
            transaction.related_object = related_object

        transaction.save()

        # Invalidate info bar cache.
        invalidate_info_bar_cache(self.user)

        # canopy activity deal with karma
        if self._is_canopy_activity(related_object):
            self.canopy_karma += points
        else:
            self.points += points

            if not self.last_awarded_submission or submission_date > self.last_awarded_submission:
                self.last_awarded_submission = submission_date

            current_round = self._get_round(submission_date)

            # If we have a round, then update the scoreboard entry.  Otherwise, this just counts towards overall.
            if current_round:
                entry, created = ScoreboardEntry.objects.get_or_create(
                    profile=self, round_name=current_round)
                entry.points += points
                if not entry.last_awarded_submission or submission_date > entry.last_awarded_submission:
                    entry.last_awarded_submission = submission_date
                entry.save()
Exemplo n.º 4
0
  def add_points(self, points, submission_date, message, related_object=None):
    """
    Adds points based on the point value of the submitted object.
    Note that this method does not save the profile.
    """
    # Create a transaction first.
    transaction = PointsTransaction(
        user=self.user,
        points=points,
        submission_date=submission_date,
        message=message,
    ) 
    if related_object:
      transaction.related_object = related_object
      
    transaction.save()
    
    # Invalidate info bar cache.
    invalidate_info_bar_cache(self.user)

    # canopy activity deal with karma
    if self._is_canopy_activity(related_object):
        self.canopy_karma += points
    else:
        self.points += points

        if not self.last_awarded_submission or submission_date > self.last_awarded_submission:
          self.last_awarded_submission = submission_date

        current_round = self._get_round(submission_date)

        # If we have a round, then update the scoreboard entry.  Otherwise, this just counts towards overall.
        if current_round:
          entry, created = ScoreboardEntry.objects.get_or_create(profile=self, round_name=current_round)
          entry.points += points
          if not entry.last_awarded_submission or submission_date > entry.last_awarded_submission:
            entry.last_awarded_submission = submission_date
          entry.save()