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
+
doc_update
Joey Hines 2019-01-13 19:27:48 -06:00
parent c57a570e97
commit 118b578b06
18 changed files with 211 additions and 150 deletions

View File

@ -92,7 +92,7 @@ class Location(models.Model):
@property @property
def location(self): def location(self):
return "(x={}, z={}".format(self.x_coord, self.z_coord) return "(x={}, z={})".format(self.x_coord, self.z_coord)
@property @property
def json(self): def json(self):
@ -104,6 +104,26 @@ class Location(models.Model):
"owner": self.owner.json "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): def __str__(self):
return self.name return self.name
@ -161,7 +181,6 @@ class ItemListing(models.Model):
"shop": self.shop.json, "shop": self.shop.json,
} }
def __str__(self): def __str__(self):
return "Item: %d %s for %d" % (self.amount, self.item_name, self.amount) return "Item: %d %s for %d" % (self.amount, self.item_name, self.amount)

View File

@ -5,7 +5,7 @@
<head> <head>
<link rel="shortcut icon" type="image/png" href="{% static 'GeoffreyApp/img/icon.png' %}"/> <link rel="shortcut icon" type="image/png" href="{% static 'GeoffreyApp/img/icon.png' %}"/>
<meta charset="UTF-8"> <meta charset="UTF-8">
{% block title %}<title>GeoffreyApp</title>{% endblock %} {% block title %}<title>Geoffrey</title>{% endblock %}
{% load static %} {% load static %}
<link rel="stylesheet" href="{% static 'GeoffreyApp/css/bootstrap.css' %}"> <link rel="stylesheet" href="{% static 'GeoffreyApp/css/bootstrap.css' %}">
@ -29,7 +29,7 @@
</head> </head>
<body> <body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark"> <nav class="navbar navbar-expand-lg navbar-dark bg-dark sticky-top">
<a href="#" class="navbar-left"><img src="{% static 'GeoffreyApp/img/icon.png' %}" height="30px" alt="sed"></a> <a href="#" class="navbar-left"><img src="{% static 'GeoffreyApp/img/icon.png' %}" height="30px" alt="sed"></a>
<a class="navbar-brand" href="#">Geoffrey</a> <a class="navbar-brand" href="#">Geoffrey</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar" <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar"

View File

@ -5,28 +5,5 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<table id="geoffrey_table" class="table table-hover link-table"> {% include "GeoffreyApp/location_table.html" with loc_list=base_list %}
<thead class="bg-dark">
<tr>
<th>Base Name</th>
<th>Location</th>
<th>Owner</th>
</tr>
</thead>
<tbody>
{% for base in base_list %}
<tr>
<td>{{ base.name }} </td>
<td>{{ base.location }}</td>
<td>{{ base.owner }} </td>
</tr>
{% endfor %}
</tbody>
</table>
<script>
$(document).ready(function () {
$('#geoffrey_table').DataTable();
});
</script>
{% endblock %} {% endblock %}

View File

@ -0,0 +1,9 @@
{% extends "GeoffreyApp/base.html" %}
{% block header %}
OwO
{% endblock %}
{% block content %}
<p>Oppsie woopsie, someone made a fucky wucky. Was probably you...</p>
{% endblock %}

View File

@ -5,33 +5,6 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<table id="geoffrey_table" class="table table-hover link-table"> {% include "GeoffreyApp/itemlisting_table.html" with show_shop=True %}
<thead class="bg-dark">
<tr>
<th>Item Name</th>
<th>Amount</th>
<th>Price</th>
<th>Price Per Item</th>
<th>Shop</th>
</tr>
</thead>
<tbody>
{% for item in itemlisting_list %}
<tr>
<td>{{ item.item_name }} </td>
<td>{{ item.amount }}</td>
<td>{{ item.price }}D</td>
<td>{{ item.normalized_price }}D</td>
<td>{{ item.shop.name }} @ {{ item.shop.location }} </td>
</tr>
{% endfor %}
</tbody>
</table>
<script>
$(document).ready(function () {
$('#geoffrey_table').DataTable();
});
</script>
{% endblock %} {% endblock %}

View File

