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(Resource)
|
||||
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):
|
||||
info_page = None
|
||||
|
||||
"""Model of a Location"""
|
||||
|
||||
info_page = None
|
||||
"""
|
||||
Name of the info page view
|
||||
"""
|
||||
|
||||
DIMENSIONS = (
|
||||
('O', 'Overworld'),
|
||||
('N', 'Nether'),
|
||||
|
@ -238,6 +241,10 @@ class Location(models.Model):
|
|||
return "%s: %s" % (self.loc_child_obj.__class__.__name__, self.name)
|
||||
|
||||
|
||||
class PointOfInterest(Location):
|
||||
info_page = "GeoffreyPointOfInterest"
|
||||
|
||||
|
||||
class Shop(Location):
|
||||
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.urls import reverse
|
||||
from GeoffreyApp.models import Player, Shop, Base, Town, ItemListing, PublicFarm, Market, PointOfInterest
|
||||
|
||||
register = template.Library()
|
||||
|
||||
navbar_options = [
|
||||
("Home", reverse("GeoffreyHome")),
|
||||
("Players", reverse("GeoffreyPlayers")),
|
||||
("Shops", reverse("GeoffreyShops")),
|
||||
("Bases", reverse("GeoffreyBases")),
|
||||
("Towns", reverse("GeoffreyTowns")),
|
||||
("Item Listings", reverse("GeoffreyItems")),
|
||||
("Public Farms", reverse("GeoffreyPublicFarms")),
|
||||
("Markets", reverse("GeoffreyMarkets"))
|
||||
]
|
||||
navbar_options = {
|
||||
"Home": ["Home", reverse("GeoffreyHome")],
|
||||
"Player": ["Players", reverse("GeoffreyPlayers")],
|
||||
"Shop": ["Shops", reverse("GeoffreyShops")],
|
||||
"Base": ["Bases", reverse("GeoffreyBases")],
|
||||
"Town": ["Towns", reverse("GeoffreyTowns")],
|
||||
"ItemListing": ["Item Listings", reverse("GeoffreyItems")],
|
||||
"PublicFarm": ["Public Farms", reverse("GeoffreyPublicFarms")],
|
||||
"Market": ["Markets", reverse("GeoffreyMarkets")],
|
||||
"PointOfInterest": ["Points of Interest", reverse("GeoffreyPointOfInterest")]
|
||||
}
|
||||
|
||||
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):
|
||||
navbar = ""
|
||||
|
||||
for option in navbar_options:
|
||||
if page == option[0]:
|
||||
for option in navbar_options.keys():
|
||||
if page == option:
|
||||
active = ' active'
|
||||
else:
|
||||
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
|
||||
|
|
5
urls.py
5
urls.py
|
@ -16,6 +16,9 @@ urlpatterns = [
|
|||
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'^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)
|
||||
|
||||
|
||||
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
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['current_page'] = "Players"
|
||||
return context
|
||||
|
||||
|
||||
class ShopList(generic.ListView):
|
||||
class ShopList(GeoffreyModelList):
|
||||
model = Shop
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['current_page'] = "Shops"
|
||||
return context
|
||||
|
||||
def get_queryset(self):
|
||||
qs = Shop.objects.all()
|
||||
|
||||
|
@ -63,54 +63,47 @@ class ShopList(generic.ListView):
|
|||
return qs
|
||||
|
||||
|
||||
class BaseList(generic.ListView):
|
||||
class BaseList(GeoffreyModelList):
|
||||
model = Base
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['current_page'] = "Bases"
|
||||
return context
|
||||
|
||||
|
||||
class TownList(generic.ListView):
|
||||
class TownList(GeoffreyModelList):
|
||||
model = Town
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['current_page'] = "Towns"
|
||||
return context
|
||||
|
||||
|
||||
class PublicFarmList(generic.ListView):
|
||||
class PublicFarmList(GeoffreyModelList):
|
||||
model = PublicFarm
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['current_page'] = "Public Farms"
|
||||
return context
|
||||
|
||||
|
||||
class ItemListingList(generic.ListView):
|
||||
class ItemListingList(GeoffreyModelList):
|
||||
model = ItemListing
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['current_page'] = "Item Listings"
|
||||
return context
|
||||
|
||||
|
||||
class MarketList(generic.ListView):
|
||||
class MarketList(GeoffreyModelList):
|
||||
model = Market
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['current_page'] = "Market"
|
||||
return context
|
||||
|
||||
class PointOfInterestList(GeoffreyModelList):
|
||||
model = PointOfInterest
|
||||
|
||||
|
||||
class PlayerInfo(View):
|
||||
class ModelInfoView(View):
|
||||
template = None
|
||||
|
||||
def get_context(self, id):
|
||||
return None
|
||||
|
||||
def get(self, request, id):
|
||||
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)
|
||||
loc_list = Location.objects.filter(owner=player).all()
|
||||
|
||||
|
@ -118,14 +111,14 @@ class PlayerInfo(View):
|
|||
"player": player,
|
||||
"loc_list": loc_list
|
||||
}
|
||||
return render(request, 'GeoffreyApp/player.html', context=context)
|
||||
except Player.DoesNotExist:
|
||||
return render(request, 'GeoffreyApp/error.html')
|
||||
|
||||
return context
|
||||
|
||||
|
||||
class ShopInfo(View):
|
||||
def get(self, request, id):
|
||||
try:
|
||||
class ShopInfo(ModelInfoView):
|
||||
template = 'shop.html'
|
||||
|
||||
def get_context(self, id):
|
||||
shop = Shop.objects.get(pk=id)
|
||||
inventory = ItemListing.objects.filter(shop=shop).all()
|
||||
|
||||
|
@ -133,27 +126,27 @@ class ShopInfo(View):
|
|||
"loc": shop,
|
||||
"inventory": inventory
|
||||
}
|
||||
return render(request, 'GeoffreyApp/shop.html', context=context)
|
||||
except Player.DoesNotExist:
|
||||
return render(request, 'GeoffreyApp/error.html')
|
||||
|
||||
return context
|
||||
|
||||
|
||||
class BaseInfo(View):
|
||||
def get(self, request, id):
|
||||
try:
|
||||
class BaseInfo(ModelInfoView):
|
||||
template = "location.html"
|
||||
|
||||
def get_context(self, id):
|
||||
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')
|
||||
|
||||
return context
|
||||
|
||||
|
||||
class TownInfo(View):
|
||||
def get(self, request, id):
|
||||
try:
|
||||
class TownInfo(ModelInfoView):
|
||||
template = "town.html"
|
||||
|
||||
def get_context(self, id):
|
||||
town = Town.objects.get(pk=id)
|
||||
|
||||
residents = town.residents.all()
|
||||
|
@ -162,14 +155,14 @@ class TownInfo(View):
|
|||
"loc": town,
|
||||
"residents": residents
|
||||
}
|
||||
return render(request, 'GeoffreyApp/town.html', context=context)
|
||||
except Player.DoesNotExist:
|
||||
return render(request, 'GeoffreyApp/error.html')
|
||||
|
||||
return context
|
||||
|
||||
|
||||
class PublicFarmInfo(View):
|
||||
def get(self, request, id):
|
||||
try:
|
||||
class PublicFarmInfo(ModelInfoView):
|
||||
template = "publicfarm.html"
|
||||
|
||||
def get_context(self, id):
|
||||
public_farm = PublicFarm.objects.get(pk=id)
|
||||
|
||||
resources = public_farm.resource.all()
|
||||
|
@ -178,14 +171,14 @@ class PublicFarmInfo(View):
|
|||
"loc": public_farm,
|
||||
"resources": resources
|
||||
}
|
||||
return render(request, 'GeoffreyApp/publicfarm.html', context=context)
|
||||
except Player.DoesNotExist:
|
||||
return render(request, 'GeoffreyApp/error.html')
|
||||
|
||||
return context
|
||||
|
||||
|
||||
class MarketInfo(View):
|
||||
def get(self, request, id):
|
||||
try:
|
||||
class MarketInfo(ModelInfoView):
|
||||
template = "market.html"
|
||||
|
||||
def get_context(self, id):
|
||||
market = Market.objects.get(pk=id)
|
||||
|
||||
shops = market.get_shops(limit=100)
|
||||
|
@ -194,6 +187,18 @@ class MarketInfo(View):
|
|||
"loc": market,
|
||||
"shops": shops
|
||||
}
|
||||
return render(request, 'GeoffreyApp/market.html', context=context)
|
||||
except Player.DoesNotExist:
|
||||
return render(request, 'GeoffreyApp/error.html')
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue