def get_previous_credits(self): # Get all the credits that were awarded to the user in previous academic years. credits = self.user.credit_recepients.filter(time__lt = get_current_session_start_datetime()) # Find the sum of the credits obtained above. credits = credits.aggregate(number_of_credits = models.Sum('number_of_credits')) if credits['number_of_credits'] != None: return credits['number_of_credits'] else: return 0
def credits(self, credit_type): try: # Get all the credits awarded to the user under the credit type. credits = credit_type.credits.filter(awarded_to = self.user) # Filter all the credits that were obtained in the current academic year. credits = credits.filter(time__gte = get_current_session_start_datetime()) # Find the sum of the credits obtained after the two filters. credits = credits.aggregate(number_of_credits = models.Sum('number_of_credits')) if credits['number_of_credits'] != None: return credits['number_of_credits'] else: return 0 except AttributeError: return None