Ejemplo n.º 1
0
def group_active_participation(num_results=None, round_name=None):
    """Calculate active participation."""
    if not round_name:
        round_name = challenge_mgr.get_round_name()

    participation = cache_mgr.get_cache('group_active_p-%s' % slugify(round_name))
    if participation is None:
        active_participation = Group.objects.filter(
            team__profile__scoreboardentry__points__gte=score_mgr.active_threshold_points(),
            team__profile__scoreboardentry__round_name=round_name).annotate(
                user_count=Count('team__profile')).order_by('-user_count')

        if num_results:
            active_participation = active_participation[:num_results]

        participation = []
        for g in active_participation:
            group_size = 0
            for t in g.team_set.all():
                group_size += t.profile_set.count()
            g.active_participation = (g.user_count * 100) / group_size
            participation.append(g)

        for g in Group.objects.all():
            if len(participation) == num_results:
                break

            if not g in active_participation:
                g.active_participation = 0
                participation.append(g)
        cache_mgr.set_cache('group_active_p-%s' % slugify(round_name), participation, 1800)
    return participation
Ejemplo n.º 2
0
def team_active_participation(num_results=None, round_name=None):
    """Calculate active participation."""
    if not round_name:
        round_name = challenge_mgr.get_round_name()

    participation = cache_mgr.get_cache('active_p-%s' % slugify(round_name))
    if participation is None:
        active_participation = Team.objects.filter(
            profile__scoreboardentry__points__gte=score_mgr.active_threshold_points(),
            profile__scoreboardentry__round_name=round_name).annotate(
                user_count=Count('profile')).order_by('-user_count')

        if num_results:
            active_participation = active_participation[:num_results]

        participation = []
        for t in active_participation:
            if t.size:
                t.active_participation = (t.user_count * 100) / t.size
            else:
                t.active_participation = (t.user_count * 100) / t.profile_set.count()
            participation.append(t)

        for t in Team.objects.all():
            if len(participation) == num_results:
                break

            if not t in active_participation:
                t.active_participation = 0
                participation.append(t)
        cache_mgr.set_cache('active_p-%s' % slugify(round_name), participation, 1800)
    return participation
Ejemplo n.º 3
0
    def _award_possible_referral_bonus(self):
        """award possible referral bonus."""

        has_referral = self.referring_user is not None and not self.referrer_awarded
        if has_referral and self.points() >= score_mgr.active_threshold_points():
            self.referrer_awarded = True
            self.save()
            referrer = self.referring_user.get_profile()
            score_mgr.award_referral_bonus(self, referrer)
Ejemplo n.º 4
0
    def _award_possible_referral_bonus(self):
        """award possible referral bonus."""

        # check if the referral game mechanics is enabled
        if not challenge_mgr.is_game_enabled("Referral Game Mechanics"):
            return

        has_referral = self.referring_user is not None and not self.referrer_awarded

        if has_referral and self.points() >= score_mgr.active_threshold_points():
            referrer = self.referring_user.profile
            if referrer.setup_profile:
                self.referrer_awarded = True
                self.save()
                score_mgr.award_referral_bonus(self, referrer)
Ejemplo n.º 5
0
    def _award_possible_referral_bonus(self):
        """award possible referral bonus."""

        # check if the referral game mechanics is enabled
        if not challenge_mgr.is_game_enabled("Referral Game Mechanics"):
            return

        has_referral = self.referring_user is not None and not self.referrer_awarded

        if has_referral and self.points() >= score_mgr.active_threshold_points(
        ):
            referrer = self.referring_user.profile
            if referrer.setup_profile:
                self.referrer_awarded = True
                self.save()
                score_mgr.award_referral_bonus(self, referrer)
Ejemplo n.º 6
0
def referral(request):
    """Display page 3 (referral bonus) of the first login wizard."""

    if request.is_ajax():
        profile = request.user.get_profile()
        form = None

        if request.method == 'POST':
            form = ReferralForm(request.POST, user=request.user)
            if form.is_valid():
                cleaned_data = form.cleaned_data
                if 'referrer_email' in cleaned_data and len(
                        cleaned_data['referrer_email']) > 0:
                    profile.referring_user = User.objects.\
                    get(email=cleaned_data['referrer_email'])
                else:
                    # Double check just in case user comes back and deletes
                    # the email.
                    profile.referring_user = None
                profile.save()

                return _get_profile_form(request)

                # If form is not valid, it falls through here
        if not form and profile.referring_user:
            form = ReferralForm(
                initial={'referrer_email': profile.referring_user.email})
        elif not form:
            form = ReferralForm()

        response = render_to_string(
            'first-login/referral.html', {
                'form': form,
                'referral_points': score_mgr.referral_points(profile),
                'active_threshold_points': score_mgr.active_threshold_points(),
            },
            context_instance=RequestContext(request))

        return HttpResponse(json.dumps({
            "title": "Introduction: Step 3 of 7",
            "contents": response,
        }),
                            mimetype='application/json')

    raise Http404
Ejemplo n.º 7
0
def referral(request):
    """Display page 3 (referral bonus) of the first login wizard."""

    if request.is_ajax():
        profile = request.user.get_profile()
        form = None

        if request.method == 'POST':
            form = ReferralForm(request.POST, user=request.user)
            if form.is_valid():
                cleaned_data = form.cleaned_data
                if 'referrer_email' in cleaned_data and len(
                    cleaned_data['referrer_email']) > 0:
                    profile.referring_user = User.objects.\
                    get(email=cleaned_data['referrer_email'])
                else:
                    # Double check just in case user comes back and deletes
                    # the email.
                    profile.referring_user = None
                profile.save()

                return _get_profile_form(request)

                # If form is not valid, it falls through here
        if not form and profile.referring_user:
            form = ReferralForm(initial={
                'referrer_email': profile.referring_user.email
            })
        elif not form:
            form = ReferralForm()

        response = render_to_string('first-login/referral.html', {
            'form': form,
            'referral_points': score_mgr.referral_points(),
            'active_threshold_points': score_mgr.active_threshold_points(),
            }, context_instance=RequestContext(request))

        return HttpResponse(json.dumps({
            "title": "Introduction: Step 3 of 7",
            "contents": response,
            }), mimetype='application/json')

    raise Http404