Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions hvzsite/hvz/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
re_path(r'^api/reports/?$', views.ApiReports.as_view()),
re_path(r'^api/create-av/?$', views.ApiCreateAv.as_view()),
re_path(r'^api/create-armor/?$', views.ApiCreateBodyArmor.as_view()),
re_path(r'^api/recent_events/?$', views.recent_events_view),

# Api Documentation
re_path(r'^openapi/?$', get_schema_view(
Expand Down
67 changes: 67 additions & 0 deletions hvzsite/hvz/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,74 @@ def index(request):
'zombiecounts': zombiecounts,
'humancounts': humancounts,
'scoreboards': scoreboards})
@api_view(["GET"])
def recent_events_view(request):
game = get_active_game()
if len(most_recent_tags := Tag.objects.filter(game=game).order_by('-timestamp')) > 0:
most_recent_tag = most_recent_tags[0]
else:
most_recent_tag = None
if len(most_recent_avs := AntiVirus.objects.filter(game=game, used_by__isnull=False).order_by('-time_used')) > 0:
most_recent_av = most_recent_avs[0]
else:
most_recent_av = None
if len(most_recent_registrations := PlayerStatus.objects.filter(game=game).order_by("-activation_timestamp")) > 0:
most_recent_registration = most_recent_registrations[0]
else:
most_recent_registration = None
(humancount, zombiecount, most_tags, merged_recents, timestamps, zombiecounts, humancounts) = get_recent_events(
most_recent_tag, most_recent_av, most_recent_registration)

authed = request.user.is_authenticated

data = {
"humancount": humancount,
"zombiecount": zombiecount,
"most_tags": [
{
'player_uuid': h.player.player_uuid,
'player_name': h.player.readable_name(authed),
'tags': h.num_tags
} for h in most_tags
],
"recent_events": [
{
'type': "av",
'av_uuid': e.av_uuid,
'time_used': e.time_used,
'used_by': {
'player_uuid': e.used_by.player_uuid,
'player_name': e.used_by.readable_name(authed),
}
}
if isinstance(e, AntiVirus) else
{
"type": 'tag',
"tagger": {
"player_uuid": e.tagger.player_uuid,
"player_name": e.tagger.readable_name(authed)
} if e.tagger is not None else {},
"taggee": {
"player_uuid": e.taggee.player_uuid,
"player_name": e.taggee.readable_name(authed)
} if e.taggee is not None else {},
"armor_taggee": {
"armor_uuid": e.armor_taggee.armor_uuid
} if e.armor_taggee is not None else {},
"timestamp": e.timestamp
} for e in merged_recents
],
"timestamps": [
t for t in timestamps
],
"zombiecounts": [
z for z in zombiecounts
],
"humancounts": [
h for h in humancounts
]
}
return JsonResponse(data)

def infection(request):
game = get_active_game()
Expand Down