Added markets
+ Shops are automatically added to markets with a certain radius + Tunnels now displayed on Location pages + Add migration for market + Updated navbardoc_update
parent
03f4080bbe
commit
0fc805444f
1
admin.py
1
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)
|
||||
|
|
|
@ -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',),
|
||||
),
|
||||
]
|
47
models.py
47
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"
|
||||
|
|
|
@ -23,8 +23,7 @@
|
|||
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css">
|
||||
|
||||
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
|
||||
<script type="text/javascript" language="javascript"
|
||||
src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js"></script>
|
||||
<script type="text/javascript" src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js"></script>
|
||||
|
||||
<link href="{% static 'GeoffreyApp/css/geoffrey.css' %}" rel="stylesheet">
|
||||
|
||||
|
|
|
@ -18,6 +18,10 @@
|
|||
|
||||
{% endif %}
|
||||
<p>Location: {{ loc.position }}</p>
|
||||
|
||||
{% if loc.tunnel %}
|
||||
<p>Tunnel: {{ loc.tunnel.get_tunnel_direction_display }} {{ loc.tunnel.tunnel_number }}</p>
|
||||
{% endif %}
|
||||
<hr class="my-4">
|
||||
{% block info %}{% endblock %}
|
||||
<iframe src="{{ loc.dynmap_url }}" width="100%" height="500">
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
{% extends "GeoffreyApp/location.html" %}
|
||||
|
||||
{% block info %}
|
||||
<h2>Shops</h2>
|
||||
{% include "GeoffreyApp/location_table.html" with loc_list=shops %}
|
||||
<hr class="my-4">
|
||||
{% endblock %}
|
|
@ -0,0 +1,9 @@
|
|||
{% extends "GeoffreyApp/base.html" %}
|
||||
|
||||
{% block header %}
|
||||
Markets
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% include "GeoffreyApp/location_table.html" with loc_list=market_list show_owner=True %}
|
||||
{% endblock %}
|
|
@ -1,7 +1,7 @@
|
|||
{% extends "GeoffreyApp/location.html" %}
|
||||
|
||||
{% block info %}
|
||||
<h2>Resources:</h2>
|
||||
<h2>Resources</h2>
|
||||
{% include "GeoffreyApp/resource_table.html" with resource_list=resources %}
|
||||
<hr class="my-4">
|
||||
{% endblock %}
|
|
@ -1,7 +1,7 @@
|
|||
{% extends "GeoffreyApp/location.html" %}
|
||||
|
||||
{% block info %}
|
||||
<h2>Inventory:</h2>
|
||||
<h2>Inventory</h2>
|
||||
{% include "GeoffreyApp/itemlisting_table.html" with itemlisting_list=inventory %}
|
||||
<hr class="my-4">
|
||||
{% endblock %}
|
|
@ -1,7 +1,7 @@
|
|||
{% extends "GeoffreyApp/location.html" %}
|
||||
|
||||
{% block info %}
|
||||
<h2>Residents:</h2>
|
||||
{% include "GeoffreyApp/player_table.html" with itemlisting_list=residents %}
|
||||
<h2>Residents</h2>
|
||||
{% include "GeoffreyApp/player_table.html" with player_list=residents %}
|
||||
<hr class="my-4">
|
||||
{% endblock %}
|
|
@ -10,7 +10,8 @@ navbar_options = [
|
|||
("Bases", reverse("GeoffreyBases")),
|
||||
("Towns", reverse("GeoffreyTowns")),
|
||||
("Item Listings", reverse("GeoffreyItems")),
|
||||
("Public Farms", reverse("GeoffreyPublicFarms"))
|
||||
("Public Farms", reverse("GeoffreyPublicFarms")),
|
||||
("Markets", reverse("GeoffreyMarkets"))
|
||||
]
|
||||
|
||||
option_format = '<li class="nav-item{}"> <a class="nav-link" href="{}">{} </a> </li>'
|
||||
|
|
6
urls.py
6
urls.py
|
@ -13,7 +13,9 @@ urlpatterns = [
|
|||
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'),
|
||||
url(r'^farm/$', views.PublicFarmList.as_view(), name='GeoffreyPublicFarms'),
|
||||
url(r'^farm/(?P<id>[0-9]{1,9})/$', views.PublicFarmInfo.as_view(), name='GeoffreyPublicFarmInfo')
|
||||
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')
|
||||
]
|
||||
|
||||
|
|
25
views.py
25
views.py
|
@ -99,6 +99,15 @@ class ItemListingList(generic.ListView):
|
|||
return context
|
||||
|
||||
|
||||
class MarketList(generic.ListView):
|
||||
model = Market
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['current_page'] = "Market"
|
||||
return context
|
||||
|
||||
|
||||
class PlayerInfo(View):
|
||||
def get(self, request, id):
|
||||
try:
|
||||
|
@ -172,3 +181,19 @@ class PublicFarmInfo(View):
|
|||
return render(request, 'GeoffreyApp/publicfarm.html', context=context)
|
||||
except Player.DoesNotExist:
|
||||
return render(request, 'GeoffreyApp/error.html')
|
||||
|
||||
|
||||
class MarketInfo(View):
|
||||
def get(self, request, id):
|
||||
try:
|
||||
market = Market.objects.get(pk=id)
|
||||
|
||||
shops = market.get_shops(limit=100)
|
||||
|
||||
context = {
|
||||
"loc": market,
|
||||
"shops": shops
|
||||
}
|
||||
return render(request, 'GeoffreyApp/market.html', context=context)
|
||||
except Player.DoesNotExist:
|
||||
return render(request, 'GeoffreyApp/error.html')
|
||||
|
|
Loading…
Reference in New Issue