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)
|
|
|
|
|
|
|
|
|
2019-04-13 00:39:25 +00:00
|
|
|
class GeoffreyModelList(generic.ListView):
|
|
|
|
model = None
|
2018-12-14 01:58:59 +00:00
|
|
|
|
2019-01-11 22:40:12 +00:00
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
2019-04-13 00:39:25 +00:00
|
|
|
|
|
|
|
context['current_page'] = self.model.__name__
|
2019-01-11 22:40:12 +00:00
|
|
|
return context
|
|
|
|
|
2018-12-14 01:58:59 +00:00
|
|
|
|
2019-04-13 00:39:25 +00:00
|
|
|
class PlayerList(GeoffreyModelList):
|
|
|
|
model = Player
|
2018-12-14 01:58:59 +00:00
|
|
|
|
2019-04-13 00:39:25 +00:00
|
|
|
|
|
|
|
class ShopList(GeoffreyModelList):
|
|
|
|
model = Shop
|
2019-01-11 22:40:12 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2019-04-13 00:39:25 +00:00
|
|
|
class BaseList(GeoffreyModelList):
|
2018-12-14 01:58:59 +00:00
|
|
|
model = Base
|
|
|
|
|
2018-12-30 01:41:18 +00:00
|
|
|
|
2019-04-13 00:39:25 +00:00
|
|
|
class TownList(GeoffreyModelList):
|
2019-02-06 20:54:50 +00:00
|
|
|
model = Town
|
|
|
|
|
|
|
|
|
2019-04-13 00:39:25 +00:00
|
|
|
class PublicFarmList(GeoffreyModelList):
|
2019-03-02 17:48:28 +00:00
|
|
|
model = PublicFarm
|
|
|
|
|
|
|
|
|
2019-04-13 00:39:25 +00:00
|
|
|
class ItemListingList(GeoffreyModelList):
|
2018-12-14 01:58:59 +00:00
|
|
|
model = ItemListing
|
|
|
|
|
2019-01-14 01:27:48 +00:00
|
|
|
|
2019-04-13 00:39:25 +00:00
|
|
|
class MarketList(GeoffreyModelList):
|
2019-04-10 23:04:20 +00:00
|
|
|
model = Market
|
|
|
|
|
|
|
|
|
2019-04-13 00:39:25 +00:00
|
|
|
class PointOfInterestList(GeoffreyModelList):
|
|
|
|
model = PointOfInterest
|
2019-04-10 23:04:20 +00:00
|
|
|
|
2019-05-12 16:23:59 +00:00
|
|
|
class AttractionList(GeoffreyModelList):
|
|
|
|
model = Attraction
|
|
|
|
|
2019-01-14 01:27:48 +00:00
|
|
|
|
2019-04-13 00:39:25 +00:00
|
|
|
class ModelInfoView(View):
|
|
|
|
template = None
|
|
|
|
|
|
|
|
def get_context(self, id):
|
|
|
|
return None
|
2019-01-14 01:27:48 +00:00
|
|
|
|
|
|
|
def get(self, request, id):
|
|
|
|
try:
|
2019-04-13 01:04:13 +00:00
|
|
|
return render(request, 'GeoffreyApp/%s' % self.template, context=self.get_context(id))
|
2019-01-14 01:27:48 +00:00
|
|
|
except Player.DoesNotExist:
|
|
|
|
return render(request, 'GeoffreyApp/error.html')
|
|
|
|
|
|
|
|
|
2019-04-13 00:39:25 +00:00
|
|
|
class PlayerInfo(ModelInfoView):
|
|
|
|
template = 'player.html'
|
2019-01-14 01:27:48 +00:00
|
|
|
|
2019-04-13 00:39:25 +00:00
|
|
|
def get_context(self, id):
|
|
|
|
player = Player.objects.get(pk=id)
|
|
|
|
loc_list = Location.objects.filter(owner=player).all()
|
2019-02-06 20:54:50 +00:00
|
|
|
|
2019-04-13 00:39:25 +00:00
|
|
|
context = {
|
|
|
|
"player": player,
|
|
|
|
"loc_list": loc_list
|
|
|
|
}
|
2019-02-06 20:54:50 +00:00
|
|
|
|
2019-04-13 00:39:25 +00:00
|
|
|
return context
|
2019-02-06 20:54:50 +00:00
|
|
|
|
|
|
|
|
2019-04-13 00:39:25 +00:00
|
|
|
class ShopInfo(ModelInfoView):
|
|
|
|
template = 'shop.html'
|
2019-03-02 17:48:28 +00:00
|
|
|
|
2019-04-13 00:39:25 +00:00
|
|
|
def get_context(self, id):
|
|
|
|
shop = Shop.objects.get(pk=id)
|
|
|
|
inventory = ItemListing.objects.filter(shop=shop).all()
|
2019-03-02 17:48:28 +00:00
|
|
|
|
2019-04-13 00:39:25 +00:00
|
|
|
context = {
|
|
|
|
"loc": shop,
|
|
|
|
"inventory": inventory
|
|
|
|
}
|
2019-03-02 17:48:28 +00:00
|
|
|
|
2019-04-13 00:39:25 +00:00
|
|
|
return context
|
2019-03-02 17:48:28 +00:00
|
|
|
|
2019-04-10 23:04:20 +00:00
|
|
|
|
2019-04-13 00:39:25 +00:00
|
|
|
class BaseInfo(ModelInfoView):
|
|
|
|
template = "location.html"
|
2019-04-10 23:04:20 +00:00
|
|
|
|
2019-04-13 00:39:25 +00:00
|
|
|
def get_context(self, id):
|
|
|
|
base = Base.objects.get(pk=id)
|
2019-04-10 23:04:20 +00:00
|
|
|
|
2019-04-13 00:39:25 +00:00
|
|
|
context = {
|
|
|
|
"loc": base,
|
|
|
|
}
|
2019-04-10 23:04:20 +00:00
|
|
|
|
2019-04-13 00:39:25 +00:00
|
|
|
return context
|
|
|
|
|
|
|
|
|
|
|
|
class TownInfo(ModelInfoView):
|
|
|
|
template = "town.html"
|
|
|
|
|
|
|
|
def get_context(self, id):
|
|
|
|
town = Town.objects.get(pk=id)
|
|
|
|
|
|
|
|
residents = town.residents.all()
|
|
|
|
|
|
|
|
context = {
|
|
|
|
"loc": town,
|
|
|
|
"residents": residents
|
|
|
|
}
|
|
|
|
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
|
|
|
class PublicFarmInfo(ModelInfoView):
|
|
|
|
template = "publicfarm.html"
|
|
|
|
|
|
|
|
def get_context(self, id):
|
|
|
|
public_farm = PublicFarm.objects.get(pk=id)
|
|
|
|
|
|
|
|
resources = public_farm.resource.all()
|
|
|
|
|
|
|
|
context = {
|
|
|
|
"loc": public_farm,
|
|
|
|
"resources": resources
|
|
|
|
}
|
|
|
|
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
|
|
|
class MarketInfo(ModelInfoView):
|
|
|
|
template = "market.html"
|
|
|
|
|
|
|
|
def get_context(self, id):
|
|
|
|
market = Market.objects.get(pk=id)
|
|
|
|
|
|
|
|
shops = market.get_shops(limit=100)
|
|
|
|
|
|
|
|
context = {
|
|
|
|
"loc": market,
|
|
|
|
"shops": shops
|
|
|
|
}
|
|
|
|
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
|
|
|
class PointOfInterestInfo(ModelInfoView):
|
|
|
|
template = "location.html"
|
|
|
|
|
|
|
|
def get_context(self, id):
|
|
|
|
point_of_interest = PointOfInterest.objects.get(pk=id)
|
|
|
|
|
|
|
|
context = {
|
|
|
|
"loc": point_of_interest,
|
|
|
|
}
|
|
|
|
|
|
|
|
return context
|
2019-05-12 16:23:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AttractionInfo(ModelInfoView):
|
|
|
|
template = "location.html"
|
|
|
|
|
|
|
|
def get_context(self, id):
|
|
|
|
attraction = Attraction.objects.get(pk=id)
|
|
|
|
|
|
|
|
context = {
|
|
|
|
"loc": attraction
|
|
|
|
}
|
|
|
|
|
|
|
|
return context
|