Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Commit

Permalink
Merge pull request #513 from praekelt/feature/golden-egg-splash
Browse files Browse the repository at this point in the history
Add splash screen for golden egg award.
  • Loading branch information
rjacobs31 committed Mar 16, 2017
2 parents c0bba9a + 70a7c64 commit 395c33e
Show file tree
Hide file tree
Showing 8 changed files with 271 additions and 116 deletions.
102 changes: 58 additions & 44 deletions oneplus/learn_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,40 @@ def post():
special_rule=True
)

if golden_egg:
_golden_egg = get_golden_egg(_participant)
state["won_golden_egg"] = True
if _golden_egg:
if _golden_egg.point_value:
_participant.points += _golden_egg.point_value
_participant.save()
if _golden_egg.airtime:
mail_managers(subject="Golden Egg Airtime Award",
message="%s %s %s won R %d airtime from a Golden Egg"
% (_participant.learner.first_name, _participant.learner.last_name,
_participant.learner.mobile, _golden_egg.airtime),
fail_silently=False)
if _golden_egg.badge:

b = ParticipantBadgeTemplateRel(participant=_participant,
badgetemplate=_golden_egg.badge.badge,
scenario=_golden_egg.badge,
awarddate=datetime.now())
b.save()

BadgeAwardLog(participant_badge_rel=b, award_date=datetime.now()).save()

if _golden_egg.badge.point and _golden_egg.badge.point.value:
_participant.points += _golden_egg.badge.point.value
_participant.save()

golden_egg["url"] = Setting.objects.get(key="GOLDEN_EGG_IMG_URL").value
GoldenEggRewardLog(participant=_participant,
points=_golden_egg.point_value,
airtime=_golden_egg.airtime,
badge=_golden_egg.badge).save()
return redirect('learn.golden_egg_splash')

return redirect("learn.right")

else:
Expand Down Expand Up @@ -1495,49 +1529,6 @@ def right(request, state, user, participant):
event=_event,
).distinct('participant', 'question', 'event').count()
request.session["state"]["total_event_questions"] = EventQuestionRel.objects.filter(event=_event).count()
golden_egg = {}

