Skip to content

Commit

Permalink
Query now works and leaderboard displays properly
Browse files Browse the repository at this point in the history
  • Loading branch information
VemAak committed Oct 30, 2024
1 parent 3152c49 commit 4c2baec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 13 additions & 1 deletion nablapps/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,19 @@ def get_context_data(self, **kwargs):

# TODO: fiks SQL query
context["bedpres_leaderboard"] = EventRegistration.objects.raw(
"""SELECT COUNT(attendance_registration), username from EventRegistration JOIN users WHERE EventRegistration.userId = users.id JOIN event where EventRegistration.eventId = event.id WHERE EventRegistration.date > "2024 - 08 - 10" AND EventRegistration.date < "2025 - 06 - 20" AND event.is_bedpres GROUP BY userId LIMIT 10"""
"""SELECT 1 as id,
COUNT(r.attendance_registration) AS num_bedpres,
u.username,
u.first_name, u.last_name
FROM content_eventregistration AS r
INNER JOIN accounts_nablauser AS u ON r.user_id = u.id
INNER JOIN content_event AS e ON r.event_id = e.id
WHERE r.date > '2024-08-10'
AND r.date < '2025-06-20'
AND e.is_bedpres = 1
GROUP BY r.user_id
ORDER BY num_bedpres DESC
LIMIT 10"""
)
return context

Expand Down
4 changes: 2 additions & 2 deletions templates/front_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ <h5 class="nabla-frontpage-header">
<tr><th>Bruker</th><th>Antall Bedpres</th></tr>
{% for t in bedpres_leaderboard %}
<tr>
<td>{{t.user.get_full_name}}</td>
<td>{{t.length}}</td> <!-- TODO: hva skal stå her istedenfor length???, Funker dette egentlig? -->
<td>{{t.first_name}} {{t.last_name}}</td>
<td>{{t.num_bedpres}}</td> <!-- TODO: hva skal stå her istedenfor length???, Funker dette egentlig? -->
</tr>
{% endfor %}
</table>
Expand Down

0 comments on commit 4c2baec

Please sign in to comment.