2017-08-31 13:20:08 +00:00
|
|
|
from django.db.models import Q
|
|
|
|
from django.views.generic import ListView
|
2017-09-04 21:42:57 +00:00
|
|
|
from rest_framework import viewsets
|
|
|
|
from .serializers import ConsoleSerializer
|
2017-08-16 20:00:41 +00:00
|
|
|
|
2017-09-04 21:42:57 +00:00
|
|
|
from .models import Console, Game, Timeline
|
|
|
|
|
|
|
|
class ConsoleViewSet(viewsets.ModelViewSet):
|
|
|
|
"""
|
|
|
|
API endpoints that allows consoles to be edited or viewed.
|
|
|
|
|
|
|
|
retrieve:
|
|
|
|
Return the given console
|
|
|
|
|
|
|
|
list:
|
|
|
|
Return a list of all existing consoles ordered by name.
|
|
|
|
|
|
|
|
create:
|
|
|
|
Create a new console instance.
|
|
|
|
"""
|
|
|
|
queryset = Console.objects.all().order_by('name')
|
|
|
|
serializer_class = ConsoleSerializer
|
2017-08-31 13:20:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
class GameList(ListView):
|
|
|
|
model = Game
|
|
|
|
context_object_name = 'non_excluded_games'
|
|
|
|
template_name = 'games/index.html'
|
2017-08-31 14:35:30 +00:00
|
|
|
queryset = Game.objects.filter(
|
|
|
|
~Q(status=Game.EXCLUDED) &
|
|
|
|
Q(wish=False)).order_by('name')
|
2017-08-31 13:20:08 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
"""
|
2017-08-31 14:35:30 +00:00
|
|
|
Add playing games list.
|
|
|
|
Add 5 last current activities from Timeline
|
2017-08-31 13:20:08 +00:00
|
|
|
"""
|
|
|
|
context = super(GameList, self).get_context_data(**kwargs)
|
|
|
|
context['playing_games'] = Game.objects.filter(
|
|
|
|
playing=True).order_by('name')
|
2017-09-03 08:53:17 +00:00
|
|
|
context['last_timelines'] = Timeline.objects.filter(
|
|
|
|
~Q(item__status=Game.EXCLUDED)
|
|
|
|
).order_by(
|
2017-08-31 14:35:30 +00:00
|
|
|
'-date')[:5]
|
2017-09-03 08:53:17 +00:00
|
|
|
return context
|