From 118b578b06a35eb571fb18f12a7912bed22105a3 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sun, 13 Jan 2019 19:27:48 -0600 Subject: [PATCH] Template clean up and added views for individual locations and players +Moved each type of table into its own template so its less repeated +Players, Bases and Shops now have their own views +Added a loc_type property to location to get the object type +Added dynmap_url to location to get the dynmap url + --- models.py | 23 +++++++++- templates/GeoffreyApp/base.html | 4 +- templates/GeoffreyApp/base_list.html | 25 +---------- templates/GeoffreyApp/error.html | 9 ++++ templates/GeoffreyApp/itemlisting_list.html | 29 +------------ templates/GeoffreyApp/itemlisting_table.html | 34 +++++++++++++++ templates/GeoffreyApp/location.html | 15 +++++++ templates/GeoffreyApp/location_link.html | 5 +++ templates/GeoffreyApp/location_table.html | 30 +++++++++++++ templates/GeoffreyApp/player.html | 8 ++++ templates/GeoffreyApp/player_link.html | 1 + templates/GeoffreyApp/player_list.html | 22 +--------- templates/GeoffreyApp/player_table.html | 21 +++++++++ templates/GeoffreyApp/search.html | 45 +------------------- templates/GeoffreyApp/shop.html | 7 +++ templates/GeoffreyApp/shop_list.html | 25 +---------- urls.py | 15 ++++--- views.py | 43 +++++++++++++++++++ 18 files changed, 211 insertions(+), 150 deletions(-) create mode 100644 templates/GeoffreyApp/error.html create mode 100644 templates/GeoffreyApp/itemlisting_table.html create mode 100644 templates/GeoffreyApp/location.html create mode 100644 templates/GeoffreyApp/location_link.html create mode 100644 templates/GeoffreyApp/location_table.html create mode 100644 templates/GeoffreyApp/player.html create mode 100644 templates/GeoffreyApp/player_link.html create mode 100644 templates/GeoffreyApp/player_table.html create mode 100644 templates/GeoffreyApp/shop.html diff --git a/models.py b/models.py index 0cd7da1..8596c8b 100644 --- a/models.py +++ b/models.py @@ -92,7 +92,7 @@ class Location(models.Model): @property def location(self): - return "(x={}, z={}".format(self.x_coord, self.z_coord) + return "(x={}, z={})".format(self.x_coord, self.z_coord) @property def json(self): @@ -104,6 +104,26 @@ class Location(models.Model): "owner": self.owner.json } + @property + def loc_type(self): + if hasattr(self, "shop"): + return "shop" + elif hasattr(self, "base"): + return "base" + else: + return "location" + + @property + def dynmap_url(self): + base_url = getattr(settings, "GEOFFREY_DYNMAP_BASE_URL") + world_name = getattr(settings, "GEOFFREY_DYNMAP_WORLD_NAME") + if base_url is not None: + url = base_url + "/?worldname={}&mapname=surface&zoom=4&x={}&y=65&z={}".format(world_name, self.x_coord, + self.z_coord) + return url + else: + return None + def __str__(self): return self.name @@ -161,7 +181,6 @@ class ItemListing(models.Model): "shop": self.shop.json, } - def __str__(self): return "Item: %d %s for %d" % (self.amount, self.item_name, self.amount) diff --git a/templates/GeoffreyApp/base.html b/templates/GeoffreyApp/base.html index 9f44fd4..4d8a9ca 100644 --- a/templates/GeoffreyApp/base.html +++ b/templates/GeoffreyApp/base.html @@ -5,7 +5,7 @@ - {% block title %}GeoffreyApp{% endblock %} + {% block title %}Geoffrey{% endblock %} {% load static %} @@ -29,7 +29,7 @@ -