Added a way to get the child object from a location object

+ get_loc_child returns the Town, Base, Shop... object
+ link gets the url for the location
+ the info command now returns the child object instead of the Location
object
+ Added Town navbar
doc_update
Joey Hines 2019-02-06 14:54:50 -06:00
parent a668ade97d
commit b88bfbda43
9 changed files with 84 additions and 11 deletions

View File

@ -44,7 +44,7 @@ def parse_help(func):
return match.group(0).partition(":help: ")[-1]
except:
return ''
return ' '
def get_player(discord_uuid=None, mc_uuid=None):
@ -348,7 +348,7 @@ def info(location_name):
location = Location.objects.filter(name__iregex=".*{}.*".format(location_name)).first()
if location is not None:
return location.json
return location.loc_child_obj.json
else:
raise LocationLookUpError
@ -602,6 +602,7 @@ def remove_resident(resident_name, town_name, discord_uuid=None, mc_uuid=None):
:param mc_uuid: Owner mc uuid
:raises: PlayerNotFound, LocationLookupError, IsResidentError, ResidentNotFoundError
:return: Updated town
:help: Removes a resident from a town
'''
owner = get_player(discord_uuid, mc_uuid)

View File

@ -1,5 +1,6 @@
from django.db import models
from django.conf import settings
from django.urls import reverse
from sys import maxsize
from GeoffreyApp.util import create_token, objects_list_to_json
@ -111,6 +112,10 @@ class Location(models.Model):
return owner_list
@property
def link(self):
return ""
@property
def json(self):
return {"type": self.__class__.__name__,
@ -120,19 +125,30 @@ class Location(models.Model):
"dimension": self.dimension,
"owner": self.get_owners,
"location": self.location,
"tunnel": None if self.tunnel is None else self.tunnel.tunnel_str
"tunnel": None if self.tunnel is None else self.tunnel.tunnel_str,
"link": self.link
}
@property
def loc_type(self):
str = self.loc_child_obj.__class__.__name__
return str
@property
def link(self):
return self.loc_child_obj.link()
@property
def loc_child_obj(self):
if hasattr(self, "shop"):
return "shop"
return self.shop
elif hasattr(self, "base"):
return "base"
return self.base
elif hasattr(self, "town"):
return "town"
return self.town
else:
return "location"
return self
@property
def dynmap_url(self):
@ -153,11 +169,19 @@ class Shop(Location):
def __str__(self):
return "Shop: %s" % self.name
@property
def link(self):
return reverse("GeoffreyShopInfo", kwargs={"id": self.id})
class Base(Location):
def __str__(self):
return "Base: %s" % self.name
@property
def link(self):
return reverse("GeoffreyBaseInfo", kwargs={"id": self.id})
class Town(Location):
residents = models.ManyToManyField(Player)
@ -175,10 +199,14 @@ class Town(Location):
def json(self):
json = super().json
json["residents"] = self.residents
json["residents"] = self.get_residents
return json
@property
def link(self):
return reverse("GeoffreyTownInfo", kwargs={"id": self.id})
class ItemListing(models.Model):
item_name = models.CharField(max_length=128)

View File

@ -1,5 +1,5 @@
{% if loc.loc_type == "base" %}
{% if loc.loc_type == "Base" %}
<a href="{% url 'GeoffreyBaseInfo' loc.id %}">{{ loc.name }}</a>
{% elif loc.loc_type == "shop" %}
{% elif loc.loc_type == "Shop" %}
<a href="{% url 'GeoffreyShopInfo' loc.id %}">{{ loc.name }}</a>
{% endif %}

View File

@ -12,7 +12,7 @@
<tbody>
{% for loc in loc_list %}
<tr>
<td>{% include "GeoffreyApp/location_link.html" with loc=loc %}</td>
<td><a href="{{ loc.link }}">{{ loc.name }}</a></td>
<td>{{ loc.location }}</td>
{% if show_owner %}
<td>

View File

@ -0,0 +1,7 @@
{% extends "GeoffreyApp/location.html" %}
{% block info %}
<h2>Residents:</h2>
{% include "GeoffreyApp/player_table.html" with itemlisting_list=residents %}
<hr class="my-4">
{% endblock %}

View File

@ -0,0 +1,9 @@
{% extends "GeoffreyApp/base.html" %}
{% block header %}
Towns
{% endblock %}
{% block content %}
{% include "GeoffreyApp/location_table.html" with loc_list=town_list show_owner=True %}
{% endblock %}

View File

@ -8,6 +8,7 @@ navbar_options = [
("Players", reverse("GeoffreyPlayers")),
("Shops", reverse("GeoffreyShops")),
("Bases", reverse("GeoffreyBases")),
("Towns", reverse("GeoffreyTowns")),
("Item Listings", reverse("GeoffreyItems"))
]

View File

@ -9,6 +9,8 @@ urlpatterns = [
url(r'^shops/(?P<id>[0-9]{1,9})/$', views.ShopInfo.as_view(), name='GeoffreyShopInfo'),
url(r'^bases/$', views.BaseList.as_view(), name='GeoffreyBases'),
url(r'^bases/(?P<id>[0-9]{1,9})/$', views.BaseInfo.as_view(), name='GeoffreyBaseInfo'),
url(r'^towns/$', views.TownList.as_view(), name='GeoffreyTowns'),
url(r'^towns/(?P<id>[0-9]{1,9})/$', views.TownInfo.as_view(), name='GeoffreyTownInfo'),
url(r'^items/$', views.ItemListingList.as_view(), name='GeoffreyItems'),
url(r'^search/$', views.SearchList.as_view(), name='GeoffreySearch'),
]

View File

@ -72,6 +72,15 @@ class BaseList(generic.ListView):
return context
class TownList(generic.ListView):
model = Town
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['current_page'] = "Towns"
return context
class ItemListingList(generic.ListView):
model = ItemListing
@ -122,3 +131,19 @@ class BaseInfo(View):
return render(request, 'GeoffreyApp/location.html', context=context)
except Player.DoesNotExist:
return render(request, 'GeoffreyApp/error.html')
class TownInfo(View):
def get(self, request, id):
try:
town = Town.objects.get(pk=id)
residents = town.residents.all()
context = {
"loc": town,
"residents": residents
}
return render(request, 'GeoffreyApp/town.html', context=context)
except Player.DoesNotExist:
return render(request, 'GeoffreyApp/error.html')