@ -0,0 +1,34 @@
<table id="itemlisting_table" class="table table-hover link-table">
<thead class="bg-dark">
<tr>
<th>Item Name</th>
<th>Amount</th>
<th>Price</th>
<th>Price Per Item</th>
{% if show_shop %}
<th>Shop Location</th>
<th>Shop</th>
{% endif %}
</tr>
</thead>
<tbody>
{% for item in itemlisting_list %}
<tr>
<td>{{ item.item_name }} </td>
<td>{{ item.amount }}</td>
<td>{{ item.price }}D</td>
<td>{{ item.normalized_price }}D</td>
{% if show_shop %}
<td>{{ item.shop.location }}</td>
<td>{% include "GeoffreyApp/location_link.html" with loc=item.shop %}</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
<script>
$(document).ready(function () {
$('#itemlisting_table').DataTable();
});
</script>

View File

@ -0,0 +1,15 @@
{% extends "GeoffreyApp/base.html" %}
{% block header %}
{{ loc.name }}
{% endblock %}
{% block content %}
<p>Owner: {{ loc.owner }}</p>
<p>Location: {{ loc.location }}</p>
<hr class="my-4">
{% block info %}{% endblock %}
<iframe src="{{ loc.dynmap_url }}" width="100%" height="500">
Your browser does not support iframes.
</iframe>
{% endblock %}

View File

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

View File

@ -0,0 +1,30 @@
<h2>Locations</h2>
<table id="loc_table" class="table table-hover link-table">
<thead class="bg-dark">
<tr>
<th>Location Name</th>
<th>Coordinates</th>
{% if show_owner %}
<th>Owner</th>
{% endif %}
</tr>
</thead>
<tbody>
{% for loc in loc_list %}
<tr>
<td>{% include "GeoffreyApp/location_link.html" with loc=loc %}</td>
<td>{{ loc.location }}</td>
{% if show_owner %}
<td>{% include "GeoffreyApp/player_link.html" with player=loc.owner %}</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
<script>
$(document).ready(function () {
$('#loc_table').DataTable();
});
</script>

View File

@ -0,0 +1,8 @@
{% extends "GeoffreyApp/base.html" %}
{% block header %}
{{ player.name }}
{% endblock %}
{% block content %}
{% include "GeoffreyApp/location_table.html" with loc_list=loc_list %}
{% endblock %}

View File

@ -0,0 +1 @@
<a href="{% url 'GeoffreyPlayerInfo' player.id %}">{{ player.name }}</a>

View File

@ -5,25 +5,5 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<table id="geoffrey_table" class="table table-hover link-table"> {% include "GeoffreyApp/player_table.html" %}
<thead class="bg-dark">
<tr>
<th>Player Username</th>
<th># of Locations</th>
</tr>
</thead>
<tbody>
{% for player in player_list %}
<tr>
<td>{{ player.name }} </td>
<td>{{ player.loc_count }} </td>
</tr>
{% endfor %}
</tbody>
</table>
<script>
$(document).ready(function () {
$('#geoffrey_table').DataTable();
});
</script>
{% endblock %} {% endblock %}

View File

@ -0,0 +1,21 @@
<table id="player_table" class="table table-hover link-table">
<thead class="bg-dark">
<tr>
<th>Player Username</th>
<th># of Locations</th>
</tr>
</thead>
<tbody>
{% for player in player_list %}
<tr>
<td>{% include "GeoffreyApp/player_link.html" %}</td>
<td>{{ player.loc_count }} </td>
</tr>
{% endfor %}
</tbody>
</table>
<script>
$(document).ready(function () {
$('#player_table').DataTable();
});
</script>

View File

