Added points of interest
+ Streamlined adding new model info and list pages + Updated navbardoc_update
parent
0fc805444f
commit
a47ea55fd6
1
admin.py
1
admin.py
|
@ -12,3 +12,4 @@ admin.site.register(Town)
|
||||||
admin.site.register(PublicFarm)
|
admin.site.register(PublicFarm)
|
||||||
admin.site.register(Resource)
|
admin.site.register(Resource)
|
||||||
admin.site.register(Market)
|
admin.site.register(Market)
|
||||||
|
admin.site.register(PointOfInterest)
|
||||||
|
|
11
models.py
11
models.py
|
@ -83,10 +83,13 @@ class Player(models.Model):
|
||||||
|
|
||||||
|
|
||||||
class Location(models.Model):
|
class Location(models.Model):
|
||||||
info_page = None
|
|
||||||
|
|
||||||
"""Model of a Location"""
|
"""Model of a Location"""
|
||||||
|
|
||||||
|
info_page = None
|
||||||
|
"""
|
||||||
|
Name of the info page view
|
||||||
|
"""
|
||||||
|
|
||||||
DIMENSIONS = (
|
DIMENSIONS = (
|
||||||
('O', 'Overworld'),
|
('O', 'Overworld'),
|
||||||
('N', 'Nether'),
|
('N', 'Nether'),
|
||||||
|
@ -238,6 +241,10 @@ class Location(models.Model):
|
||||||
return "%s: %s" % (self.loc_child_obj.__class__.__name__, self.name)
|
return "%s: %s" % (self.loc_child_obj.__class__.__name__, self.name)
|
||||||
|
|
||||||
|
|
||||||
|
class PointOfInterest(Location):
|
||||||
|
info_page = "GeoffreyPointOfInterest"
|
||||||
|
|
||||||
|
|
||||||
class Shop(Location):
|
class Shop(Location):
|
||||||
info_page = "GeoffreyShopInfo"
|
info_page = "GeoffreyShopInfo"
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
{% extends "GeoffreyApp/base.html" %}
|
||||||
|
|
||||||
|
{% block header %}
|
||||||
|
Bases
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{% include "GeoffreyApp/location_table.html" with loc_list=pointofinterest_list show_owner=True %}
|
||||||
|
{% endblock %}
|
|
@ -1,18 +1,20 @@
|
||||||
from django import template
|
from django import template
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
from GeoffreyApp.models import Player, Shop, Base, Town, ItemListing, PublicFarm, Market, PointOfInterest
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
navbar_options = [
|
navbar_options = {
|
||||||
("Home", reverse("GeoffreyHome")),
|
"Home": ["Home", reverse("GeoffreyHome")],
|
||||||
("Players", reverse("GeoffreyPlayers")),
|
"Player": ["Players", reverse("GeoffreyPlayers")],
|
||||||
("Shops", reverse("GeoffreyShops")),
|
"Shop": ["Shops", reverse("GeoffreyShops")],
|
||||||
("Bases", reverse("GeoffreyBases")),
|
"Base": ["Bases", reverse("GeoffreyBases")],
|
||||||
("Towns", reverse("GeoffreyTowns")),
|
"Town": ["Towns", reverse("GeoffreyTowns")],
|
||||||
("Item Listings", reverse("GeoffreyItems")),
|
"ItemListing": ["Item Listings", reverse("GeoffreyItems")],
|
||||||
("Public Farms", reverse("GeoffreyPublicFarms")),
|
"PublicFarm": ["Public Farms", reverse("GeoffreyPublicFarms")],
|
||||||
("Markets", reverse("GeoffreyMarkets"))
|
"Market": ["Markets", reverse("GeoffreyMarkets")],
|
||||||
]
|
"PointOfInterest": ["Points of Interest", reverse("GeoffreyPointOfInterest")]
|
||||||
|
}
|
||||||
|
|
||||||
option_format = '<li class="nav-item{}"> <a class="nav-link" href="{}">{} </a> </li>'
|
option_format = '<li class="nav-item{}"> <a class="nav-link" href="{}">{} </a> </li>'
|
||||||
|
|
||||||
|
@ -21,12 +23,12 @@ option_format = '<li class="nav-item{}"> <a class="nav-link" href="{}">{} </a> <
|
||||||
def get_navbar(page):
|
def get_navbar(page):
|
||||||
navbar = ""
|
navbar = ""
|
||||||
|
|
||||||
for option in navbar_options:
|
for option in navbar_options.keys():
|
||||||
if page == option[0]:
|
if page == option:
|
||||||
active = ' active'
|
active = ' active'
|
||||||
else:
|
else:
|
||||||
active = ''
|
active = ''
|
||||||
|
|
||||||
navbar += option_format.format(active, option[1], option[0])
|
navbar += option_format.format(active, navbar_options[option][1], navbar_options[option][0])
|
||||||
|
|
||||||
return navbar
|
return navbar
|
||||||
|
|
5
urls.py
5
urls.py
|
@ -16,6 +16,9 @@ urlpatterns = [
|
||||||
url(r'^farms/$', views.PublicFarmList.as_view(), name='GeoffreyPublicFarms'),
|
url(r'^farms/$', views.PublicFarmList.as_view(), name='GeoffreyPublicFarms'),
|
||||||
url(r'^farms/(?P<id>[0-9]{1,9})/$', views.PublicFarmInfo.as_view(), name='GeoffreyPublicFarmInfo'),
|
url(r'^farms/(?P<id>[0-9]{1,9})/$', views.PublicFarmInfo.as_view(), name='GeoffreyPublicFarmInfo'),
|
||||||
url(r'^markets/$', views.MarketList.as_view(), name='GeoffreyMarkets'),
|
url(r'^markets/$', views.MarketList.as_view(), name='GeoffreyMarkets'),
|
||||||
url(r'^markets/(?P<id>[0-9]{1,9})/$', views.MarketInfo.as_view(), name='GeoffreyMarketInfo')
|
url(r'^markets/(?P<id>[0-9]{1,9})/$', views.MarketInfo.as_view(), name='GeoffreyMarketInfo'),
|
||||||
|
url(r'^pointofinterest/$', views.PointOfInterestList.as_view(), name='GeoffreyPointOfInterest'),
|
||||||
|
url(r'^pointofinterest/(?P<id>[0-9]{1,9})/$', views.PointOfInterestInfo.as_view(),
|
||||||
|
name='GeoffreyPointOfInterestInfo'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
155
views.py
155
views.py
|
@ -36,23 +36,23 @@ class SearchList(View):
|
||||||
return render(request, 'GeoffreyApp/search.html', context=context)
|
return render(request, 'GeoffreyApp/search.html', context=context)
|
||||||
|
|
||||||
|
|
||||||
class PlayerList(generic.ListView):
|
class GeoffreyModelList(generic.ListView):
|
||||||
|
model = None
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
|
context['current_page'] = self.model.__name__
|
||||||
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
class PlayerList(GeoffreyModelList):
|
||||||
model = Player
|
model = Player
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
|
||||||
context = super().get_context_data(**kwargs)
|
|
||||||
context['current_page'] = "Players"
|
|
||||||
return context
|
|
||||||
|
|
||||||
|
class ShopList(GeoffreyModelList):
|
||||||
class ShopList(generic.ListView):
|
|
||||||
model = Shop
|
model = Shop
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
|
||||||
context = super().get_context_data(**kwargs)
|
|
||||||
context['current_page'] = "Shops"
|
|
||||||
return context
|
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
qs = Shop.objects.all()
|
qs = Shop.objects.all()
|
||||||
|
|
||||||
|
@ -63,54 +63,47 @@ class ShopList(generic.ListView):
|
||||||
return qs
|
return qs
|
||||||
|
|
||||||
|
|
||||||
class BaseList(generic.ListView):
|
class BaseList(GeoffreyModelList):
|
||||||
model = Base
|
model = Base
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
|
||||||
context = super().get_context_data(**kwargs)
|
|
||||||
context['current_page'] = "Bases"
|
|
||||||
return context
|
|
||||||
|
|
||||||
|
class TownList(GeoffreyModelList):
|
||||||
class TownList(generic.ListView):
|
|
||||||
model = Town
|
model = Town
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
|
||||||
context = super().get_context_data(**kwargs)
|
|
||||||
context['current_page'] = "Towns"
|
|
||||||
return context
|
|
||||||
|
|
||||||
|
class PublicFarmList(GeoffreyModelList):
|
||||||
class PublicFarmList(generic.ListView):
|
|
||||||
model = PublicFarm
|
model = PublicFarm
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
|
||||||
context = super().get_context_data(**kwargs)
|
|
||||||
context['current_page'] = "Public Farms"
|
|
||||||
return context
|
|
||||||
|
|
||||||
|
class ItemListingList(GeoffreyModelList):
|
||||||
class ItemListingList(generic.ListView):
|
|
||||||
model = ItemListing
|
model = ItemListing
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
|
||||||
context = super().get_context_data(**kwargs)
|
|
||||||
context['current_page'] = "Item Listings"
|
|
||||||
return context
|
|
||||||
|
|
||||||
|
class MarketList(GeoffreyModelList):
|
||||||
class MarketList(generic.ListView):
|
|
||||||
model = Market
|
model = Market
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
|
||||||
context = super().get_context_data(**kwargs)
|
class PointOfInterestList(GeoffreyModelList):
|
||||||
context['current_page'] = "Market"
|
model = PointOfInterest
|
||||||
return context
|
|
||||||
|
|
||||||
|
|
||||||
class PlayerInfo(View):
|
class ModelInfoView(View):
|
||||||
|
template = None
|
||||||
|
|
||||||
|
def get_context(self, id):
|
||||||
|
return None
|
||||||
|
|
||||||
def get(self, request, id):
|
def get(self, request, id):
|
||||||
try:
|
try:
|
||||||
|
return render(request, 'GeoffreyApp/%s' % self.template, context=self.context(id))
|
||||||
|
except Player.DoesNotExist:
|
||||||
|
return render(request, 'GeoffreyApp/error.html')
|
||||||
|
|
||||||
|
|
||||||
|
class PlayerInfo(ModelInfoView):
|
||||||
|
template = 'player.html'
|
||||||
|
|
||||||
|
def get_context(self, id):
|
||||||
player = Player.objects.get(pk=id)
|
player = Player.objects.get(pk=id)
|
||||||
loc_list = Location.objects.filter(owner=player).all()
|
loc_list = Location.objects.filter(owner=player).all()
|
||||||
|
|
||||||
|
@ -118,14 +111,14 @@ class PlayerInfo(View):
|
||||||
"player": player,
|
"player": player,
|
||||||
"loc_list": loc_list
|
"loc_list": loc_list
|
||||||
}
|
}
|
||||||
return render(request, 'GeoffreyApp/player.html', context=context)
|
|
||||||
except Player.DoesNotExist:
|
return context
|
||||||
return render(request, 'GeoffreyApp/error.html')
|
|
||||||
|
|
||||||
|
|
||||||
class ShopInfo(View):
|
class ShopInfo(ModelInfoView):
|
||||||
def get(self, request, id):
|
template = 'shop.html'
|
||||||
try:
|
|
||||||
|
def get_context(self, id):
|
||||||
shop = Shop.objects.get(pk=id)
|
shop = Shop.objects.get(pk=id)
|
||||||
inventory = ItemListing.objects.filter(shop=shop).all()
|
inventory = ItemListing.objects.filter(shop=shop).all()
|
||||||
|
|
||||||
|
@ -133,27 +126,27 @@ class ShopInfo(View):
|
||||||
"loc": shop,
|
"loc": shop,
|
||||||
"inventory": inventory
|
"inventory": inventory
|
||||||
}
|
}
|
||||||
return render(request, 'GeoffreyApp/shop.html', context=context)
|
|
||||||
except Player.DoesNotExist:
|
return context
|
||||||
return render(request, 'GeoffreyApp/error.html')
|
|
||||||
|
|
||||||
|
|
||||||
class BaseInfo(View):
|
class BaseInfo(ModelInfoView):
|
||||||
def get(self, request, id):
|
template = "location.html"
|
||||||
try:
|
|
||||||
|
def get_context(self, id):
|
||||||
base = Base.objects.get(pk=id)
|
base = Base.objects.get(pk=id)
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
"loc": base,
|
"loc": base,
|
||||||
}
|
}
|
||||||
return render(request, 'GeoffreyApp/location.html', context=context)
|
|
||||||
except Player.DoesNotExist:
|
return context
|
||||||
return render(request, 'GeoffreyApp/error.html')
|
|
||||||
|
|
||||||
|
|
||||||
class TownInfo(View):
|
class TownInfo(ModelInfoView):
|
||||||
def get(self, request, id):
|
template = "town.html"
|
||||||
try:
|
|
||||||
|
def get_context(self, id):
|
||||||
town = Town.objects.get(pk=id)
|
town = Town.objects.get(pk=id)
|
||||||
|
|
||||||
residents = town.residents.all()
|
residents = town.residents.all()
|
||||||
|
@ -162,14 +155,14 @@ class TownInfo(View):
|
||||||
"loc": town,
|
"loc": town,
|
||||||
"residents": residents
|
"residents": residents
|
||||||
}
|
}
|
||||||
return render(request, 'GeoffreyApp/town.html', context=context)
|
|
||||||
except Player.DoesNotExist:
|
return context
|
||||||
return render(request, 'GeoffreyApp/error.html')
|
|
||||||
|
|
||||||
|
|
||||||
class PublicFarmInfo(View):
|
class PublicFarmInfo(ModelInfoView):
|
||||||
def get(self, request, id):
|
template = "publicfarm.html"
|
||||||
try:
|
|
||||||
|
def get_context(self, id):
|
||||||
public_farm = PublicFarm.objects.get(pk=id)
|
public_farm = PublicFarm.objects.get(pk=id)
|
||||||
|
|
||||||
resources = public_farm.resource.all()
|
resources = public_farm.resource.all()
|
||||||
|
@ -178,14 +171,14 @@ class PublicFarmInfo(View):
|
||||||
"loc": public_farm,
|
"loc": public_farm,
|
||||||
"resources": resources
|
"resources": resources
|
||||||
}
|
}
|
||||||
return render(request, 'GeoffreyApp/publicfarm.html', context=context)
|
|
||||||
except Player.DoesNotExist:
|
return context
|
||||||
return render(request, 'GeoffreyApp/error.html')
|
|
||||||
|
|
||||||
|
|
||||||
class MarketInfo(View):
|
class MarketInfo(ModelInfoView):
|
||||||
def get(self, request, id):
|
template = "market.html"
|
||||||
try:
|
|
||||||
|
def get_context(self, id):
|
||||||
market = Market.objects.get(pk=id)
|
market = Market.objects.get(pk=id)
|
||||||
|
|
||||||
shops = market.get_shops(limit=100)
|
shops = market.get_shops(limit=100)
|
||||||
|
@ -194,6 +187,18 @@ class MarketInfo(View):
|
||||||
"loc": market,
|
"loc": market,
|
||||||
"shops": shops
|
"shops": shops
|
||||||
}
|
}
|
||||||
return render(request, 'GeoffreyApp/market.html', context=context)
|
|
||||||
except Player.DoesNotExist:
|
return context
|
||||||
return render(request, 'GeoffreyApp/error.html')
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
Loading…
Reference in New Issue