def award_participation():
    """award the participation rate for all team."""
    p_setting, _ = ParticipationSetting.objects.get_or_create(pk=1)

    for team in team_mgr.team_active_participation():
        team_participation, _ = TeamParticipation.objects.get_or_create(team=team)

        # check if the participation rate change
        if team_participation.participation != team.active_participation:
            # save the new participation rate
            team_participation.participation = team.active_participation
            team_participation.save()
            cache_mgr.delete("team_participation")

            if team.active_participation == 100:
                team_mgr.award_member_points(team,
                                             p_setting.points_100_percent,
                                             "Team 100% participation")
            elif team.active_participation >= 75:
                team_mgr.award_member_points(team,
                                             p_setting.points_75_percent,
                                             "Team 75% participation")
            elif team.active_participation >= 50:
                team_mgr.award_member_points(team,
                                             p_setting.points_50_percent,
                                             "Team 50% participation")
Beispiel #2
0
 def save(self, *args, **kwargs):
     """Custom save method to create a points transaction after the object is saved."""
     super(QuestMember, self).save(*args, **kwargs)
     if self.completed:
         message = "Quest: %s" % self.quest.name
         self.user.get_profile().add_points(score_mgr.quest_points(),
                                            datetime.datetime.today(), message, self)
     cache_mgr.delete('get_quests-%s' % self.user.username)
Beispiel #3
0
 def save(self, *args, **kwargs):
     """Custom save method to create a points transaction after the object is saved."""
     super(QuestMember, self).save(*args, **kwargs)
     if self.completed:
         message = "Quest: %s" % self.quest.name
         self.user.profile.add_points(score_mgr.quest_points(),
                                      datetime.datetime.today(), message,
                                      self)
     cache_mgr.delete('get_quests-%s' % self.user.username)
def update_resource_usage(resource, date):
    """Update the latest resource usage from Storage server."""

    session = requests.session()

    for team in Team.objects.all():
        goal_settings = team_goal_settings(team, resource)
        if not goal_settings.manual_entry:
            storage = get_resource_storage(goal_settings.data_storage)
            resource_mgr.update_team_resource_usage(resource, session, date, team, storage)

    # clear the cache for energy ranking, and RIB where it displays
    round_name = challenge_mgr.get_round_name(date)
    cache_mgr.delete("%s_ranks-%s" % (resource, slugify(round_name)))
Beispiel #5
0
    def invalidate_cache(self):
        """Invalidate the categories cache."""
        username = self.user.username
        cache_mgr.delete('smartgrid-levels-%s' % username)
        cache_mgr.delete('smartgrid-completed-%s' % username)
        cache_mgr.delete('user_events-%s' % username)
        cache_mgr.delete('get_quests-%s' % username)
        cache_mgr.delete('golow_actions-%s' % username)

        team = self.user.get_profile().team
        if team:
            cache_mgr.invalidate_template_cache("team_avatar", self.action.id, team.id)
        cache_mgr.invalidate_template_cache("commitments", username)
        cache_mgr.invalidate_template_cache("smartgrid", username)
def update_resource_usage(resource, date):
    """Update the latest resource usage from Storage server."""

    session = requests.session()

    for team in Team.objects.all():
        goal_settings = team_goal_settings(team, resource)
        if not goal_settings.manual_entry:
            storage = get_resource_storage(goal_settings.data_storage)
            resource_mgr.update_team_resource_usage(resource, session, date,
                                                    team, storage)

    # clear the cache for energy ranking, and RIB where it displays
    round_name = challenge_mgr.get_round_name(date)
    cache_mgr.delete("%s_ranks-%s" % (resource, slugify(round_name)))
Beispiel #7
0
    def invalidate_cache(self):
        """Invalidate the categories cache."""
        username = self.user.username
        cache_mgr.delete('smartgrid-levels-%s' % username)
        cache_mgr.delete('smartgrid-completed-%s' % username)
        cache_mgr.delete('user_events-%s' % username)
        cache_mgr.delete('get_quests-%s' % username)
        cache_mgr.delete('golow_actions-%s' % username)

        team = self.user.get_profile().team
        if team:
            cache_mgr.invalidate_template_cache("team_avatar", self.action.id, team.id)
        cache_mgr.invalidate_template_cache("my_commitments", username)
        cache_mgr.invalidate_template_cache("my_achievements", username)
        cache_mgr.invalidate_template_cache("smartgrid", username)
