From 0fc805444f87bdbe69815f32a03a36b4b8645e43 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Wed, 10 Apr 2019 18:04:20 -0500 Subject: [PATCH] Added markets + Shops are automatically added to markets with a certain radius + Tunnels now displayed on Location pages + Add migration for market + Updated navbar --- admin.py | 1 + migrations/0009_market.py | 22 ++++++++++++ models.py | 47 ++++++++++++++++++++------ templates/GeoffreyApp/base.html | 3 +- templates/GeoffreyApp/location.html | 4 +++ templates/GeoffreyApp/market.html | 7 ++++ templates/GeoffreyApp/market_list.html | 9 +++++ templates/GeoffreyApp/publicfarm.html | 2 +- templates/GeoffreyApp/shop.html | 2 +- templates/GeoffreyApp/town.html | 4 +-- templatetags/navbar.py | 3 +- urls.py | 6 ++-- views.py | 25 ++++++++++++++ 13 files changed, 115 insertions(+), 20 deletions(-) create mode 100644 migrations/0009_market.py create mode 100644 templates/GeoffreyApp/market.html create mode 100644 templates/GeoffreyApp/market_list.html diff --git a/admin.py b/admin.py index 8e61638..f5905ee 100644 --- a/admin.py +++ b/admin.py @@ -11,3 +11,4 @@ admin.site.register(APIToken) admin.site.register(Town) admin.site.register(PublicFarm) admin.site.register(Resource) +admin.site.register(Market) diff --git a/migrations/0009_market.py b/migrations/0009_market.py new file mode 100644 index 0000000..f0b757f --- /dev/null +++ b/migrations/0009_market.py @@ -0,0 +1,22 @@ +# Generated by Django 2.1.2 on 2019-04-10 22:53 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + dependencies = [ + ('GeoffreyApp', '0008_publicfarm_resource'), + ] + + operations = [ + migrations.CreateModel( + name='Market', + fields=[ + ('location_ptr', + models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, + primary_key=True, serialize=False, to='GeoffreyApp.Location')), + ], + bases=('GeoffreyApp.location',), + ), + ] diff --git a/models.py b/models.py index 17e6f34..8d07dec 100644 --- a/models.py +++ b/models.py @@ -214,6 +214,8 @@ class Location(models.Model): return self.town elif hasattr(self, "publicfarm"): return self.publicfarm + elif hasattr(self, "market"): + return self.market else: return self @@ -233,22 +235,16 @@ class Location(models.Model): return None def __str__(self): - return self.name + return "%s: %s" % (self.loc_child_obj.__class__.__name__, self.name) class Shop(Location): info_page = "GeoffreyShopInfo" - def __str__(self): - return "Shop: %s" % self.name - class Base(Location): info_page = "GeoffreyBaseInfo" - def __str__(self): - return "Base: %s" % self.name - class Town(Location): info_page = "GeoffreyTownInfo" @@ -258,9 +254,6 @@ class Town(Location): Players who are members of the town """ - def __str__(self): - return "Town: %s" % self.name - @property def get_residents(self): """ @@ -286,7 +279,7 @@ class Town(Location): "dimension": "O", "owner": [], "tunnel": {}, - "link": "/GeoffreyApp/Base/1", + "link": "/GeoffreyApp/Town/1", "residents": [] } """ @@ -301,6 +294,38 @@ class Town(Location): class Market(Location): info_page = "GeoffreyMarketInfo" + def get_shops(self, market_radius=100, limit=10): + shops = Shop.objects.filter(x_coord__range=(self.x_coord - market_radius, self.x_coord + market_radius), + z_coord__range=(self.z_coord - market_radius, self.z_coord + market_radius) + )[:limit] + + return shops + + @property + def json(self): + """ + JSON representation of the market + .. code-block:: json + + { + "type": "Town", + "name": "Location", + "x_coord": 0, + "z_coord": 0, + "dimension": "O", + "owner": [], + "tunnel": {}, + "link": "/GeoffreyApp/Market/1", + "shops": [] + } + """ + + json = super().json + + json["shops"] = objects_list_to_json(self.get_shops(limit=10)) + + return json + class PublicFarm(Location): info_page = "GeoffreyPublicFarmInfo" diff --git a/templates/GeoffreyApp/base.html b/templates/GeoffreyApp/base.html index 123875f..4739216 100644 --- a/templates/GeoffreyApp/base.html +++ b/templates/GeoffreyApp/base.html @@ -23,8 +23,7 @@ - + diff --git a/templates/GeoffreyApp/location.html b/templates/GeoffreyApp/location.html index 87df13a..c3c6e2f 100644 --- a/templates/GeoffreyApp/location.html +++ b/templates/GeoffreyApp/location.html @@ -18,6 +18,10 @@ {% endif %}

Location: {{ loc.position }}

+ + {% if loc.tunnel %} +

Tunnel: {{ loc.tunnel.get_tunnel_direction_display }} {{ loc.tunnel.tunnel_number }}

+ {% endif %}
{% block info %}{% endblock %}