Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Jochen Bauer
spn-website
Commits
2b11cf6f
Commit
2b11cf6f
authored
May 10, 2018
by
nachtgold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
highscore shows the gamers rank
parent
0bb3d2c8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
19 deletions
+46
-19
highscore/static/highscore/highscore.css
highscore/static/highscore/highscore.css
+0
-1
highscore/templates/highscore/table.html
highscore/templates/highscore/table.html
+32
-17
highscore/views.py
highscore/views.py
+14
-1
No files found.
highscore/static/highscore/highscore.css
View file @
2b11cf6f
...
...
@@ -5,7 +5,6 @@
.ui.table.highscore-table
{
font-size
:
.6em
;
margin-left
:
200px
;
width
:
60%
;
}
/*
...
...
highscore/templates/highscore/table.html
View file @
2b11cf6f
...
...
@@ -7,22 +7,37 @@
{% block content %}
<h2>
Highscores
</h2>
<table
class=
"highscore-table ui celled selectable inverted table"
cellspacing=
"0"
style=
"margin-bottom:5em"
>
<thead>
<tr>
<th
class=
"eleven wide"
>
User
</th>
<th
class=
"five wide right aligned"
>
Score
</th>
</tr>
</thead>
<tbody>
{% for score in highscores %}
<tr>
<td>
{{score.user__username}}
</td>
<td
class=
"right aligned"
>
{{score.score|floatformat:1}}
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div
class=
"panel"
>
{% if usr %}
<h2>
Your score
</h2>
<table
class=
"highscore-table ui celled selectable inverted table"
cellspacing=
"0"
style=
"margin-bottom:5em"
>
<tr>
<td
class=
"two wide"
>
{{usr.position}}
</td>
<td
class=
"nine wide"
>
{{request.user.username}}
</td>
<td
class=
"five wide right aligned"
>
{{usr.score|floatformat:1}}
</td>
</tr>
</tbody>
</table>
{% endif %}
<h2>
Highscores
</h2>
<table
class=
"highscore-table ui celled selectable inverted table"
cellspacing=
"0"
style=
"margin-bottom:5em"
>
<thead>
<tr>
<th
class=
"two wide"
>
Position
</th>
<th
class=
"nine wide"
>
User
</th>
<th
class=
"five wide right aligned"
>
Score
</th>
</tr>
</thead>
<tbody>
{% for score in highscores %}
<tr>
<td>
{{score.position}}
</td>
<td>
{{score.user__username}}
</td>
<td
class=
"right aligned"
>
{{score.score|floatformat:1}}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}
\ No newline at end of file
highscore/views.py
View file @
2b11cf6f
...
...
@@ -3,5 +3,18 @@ from django.db.models import Max
from
core.models
import
SnakeGame
def
table
(
request
):
if
request
.
user
.
is_authenticated
:
usr
=
SnakeGame
.
objects
.
filter
(
user
=
request
.
user
).
aggregate
(
score
=
Max
(
'final_mass'
))
data
=
SnakeGame
.
objects
.
values
(
'user__username'
).
annotate
(
score
=
Max
(
'final_mass'
)).
order_by
(
'-score'
)
return
render
(
request
,
'highscore/table.html'
,
context
=
{
'highscores'
:
data
})
for
i
in
range
(
len
(
data
)):
data
[
i
][
'position'
]
=
'{}.'
.
format
(
i
+
1
)
if
request
.
user
.
is_authenticated
and
data
[
i
][
'user__username'
]
==
request
.
user
.
username
:
usr
[
'position'
]
=
data
[
i
][
'position'
]
context
=
{
'highscores'
:
data
}
if
request
.
user
.
is_authenticated
:
context
[
'usr'
]
=
usr
return
render
(
request
,
'highscore/table.html'
,
context
=
context
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment