Added points of interest

+ Streamlined adding new model info and list pages
+ Updated navbar
doc_update
Joey Hines 2019-04-12 19:39:25 -05:00
parent 0fc805444f
commit a47ea55fd6
6 changed files with 153 additions and 126 deletions

View File

@ -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)

View File

@ -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"

View File

@ -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 %}

View File

@ -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

View File

@ -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'),
] ]

225
views.py
View File

@ -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,137 +63,142 @@ 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
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()
context = {
"player": player,
"loc_list": loc_list
}
return context return context
class PlayerInfo(View): class ShopInfo(ModelInfoView):
def get(self, request, id): template = 'shop.html'
try:
player = Player.objects.get(pk=id)
loc_list = Location.objects.filter(owner=player).all()
context = { def get_context(self, id):
"player": player, shop = Shop.objects.get(pk=id)
"loc_list": loc_list inventory = ItemListing.objects.filter(shop=shop).all()
}
return render(request, 'GeoffreyApp/player.html', context=context) context = {
except Player.DoesNotExist: "loc": shop,
return render(request, 'GeoffreyApp/error.html') "inventory": inventory
}
return context
class ShopInfo(View): class BaseInfo(ModelInfoView):
def get(self, request, id): template = "location.html"
try:
shop = Shop.objects.get(pk=id)
inventory = ItemListing.objects.filter(shop=shop).all()
context = { def get_context(self, id):
"loc": shop, base = Base.objects.get(pk=id)
"inventory": inventory
} context = {
return render(request, 'GeoffreyApp/shop.html', context=context) "loc": base,
except Player.DoesNotExist: }
return render(request, 'GeoffreyApp/error.html')
return context
class BaseInfo(View): class TownInfo(ModelInfoView):
def get(self, request, id): template = "town.html"
try:
base = Base.objects.get(pk=id)
context = { def get_context(self, id):
"loc": base, town = Town.objects.get(pk=id)
}
return render(request, 'GeoffreyApp/location.html', context=context) residents = town.residents.all()
except Player.DoesNotExist:
return render(request, 'GeoffreyApp/error.html') context = {
"loc": town,
"residents": residents
}
return context
class TownInfo(View): class PublicFarmInfo(ModelInfoView):
def get(self, request, id): template = "publicfarm.html"
try:
town = Town.objects.get(pk=id)
residents = town.residents.all() def get_context(self, id):
public_farm = PublicFarm.objects.get(pk=id)
context = { resources = public_farm.resource.all()
"loc": town,
"residents": residents context = {
} "loc": public_farm,
return render(request, 'GeoffreyApp/town.html', context=context) "resources": resources
except Player.DoesNotExist: }
return render(request, 'GeoffreyApp/error.html')
return context
class PublicFarmInfo(View): class MarketInfo(ModelInfoView):
def get(self, request, id): template = "market.html"
try:
public_farm = PublicFarm.objects.get(pk=id)
resources = public_farm.resource.all() def get_context(self, id):
market = Market.objects.get(pk=id)
context = { shops = market.get_shops(limit=100)
"loc": public_farm,
"resources": resources context = {
} "loc": market,
return render(request, 'GeoffreyApp/publicfarm.html', context=context) "shops": shops
except Player.DoesNotExist: }
return render(request, 'GeoffreyApp/error.html')
return context
class MarketInfo(View): class PointOfInterestInfo(ModelInfoView):
def get(self, request, id): template = "location.html"
try:
market = Market.objects.get(pk=id)
shops = market.get_shops(limit=100) def get_context(self, id):
point_of_interest = PointOfInterest.objects.get(pk=id)
context = { context = {
"loc": market, "loc": point_of_interest,
"shops": shops }
}
return render(request, 'GeoffreyApp/market.html', context=context) return context
except Player.DoesNotExist:
return render(request, 'GeoffreyApp/error.html')