def player_remove_points(profile, points, transaction_date, message, related_object=None): """Removes points from the user. If the submission date is the same as the last_awarded_submission field, we rollback to a previously completed task. """ if not challenge_mgr.in_competition(transaction_date): return # update the scoreboard entry _update_scoreboard_entry(profile, points * -1, transaction_date) # Log the transaction. transaction = PointsTransaction( user=profile.user, points=points * -1, transaction_date=transaction_date, message=message, ) if related_object: transaction.related_object = related_object transaction.save() # Invalidate info bar cache. cache_mgr.invalidate_template_cache("RIB", profile.user.username)
def player_remove_points(profile, points, transaction_date, message, related_object=None): """Removes points from the user. If the submission date is the same as the last_awarded_submission field, we rollback to a previously completed task. """ if not challenge_mgr.in_competition(transaction_date): return # update the scoreboard entry _update_scoreboard_entry(profile, points * -1, transaction_date) # Log the transaction. transaction = PointsTransaction( user=profile.user, points=points * -1, transaction_date=transaction_date, message=message, ) if related_object: transaction.related_object = related_object transaction.save() # Invalidate info bar cache. cache_mgr.invalidate_template_cache("RIB", profile.user.username)
def player_add_points(profile, points, transaction_date, message, related_object=None): """Adds points based on the point value of the submitted object.""" # player won't get points if outside of the competitions. # ignore the transaction if not challenge_mgr.in_competition(transaction_date): return # Create a transaction first. transaction = PointsTransaction( user=profile.user, points=points, transaction_date=transaction_date, message=message, ) if related_object: transaction.related_object = related_object transaction.save() # update the scoreboard entry _update_scoreboard_entry(profile, points, transaction_date) # Invalidate info bar cache. cache_mgr.invalidate_template_cache("RIB", profile.user.username)
def player_add_points(profile, points, transaction_date, message, related_object=None): """Adds points based on the point value of the submitted object.""" # player won't get points if outside of the competitions. # ignore the transaction if not challenge_mgr.in_competition(transaction_date): return # Create a transaction first. transaction = PointsTransaction( user=profile.user, points=points, transaction_date=transaction_date, message=message, ) if related_object: transaction.related_object = related_object transaction.save() # update the scoreboard entry _update_scoreboard_entry(profile, points, transaction_date) # Invalidate info bar cache. cache_mgr.invalidate_template_cache("RIB", profile.user.username)
def supply(request, page_name): """Supply view_objects for My_Info and process the POST command.""" _ = page_name user = request.user form = None if request.method == "POST": user = request.user form = ProfileForm(request.POST, user=request.user) if form.is_valid(): profile = user.get_profile() name = form.cleaned_data["display_name"].strip() if name != profile.name: profile.name = name theme = form.cleaned_data["theme"].strip() if theme and theme != profile.theme: profile.theme = theme 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"] profile.save() # Invalidate info bar cache. cache_mgr.invalidate_template_cache("RIB", user.username) form.message = "Your changes have been saved" else: form.message = "Please correct the errors below." # If this is a new request, initialize the form. if not form: profile = user.get_profile() user_theme = profile.theme if not user_theme: user_theme = challenge_mgr.get_challenge().theme form = ProfileForm(initial={ "display_name": profile.name, "contact_email": user.email, "contact_text": profile.contact_text, "contact_carrier": profile.contact_carrier, "theme": user_theme, }) if "changed_avatar" in request.GET: form.message = "Your avatar has been updated." return { "form": form, }
def save(self, *args, **kwargs): if self.primary: avatars = Avatar.objects.filter(user=self.user, primary=True)\ .exclude(id=self.id) avatars.update(primary=False) super(Avatar, self).save(*args, **kwargs) # Invalidate info bar cache. user = self.user cache_mgr.invalidate_template_cache("RIB", user.username) # Invalidate team action avatar cache. team = user.get_profile().team if team: for member in ActionMember.objects.filter(user=user): cache_mgr.invalidate_template_cache("team_avatar", member.action.id, team.id)
def player_add_points(profile, points, transaction_date, message, related_object=None): """Adds points based on the point value of the submitted object.""" # Create a transaction first. transaction = PointsTransaction( user=profile.user, points=points, transaction_date=transaction_date, message=message, ) if related_object: transaction.related_object = related_object transaction.save() # update the scoreboard entry _update_scoreboard_entry(profile, points, transaction_date) # Invalidate info bar cache. cache_mgr.invalidate_template_cache("RIB", profile.user.username)
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=()))
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=()))
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)
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)
def save(self, *args, **kwargs): if self.primary: avatars = Avatar.objects.filter(user=self.user, primary=True)\ .exclude(id=self.id) avatars.update(primary=False) super(Avatar, self).save(*args, **kwargs) # Invalidate info bar cache. user = self.user cache_mgr.invalidate_template_cache("RIB", user.username) # Invalidate team action avatar cache. team = user.get_profile().team if team: cache_mgr.invalidate_template_cache("team_member_avatar", team.id) for member in ActionMember.objects.filter(user=user): cache_mgr.invalidate_template_cache("team_avatar", member.action.id, team.id)
def award_badge(profile, badge): """award the badge to the user.""" BadgeAward(profile=profile, badge=badge).save() if profile.team: cache_mgr.invalidate_template_cache("team_member_avatar", profile.team.id)