if (len(_learnerstate.get_answers_this_week()) + _learnerstate.get_num_questions_answered_today()) == \
_learnerstate.golden_egg_question and get_golden_egg(_participant):
# ensure the question was answered on the allocated bucket day, 3 days per bucket
# ie. golden_egg_question = 1 Only Monday
# golden_egg_question = 7 Only Wednesday
if ((_learnerstate.golden_egg_question - 1) // 3) == _learnerstate.get_week_day():
_golden_egg = get_golden_egg(_participant)
if _golden_egg and "won_golden_egg" not in state:
state["won_golden_egg"] = True
if _golden_egg.point_value:
golden_egg["message"] = "You've won this week's Golden Egg and %d points." % _golden_egg.point_value
_participant.points += _golden_egg.point_value
_participant.save()
if _golden_egg.airtime:
golden_egg["message"] = "You've won this week's Golden Egg and your share of R %d airtime. " \
"You will be awarded your airtime next Monday." % _golden_egg.airtime
mail_managers(subject="Golden Egg Airtime Award",
message="%s %s %s won R %d airtime from a Golden Egg"
% (_participant.learner.first_name, _participant.learner.last_name,
_participant.learner.mobile, _golden_egg.airtime),
fail_silently=False)
if _golden_egg.badge:
golden_egg["message"] = "You've won this week's Golden Egg and a badge"

b = ParticipantBadgeTemplateRel(participant=_participant,
badgetemplate=_golden_egg.badge.badge,
scenario=_golden_egg.badge,
awarddate=datetime.now())
b.save()

BadgeAwardLog(participant_badge_rel=b, award_date=datetime.now()).save()

if _golden_egg.badge.point and _golden_egg.badge.point.value:
_participant.points += _golden_egg.badge.point.value
_participant.save()

golden_egg["url"] = Setting.objects.get(key="GOLDEN_EGG_IMG_URL").value
GoldenEggRewardLog(participant=_participant,
points=_golden_egg.point_value,
airtime=_golden_egg.airtime,
badge=_golden_egg.badge).save()

state["total_tasks_today"] = _learnerstate.get_total_questions()

Expand Down Expand Up @@ -1589,7 +1580,6 @@ def get():
{
"badges": badges,
"comment_messages": _messages,
"golden_egg": golden_egg,
"most_popular": _popular_messages,
"question": _learnerstate.active_question,
"points": points,
Expand Down Expand Up @@ -1720,6 +1710,30 @@ def post():
return resolve_http_method(request, [get, post])


@oneplus_participant_required
def golden_egg_splash(request, state, user, participant):
_learnerstate = LearnerState.objects.filter(participant=participant).first()

golden_egg = GoldenEggRewardLog.objects.filter(participant=participant)\
.values('award_date', 'points', 'airtime', 'badge')\
.order_by('-award_date')\
.first()

answer = ParticipantQuestionAnswer.objects.filter(participant=participant,
question_id=_learnerstate.active_question.id)\
.only('answerdate')\
.order_by('-answerdate')\
.first()

def get():
if not golden_egg or not answer or golden_egg['award_date'] < answer.answerdate:
return redirect('learn.right')

return render(request, 'prog/golden_egg_splash.html', {'golden_egg': golden_egg})

return resolve_http_method(request, [get])


@oneplus_participant_required
def wrong(request, state, user, participant):
# get learner state
Expand Down
3 changes: 3 additions & 0 deletions oneplus/static/css/oneplus.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 0 additions & 9 deletions oneplus/templates/learn/right.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@ <h2>
You've earned <b>{% if points %}{{ points }} point{{ points |pluralize }}{% else %}0 points{% endif %}</b>.
</h2>

{% if golden_egg %}
<section>
<div class="center-font"><img src="{{ golden_egg.url }}"></div>
<h3 class="center-font">Congratulations!</h3>
<div class="center-font">
<p>{{ golden_egg.message }}</p>
</div>
</section>
{% endif %}
{% if badges %}
<section>
{% for badge in badges %}
Expand Down
24 changes: 24 additions & 0 deletions oneplus/templates/prog/golden_egg_splash.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% extends "core/main.html" %}

{% block title %}Golden Egg{% endblock %}

{% block page_descriptor_text %}Golden Egg{% endblock %}

{% block content %}
<article class="content sunflower-yellow-accent">
<h1 class="center-font color-accent">You've won a Golden Egg!</h1>

<div class="img-container">
<img class="limit-size" src="/media/img/splash/splash_golden_egg.png" width="100%" height="auto"/>
</div>

<h3>
You've won this week's <span class="color-accent">Golden Egg</span>{% if golden_egg.points %} and
{{ golden_egg.points }} points{% endif %}{% if golden_egg.airtime %} and R{{ golden_egg.airtime }}
airtime{% endif %}{% if golden_egg.badge %} and a badge{% endif %}.
{% if golden_egg.airtime %}You will be awarded your airtime next Monday.{% endif %}
</h3>

<a class="button" href="right">Continue</a>
</article>
{% endblock content %}
4 changes: 2 additions & 2 deletions oneplus/templates/sharing/badge_single.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ <h3 class="center-font">{{ badge.name }}</h3>
</a>
</li>
<li class="js-required should-block" style="display:none">
<a class="vert-center" href="https://twitter.com/intent/tweet?text={{ "I earned a badge on Dig-it!"|urlencode:'' }}&url={{ FB_REDIRECT|urlencode:'' }}{{ share_url|urlencode:'' }}" src="">
<a class="vert-center" href="https://twitter.com/intent/tweet?text={{ 'I earned a badge on Dig-it!'|urlencode:'' }}&url={{ FB_REDIRECT|urlencode:'' }}{{ share_url|urlencode:'' }}" src="">
<span class="icon tw-logo vert-center" style="margin:-6px"></span>Share on Twitter
</a>
</li>
Expand Down Expand Up @@ -71,7 +71,7 @@ <h3 class="center-font">{{ badge.name }}</h3>
<ul>
<li>
<p>You will not be able to share your level until you give us
<a href="{% url "auth.profile" %}" >permission to share your achievements</a>.
<a href="{% url 'auth.profile' %}" >permission to share your achievements</a>.
</p>
</li>
</ul>
Expand Down
Loading

0 comments on commit 395c33e

Please sign in to comment.