@ -6,51 +6,10 @@
{% block content %} {% block content %}
<h2>Players</h2> <h2>Players</h2>
<table id="player_table" class="table table-hover link-table"> {% include "GeoffreyApp/player_table.html" %}
<thead class="bg-dark">
<tr>
<th>Player Username</th>
<th># of Locations</th>
</tr>
</thead>
<tbody>
{% for player in player_list %}
<tr>
<td>{{ player.name }} </td>
<td>{{ player.loc_count }} </td>
</tr>
{% endfor %}
</tbody>
</table>
<hr class="my-4"> <hr class="my-4">
<h2>Locations</h2> {% include "GeoffreyApp/location_table.html" with show_owner=True %}
<table id="loc_table" class="table table-hover link-table">
<thead class="bg-dark">
<tr>
<th>Location Name</th>
<th>Coordinates</th>
<th>Owner</th>
</tr>
</thead>
<tbody>
{% for loc in loc_list %}
<tr>
<td>{{ loc.name }} </td>
<td>{{ loc.location }}</td>
<td>{{ loc.owner }} </td>
</tr>
{% endfor %}
</tbody>
</table>
<script>
$(document).ready(function () {
$('#player_table').DataTable();
$('#loc_table').DataTable();
});
</script>
{% endblock %} {% endblock %}

View File

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

View File

@ -5,29 +5,6 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<table id="geoffrey_table" class="table table-hover link-table"> {% include "GeoffreyApp/location_table.html" with loc_list=shop_list show_owner=True %}
<thead class="bg-dark">
<tr>
<th>Shop Name</th>
<th>Location</th>
<th>Owner</th>
</tr>
</thead>
<tbody>
{% for shop in shop_list %}
<tr>
<td>{{ shop.name }} </td>
<td>{{ shop.location }}</td>
<td>{{ shop.owner }} </td>
</tr>
{% endfor %}
</tbody>
</table>
<script>
$(document).ready(function () {
$('#geoffrey_table').DataTable();
});
</script>
{% endblock %} {% endblock %}

15
urls.py
View File

@ -2,11 +2,14 @@ from django.conf.urls import url
from . import views from . import views
urlpatterns = [ urlpatterns = [
url(r'^home$', views.Home.as_view(), name='GeoffreyHome'), url(r'^home/$', views.Home.as_view(), name='GeoffreyHome'),
url(r'^player$', views.PlayerList.as_view(), name='GeoffreyPlayers'), url(r'^player/$', views.PlayerList.as_view(), name='GeoffreyPlayers'),
url(r'^shops$', views.ShopList.as_view(), name='GeoffreyShops'), url(r'^player/(?P<id>[0-9]{1,9})/$', views.PlayerInfo.as_view(), name='GeoffreyPlayerInfo'),
url(r'^bases$', views.BaseList.as_view(), name='GeoffreyBases'), url(r'^shops/$', views.ShopList.as_view(), name='GeoffreyShops'),
url(r'^items$', views.ItemListingList.as_view(), name='GeoffreyItems'), url(r'^shops/(?P<id>[0-9]{1,9})/$', views.ShopInfo.as_view(), name='GeoffreyShopInfo'),
url(r'^search$', views.SearchList.as_view(), name='GeoffreySearch'), 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'^items/$', views.ItemListingList.as_view(), name='GeoffreyItems'),
url(r'^search/$', views.SearchList.as_view(), name='GeoffreySearch'),
] ]

View File

@ -79,3 +79,46 @@ class ItemListingList(generic.ListView):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['current_page'] = "Item Listings" context['current_page'] = "Item Listings"
return context return context
class PlayerInfo(View):
def get(self, request, id):
try:
player = Player.objects.get(pk=id)
loc_list = Location.objects.filter(owner=player).all()
context = {
"player": player,
"loc_list": loc_list
}
return render(request, 'GeoffreyApp/player.html', context=context)
except Player.DoesNotExist:
return render(request, 'GeoffreyApp/error.html')
class ShopInfo(View):
def get(self, request, id):
try:
shop = Shop.objects.get(pk=id)
inventory = ItemListing.objects.filter(shop=shop).all()
context = {
"loc": shop,
"inventory": inventory
}
return render(request, 'GeoffreyApp/shop.html', context=context)
except Player.DoesNotExist:
return render(request, 'GeoffreyApp/error.html')
class BaseInfo(View):
def get(self, request, id):
try:
base = Base.objects.get(pk=id)
context = {
"loc": base,
}
return render(request, 'GeoffreyApp/location.html', context=context)
except Player.DoesNotExist:
return render(request, 'GeoffreyApp/error.html')