Beispiel #8
0
    def testCache(self):
        """Tests basic cache operations."""
        self.assertTrue(cache_mgr.info() is not None,
                        "Test that info() return something.")
        cache_mgr.set_cache('test_key', 'test_value')

        if settings.MAKAHIKI_USE_MEMCACHED:
            self.assertEqual(cache_mgr.get_cache('test_key'), 'test_value',
                             "Test get the correct value from cache.")

        cache_mgr.delete('test_key')
        self.assertEqual(cache_mgr.get_cache('test_key'), None,
                         "Test get the correct value from cache.")

        cache_mgr.clear()
        self.assertEqual(cache_mgr.get_cache('test_key'), None,
                         "Test get the correct value from cache.")
Beispiel #9
0
    def testCache(self):
        """Tests basic cache operations."""
        self.assertTrue(cache_mgr.info() is not None,
                         "Test that info() return something.")
        cache_mgr.set_cache('test_key', 'test_value')

        if settings.MAKAHIKI_USE_MEMCACHED:
            self.assertEqual(cache_mgr.get_cache('test_key'), 'test_value',
                             "Test get the correct value from cache.")

        cache_mgr.delete('test_key')
        self.assertEqual(cache_mgr.get_cache('test_key'), None,
                         "Test get the correct value from cache.")

        cache_mgr.clear()
        self.assertEqual(cache_mgr.get_cache('test_key'), None,
                         "Test get the correct value from cache.")
Beispiel #10
0
def save(request):
    """profile save"""
    form = None
    if request.method == "POST":
        user = request.user
        form = ProfileForm(request.POST, user=request.user.username)

        if form.is_valid():
            profile = user.profile
            name = form.cleaned_data["display_name"].strip()

            if name != profile.name:
                profile.name = name

            user.email = form.cleaned_data["contact_email"]
            user.save()
            profile.contact_text = form.cleaned_data["contact_text"]
            profile.contact_carrier = form.cleaned_data["contact_carrier"]

            theme = form.cleaned_data["theme"].strip()
            if theme and theme != profile.theme:
                profile.theme = theme
                # Invalidate quest bar cache.
                cache_mgr.delete('get_quests-%s' % user.username)

            profile.save()

            # Invalidate info bar cache.
            cache_mgr.invalidate_template_cache("RIB", user.username)

            message = "Your changes have been saved"
        else:
            message = "Please correct the errors below."

        request.session["form_dict"] = form.data
        request.session["form_errors"] = form.errors
        request.session["message"] = message

    return HttpResponseRedirect(reverse("profile_index", args=()))
Beispiel #11
0
def save(request):
    """profile save"""
    form = None
    if request.method == "POST":
        user = request.user
        form = ProfileForm(request.POST, user=request.user.username)

        if form.is_valid():
            profile = user.profile
            name = form.cleaned_data["display_name"].strip()

            if name != profile.name:
                profile.name = name

            user.email = form.cleaned_data["contact_email"]
            user.save()
            profile.contact_text = form.cleaned_data["contact_text"]
            profile.contact_carrier = form.cleaned_data["contact_carrier"]

            theme = form.cleaned_data["theme"].strip()
            if theme and theme != profile.theme:
                profile.theme = theme
                # Invalidate quest bar cache.
                cache_mgr.delete('get_quests-%s' % user.username)

            profile.save()

            # Invalidate info bar cache.
            cache_mgr.invalidate_template_cache("RIB", user.username)

            message = "Your changes have been saved"
        else:
            message = "Please correct the errors below."

        request.session["form_dict"] = form.data
        request.session["form_errors"] = form.errors
        request.session["message"] = message

    return HttpResponseRedirect(reverse("profile_index", args=()))
Beispiel #12
0
 def save(self, *args, **kwargs):
     """Custom save method."""
     super(UserNotification, self).save(*args, **kwargs)
     cache_mgr.delete("notification-%s" % self.recipient.username)
Beispiel #13
0
 def save(self, *args, **kwargs):
     """Custom save method."""
     super(GameSetting, self).save(*args, **kwargs)
     cache_mgr.delete("enabled_widgets")
Beispiel #14
0
 def save(self, *args, **kwargs):
     """Custom save method."""
     super(TeamParticipation, self).save(*args, **kwargs)
     for round_name in challenge_mgr.get_all_round_info()["rounds"].keys():
         cache_mgr.delete("p_ranks-%s" % slugify(round_name))
