2018-10-26 23:42:53 +00:00
|
|
|
from django.shortcuts import render
|
2018-12-14 01:58:59 +00:00
|
|
|
from django.views.generic import View
|
|
|
|
from GeoffreyApp.models import *
|
|
|
|
from django.views import generic
|
2018-12-15 21:12:17 +00:00
|
|
|
from django.db.models import Q
|
2018-10-26 23:42:53 +00:00
|
|
|
# Create your views here.
|
2018-11-22 02:09:30 +00:00
|
|
|
|
|
|
|
|
2018-12-14 01:58:59 +00:00
|
|
|
class Home(View):
|
|
|
|
|
|
|
|
def get(self, request):
|
2019-01-12 21:06:06 +00:00
|
|
|
stats = []
|
|
|
|
stats.append(("Players", Player.objects.count()))
|
|
|
|
stats.append(("Bases", Base.objects.count()))
|
|
|
|
stats.append(("Shops", Shop.objects.count()))
|
2019-01-15 01:21:15 +00:00
|
|
|
stats.append(("Items for Sale", ItemListing.objects.count()))
|
2018-12-14 01:58:59 +00:00
|
|
|
|
|
|
|
context = {
|
2019-01-12 21:06:06 +00:00
|
|
|
"stat_list": stats,
|
2019-01-11 22:40:12 +00:00
|
|
|
"current_page": "Home",
|
2018-12-14 01:58:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return render(request, 'GeoffreyApp/home.html', context=context)
|
|
|
|
|
|
|
|
|
2019-01-11 22:40:12 +00:00
|
|
|
class SearchList(View):
|
|
|
|
def get(self, request):
|
|
|
|
context = {}
|
|
|
|
query = request.GET.get('search')
|
|
|
|
context["search"] = query
|
|
|
|
|
|
|
|
context["player_list"] = Player.objects.filter(Q(name__icontains=query)).all()
|
|
|
|
|
2019-01-12 21:06:06 +00:00
|
|
|
context["loc_list"] = Location.objects.filter(Q(name__icontains=query) | Q(owner__name__icontains=query)).all()
|
2019-01-11 22:40:12 +00:00
|
|
|
|
|
|
|
return render(request, 'GeoffreyApp/search.html', context=context)
|
|
|
|
|
|
|
|
|
2018-12-14 01:58:59 +00:00
|
|
|
class PlayerList(generic.ListView):
|
|
|
|
model = Player
|
|
|
|
|
2019-01-11 22:40:12 +00:00
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context['current_page'] = "Players"
|
|
|
|
return context
|
|
|
|
|
2018-12-14 01:58:59 +00:00
|
|
|
|
|
|
|
class ShopList(generic.ListView):
|
|
|
|
model = Shop
|
|
|
|
|
2019-01-11 22:40:12 +00:00
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context['current_page'] = "Shops"
|
|
|
|
return context
|
|
|
|
|
2018-12-15 21:12:17 +00:00
|
|
|
def get_queryset(self):
|
|
|
|
qs = Shop.objects.all()
|
|
|
|
|
|
|
|
search = self.request.GET.get('q')
|
|
|
|
if search:
|
|
|
|
qs = qs.filter(Q(name__icontains=search) | Q(owner__name__icontains=search))
|
|
|
|
|
|
|
|
return qs
|
|
|
|
|
|
|
|
|
2018-12-14 01:58:59 +00:00
|
|
|
class BaseList(generic.ListView):
|
|
|
|
model = Base
|
|
|
|
|
2019-01-11 22:40:12 +00:00
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context['current_page'] = "Bases"
|
|
|
|
return context
|
|
|
|
|
2018-12-30 01:41:18 +00:00
|
|
|
|
2018-12-14 01:58:59 +00:00
|
|
|
class ItemListingList(generic.ListView):
|
|
|
|
model = ItemListing
|
|
|
|
|
2019-01-11 22:40:12 +00:00
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context['current_page'] = "Item Listings"
|
|
|
|
return context
|
2019-01-14 01:27:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PlayerInfo(View):
|
|
|
|
def get(self, request, id):
|
|
|
|
try:
|
|
|
|
player = Player.objects.get(pk=id)
|
|
|
|
loc_list = Location.objects.filter(owner=player).all()
|
|
|
|
|
|
|
|
context = {
|
|
|
|
"player": player,
|
|
|
|
"loc_list": loc_list
|
|
|
|
}
|
|
|
|
return render(request, 'GeoffreyApp/player.html', context=context)
|
|
|
|
except Player.DoesNotExist:
|
|
|
|
return render(request, 'GeoffreyApp/error.html')
|
|
|
|
|
|
|
|
|
|
|
|
class ShopInfo(View):
|
|
|
|
def get(self, request, id):
|
|
|
|
try:
|
|
|
|
shop = Shop.objects.get(pk=id)
|
|
|
|
inventory = ItemListing.objects.filter(shop=shop).all()
|
|
|
|
|
|
|
|
context = {
|
|
|
|
"loc": shop,
|
|
|
|
"inventory": inventory
|
|
|
|
}
|
|
|
|
return render(request, 'GeoffreyApp/shop.html', context=context)
|
|
|
|
except Player.DoesNotExist:
|
|
|
|
return render(request, 'GeoffreyApp/error.html')
|
|
|
|
|
|
|
|
|
|
|
|
class BaseInfo(View):
|
|
|
|
def get(self, request, id):
|
|
|
|
try:
|
|
|
|
base = Base.objects.get(pk=id)
|
|
|
|
|
|
|
|
context = {
|
|
|
|
"loc": base,
|
|
|
|
}
|
|
|
|
return render(request, 'GeoffreyApp/location.html', context=context)
|
|
|
|
except Player.DoesNotExist:
|
|
|
|
return render(request, 'GeoffreyApp/error.html')
|