Skip to content

Commit

Permalink
Add logout button to base template
Browse files Browse the repository at this point in the history
  • Loading branch information
celeritas17 committed Feb 4, 2014
1 parent 3a95260 commit 9b3ed96
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 10 deletions.
13 changes: 13 additions & 0 deletions assets/css/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ body{
border-radius: 20px;
border-top-left-radius:2px;
border-top-right-radius:2px;
position:relative;
}

a, a:visited, a:active{
Expand All @@ -57,3 +58,15 @@ div.muncher > img{
margin-top:60px;
}

.logout{
color:#111;
height:17px;
width:75px;
border-radius:10px;
background-color: #5dfc0a;
font-family: Arial, Monaco, monospace;
position:absolute;
bottom:0;
float:right;
}

21 changes: 13 additions & 8 deletions puzzles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ def puzzle(request, puzzle_id):
user = request.user
answers = [ans.replace('_', ' ') for ans in p.right_answers.split() + p.wrong_answers.split()]
shuffle(answers)
pa = PuzzleAttempt(puzzle=p, attempt_date=now(), user=user)
pa.save()
if user.id:
pa = PuzzleAttempt(puzzle=p, attempt_date=now(), user=user)
pa.save()
else:
pa = False
prizes = random.sample(xrange(0, row_size*col_size - 1), 3) # ids for the hidden prizes
prize1, prize2, prize3 = prizes

Expand All @@ -30,14 +33,15 @@ def puzzle(request, puzzle_id):
'prize1': prize1,
'prize2': prize2,
'prize3': prize3,
'attempt_id': pa.id,
'attempt_id': (0 if not pa else pa.id),
}
context.update(csrf(request))
return render_to_response('puzzle.html', context)

def puzzles(request):
user = request.user
puzzles = Puzzle.objects.all()
context = {'puzzles': Puzzle.objects.all()[0:14]}
context = {'puzzles': Puzzle.objects.all()[0:14], 'user': user}

return render_to_response('puzzles.html', context)

Expand All @@ -47,10 +51,11 @@ def endgame(request):
score = request.POST['score']
context = {'success':success}
if success == 'victory':
pa = PuzzleAttempt.objects.get(pk=attempt_id)
pa.success = True
pa.score = score
pa.save()
if int(attempt_id) > 0:
pa = PuzzleAttempt.objects.get(pk=attempt_id)
pa.success = True
pa.score = score
pa.save()
context['score'] = score

return render_to_response('game_over.html', context)
Expand Down
1 change: 1 addition & 0 deletions snacMan/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
url(r'^register/$', 'register'),
url(r'^register_success/$', 'register_success'),
url(r'^register_fail/$', 'register_fail'),
url(r'^logout/$', 'logout'),
)
Binary file modified snacMan/urls.pyc
Binary file not shown.
7 changes: 6 additions & 1 deletion snacMan/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
from forms import SnacManRegistrationForm

def main(request):
return render_to_response('main.html')
user = request.user
return render_to_response('main.html', {'user': user})

def login(request):
context = {}
context.update(csrf(request))
return render_to_response('login.html', context)

def logout(request):
auth.logout(request)
return render_to_response('main.html', {'logout': True})

def auth_view(request):
username = request.POST.get('username', '')
password = request.POST.get('password', '')
Expand Down
13 changes: 13 additions & 0 deletions static/css/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ body{
border-radius: 20px;
border-top-left-radius:2px;
border-top-right-radius:2px;
position:relative;
}

a, a:visited, a:active{
Expand All @@ -57,3 +58,15 @@ div.muncher > img{
margin-top:60px;
}

.logout{
color:#111;
height:17px;
width:75px;
border-radius:10px;
background-color: #5dfc0a;
font-family: Arial, Monaco, monospace;
position:absolute;
bottom:0;
float:right;
}

6 changes: 6 additions & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
{% block scoreboard %}
<h1><em>SnacMan</em></h1>
<div class="muncher"><img src="{% static "assets/img/eat1.png" %}" /></div>
{% if user.is_authenticated %}
<div class="logout">
<a href="{% url 'snacMan.views.logout' %}">Logout</a>
</div>
{% endif %}

{% endblock %}

</div>
Expand Down
6 changes: 5 additions & 1 deletion templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@

{% block content %}
<h1>Hello, World</h1>
{% if logout %}
<h2>Logged Out</h2>
{% endif %}
<div class="buttons">
<div id="register"><h4><em><a href="{% url 'snacMan.views.register' %}">Register</a></em></h4></div>
<div id="play"><h4><em><a href="{% url 'puzzles.views.puzzles' %}">Play</a></em></h4></div>
<div id="login"><h4><em><a href="{% url 'snacMan.views.login' %}">Login</a></em></h4></div>
</div>
{% endblock %}
{% endblock %}

0 comments on commit 9b3ed96

Please sign in to comment.