Beispiel #15
0
 def add_ticket(self, user):
     """Adds a ticket from the user if they have one.
       Throws an exception if they cannot add a ticket."""
     ticket = RaffleTicket(raffle_prize=self, user=user)
     ticket.save()
     cache_mgr.delete('get_quests-%s' % user.username)
Beispiel #16
0
 def save(self, *args, **kwargs):
     """Custom save method."""
     super(RoundSetting, self).save(*args, **kwargs)
     cache_mgr.delete("rounds")
Beispiel #17
0
 def delete(self, *args, **kwargs):
     """Custom delete method."""
     cache_mgr.delete('get_quests-%s' % self.user.username)
     super(QuestMember, self).delete(*args, **kwargs)
 def save(self, *args, **kwargs):
     """Custom save method."""
     super(RoundSetting, self).save(*args, **kwargs)
     cache_mgr.delete("rounds")
Beispiel #19
0
 def add_ticket(self, user):
     """Adds a ticket from the user if they have one.
       Throws an exception if they cannot add a ticket."""
     ticket = RaffleTicket(raffle_prize=self, user=user)
     ticket.save()
     cache_mgr.delete('get_quests-%s' % user.username)
Beispiel #20
0
 def save(self, *args, **kwargs):
     """Custom save method to set fields."""
     super(WaterGoalSetting, self).save(args, kwargs)
     cache_mgr.delete("goal_setting-%s-%s" % ("water", self.team.name))
Beispiel #21
0
 def save(self, *args, **kwargs):
     """Custom save method."""
     super(UserNotification, self).save(*args, **kwargs)
     cache_mgr.delete("notification-%s" % self.recipient.username)
Beispiel #22
0
 def save(self, *args, **kwargs):
     """Custom save method to set fields."""
     super(EnergyGoalSetting, self).save(args, kwargs)
     cache_key = "goal_setting-%s-%s" % ("energy", slugify(self.team.name))
     cache_mgr.delete(cache_key)
Beispiel #23
0
 def delete(self, *args, **kwargs):
     """Custom delete method."""
     cache_mgr.delete('get_quests-%s' % self.user.username)
     super(QuestMember, self).delete(*args, **kwargs)
Beispiel #24
0
 def save(self, *args, **kwargs):
     """Custom save method to set fields."""
     super(EnergyGoalSetting, self).save(args, kwargs)
     cache_mgr.delete("goal_setting-%s-%s" % ("energy", self.team.name))
Beispiel #25
0
 def save(self, *args, **kwargs):
     """Custom save method."""
     super(ResourceSetting, self).save(*args, **kwargs)
     cache_mgr.delete("resource_setting-%s" % self.name)
Beispiel #26
0
 def save(self, *args, **kwargs):
     """Custom save method."""
     super(ReferralSetting, self).save(*args, **kwargs)
     cache_mgr.delete("referral_setting")
 def save(self, *args, **kwargs):
     """Custom save method."""
     super(ScoreSetting, self).save(*args, **kwargs)
     cache_mgr.delete("score_setting")
Beispiel #28
0
 def save(self, *args, **kwargs):
     """Custom save method."""
     super(ChallengeSetting, self).save(*args, **kwargs)
     cache_mgr.delete("challenge")
Beispiel #29
0
 def save(self, *args, **kwargs):
     """Custom save method."""
     super(TeamParticipation, self).save(*args, **kwargs)
     for round_name in challenge_mgr.get_all_round_info()["rounds"].keys():
         cache_mgr.delete("p_ranks-%s" % slugify(round_name))
 def save(self, *args, **kwargs):
     """Custom save method."""
     super(ReferralSetting, self).save(*args, **kwargs)
     cache_mgr.delete("referral_setting")
 def save(self, *args, **kwargs):
     """Custom save method."""
     super(ChallengeSetting, self).save(*args, **kwargs)
     cache_mgr.delete("challenge")
Beispiel #32
0
 def save(self, *args, **kwargs):
     """Custom save method."""
     super(ResourceSetting, self).save(*args, **kwargs)
     cache_mgr.delete("resource_setting-%s" % self.name)
Beispiel #33
0
 def save(self, *args, **kwargs):
     """Custom save method to set fields."""
     super(WaterGoalSetting, self).save(args, kwargs)
     cache_key = "goal_setting-%s-%s" % ("water", slugify(self.team.name))
     cache_mgr.delete(cache_key)
Beispiel #34
0
 def save(self, *args, **kwargs):
     """Custom save method."""
     super(ScoreSetting, self).save(*args, **kwargs)
     cache_mgr.delete("score_setting")