Holy datatables batman
+ Converted all the lists to nice datatables + Added location property to Location for displaying the position + Added a location count property to Playersdoc_update
parent
9f3a60d3c0
commit
c57a570e97
|
@ -46,6 +46,10 @@ class Player(models.Model):
|
|||
Discord UUID
|
||||
'''
|
||||
|
||||
@property
|
||||
def loc_count(self):
|
||||
return Location.objects.filter(owner=self).count()
|
||||
|
||||
@property
|
||||
def json(self):
|
||||
return {"name": self.name,
|
||||
|
@ -86,6 +90,10 @@ class Location(models.Model):
|
|||
Owner of Location
|
||||
'''
|
||||
|
||||
@property
|
||||
def location(self):
|
||||
return "(x={}, z={}".format(self.x_coord, self.z_coord)
|
||||
|
||||
@property
|
||||
def json(self):
|
||||
return {"type": self.__class__.__name__,
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
<meta charset="UTF-8">
|
||||
{% block title %}<title>GeoffreyApp</title>{% endblock %}
|
||||
|
||||
{% load static %}
|
||||
<link rel="stylesheet" href="{% static 'GeoffreyApp/css/bootstrap.css' %}">
|
||||
|
||||
<!-- jQuery library -->
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
||||
|
||||
|
@ -15,8 +18,14 @@
|
|||
|
||||
<!-- Latest compiled JavaScript -->
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
|
||||
{% load static %}
|
||||
<link rel="stylesheet" href="{% static 'GeoffreyApp/css/bootstrap.css' %}">
|
||||
|
||||
<!-- Datatables -->
|
||||
<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>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
@ -32,15 +41,17 @@
|
|||
<ul class="navbar-nav mr-auto">
|
||||
{% autoescape off %}{% get_navbar current_page|safe %}{% endautoescape %}
|
||||
</ul>
|
||||
|
||||
<form class="form-inline my-2 my-lg-0" id="searchform" action="{% url 'GeoffreySearch' %}">
|
||||
<input class="form-control mr-sm-2" name="search" type="text" placeholder="Search">
|
||||
<input class="form-control mr-sm-2" name="search" type="text" placeholder="Find a Location...">
|
||||
<button class="btn btn-secondary my-2 my-sm-0" type="submit">Search</button>
|
||||
{% block search %}{% endblock %}
|
||||
</form>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="container-fluid">
|
||||
<div class="container">
|
||||
<h1>{% block header %}{% endblock %}</h1>
|
||||
{% block content %}{% endblock %}
|
||||
</div>
|
||||
</body>
|
||||
|
|
|
@ -1,17 +1,32 @@
|
|||
{% extends "GeoffreyApp/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Bases</h1>
|
||||
{% if base_list %}
|
||||
<ul>
|
||||
{% for base in base_list %}
|
||||
<li>
|
||||
{{ base.name }} {{ base.owner }} {{ base.x_coord }} {{ base.z_coord }}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<p>There are no bases in the database :pepethonk:</p>
|
||||
{% endif %}
|
||||
|
||||
{% block header %}
|
||||
Bases
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<table id="geoffrey_table" class="table table-hover link-table">
|
||||
<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 %}
|
||||
|
|
|
@ -1,13 +1,32 @@
|
|||
{% extends "GeoffreyApp/base.html" %}
|
||||
|
||||
{% block header %}
|
||||
Geoffrey
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2>Geoffrey Minecraft Database Home</h2>
|
||||
<h3>About</h3>
|
||||
<p>Geoffrey is a database for storing information on Players, Bases, Shops, Towns, and more! </p>
|
||||
<p>Current Database Count:</p>
|
||||
<ul>
|
||||
<li><strong>Players:</strong> {{ num_players }}</li>
|
||||
<li><strong>Shops:</strong> {{ num_shops }}</li>
|
||||
<li><strong>Items for Sale:</strong> {{ num_items }}</li>
|
||||
<li><strong>Bases:</strong> {{ num_bases }}</li>
|
||||
</ul>
|
||||
|
||||
<h3>Current Database Counts</h3>
|
||||
|
||||
<table class="table table-hover link-table">
|
||||
<thead class="bg-dark">
|
||||
<tr>
|
||||
<th>Type</th>
|
||||
<th>Count</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for stat in stat_list %}
|
||||
<tr>
|
||||
<td>{{ stat.0 }}</td>
|
||||
<td>{{ stat.1 }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
{% endblock %}
|
|
@ -1,16 +1,37 @@
|
|||
{% extends "GeoffreyApp/base.html" %}
|
||||
|
||||
{% block header %}
|
||||
Item Listings
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% if itemlisting_list %}
|
||||
<ul>
|
||||
{% for item in itemlisting_list %}
|
||||
<li>
|
||||
{{ item.item_name}} {{ item.amount }} for {{ item.price }}D
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<p>There are no items for sale in the database :pepethonk:</p>
|
||||
{% endif %}
|
||||
<table id="geoffrey_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>
|
||||
<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 %}
|
||||
|
|
|
@ -1,17 +1,29 @@
|
|||
{% extends "GeoffreyApp/base.html" %}
|
||||
|
||||
{% block header %}
|
||||
Players
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% if player_list %}
|
||||
<ul>
|
||||
{% for player in player_list %}
|
||||
<li>
|
||||
{{ player.name }}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<p>There are no players in the database :pepethonk:</p>
|
||||
{% endif %}
|
||||
|
||||
<table id="geoffrey_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>{{ player.name }} </td>
|
||||
<td>{{ player.loc_count }} </td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$('#geoffrey_table').DataTable();
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
|
@ -1,42 +1,56 @@
|
|||
{% extends "GeoffreyApp/base.html" %}
|
||||
|
||||
{% block header %}
|
||||
Search results for {{ search }}...
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h4>Search results for {{ search }}...</h4>
|
||||
<h2>Players</h2>
|
||||
<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>{{ player.name }} </td>
|
||||
<td>{{ player.loc_count }} </td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{% if player_list %}
|
||||
<h6>Players</h6>
|
||||
<ul>
|
||||
{% for player in player_list %}
|
||||
<li>
|
||||
{{ player.name }}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
{% endif %}
|
||||
<hr class="my-4">
|
||||
|
||||
{% if base_list %}
|
||||
<h6>Bases</h6>
|
||||
<ul>
|
||||
{% for base in base_list %}
|
||||
<li>
|
||||
{{ base.name }}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
{% endif %}
|
||||
<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>
|
||||
<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 %}
|
||||
|
||||
{% if shop_list %}
|
||||
<h6>Shops</h6>
|
||||
<ul>
|
||||
{% for shop in shop_list %}
|
||||
<li>
|
||||
{{ shop.name }}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
{% endif %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$('#player_table').DataTable();
|
||||
$('#loc_table').DataTable();
|
||||
});
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
|
@ -1,18 +1,33 @@
|
|||
{% extends "GeoffreyApp/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Shops</h1>
|
||||
|
||||
{% if shop_list %}
|
||||
<ul>
|
||||
{% for shop in shop_list %}
|
||||
<li>
|
||||
{{ shop.name }} {{ shop.owner }} {{ shop.x_coord }} {{ shop.z_coord }}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<p>There are no shops in the database :pepethonk:</p>
|
||||
{% endif %}
|
||||
|
||||
{% block header %}
|
||||
Shops
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<table id="geoffrey_table" class="table table-hover link-table">
|
||||
<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 %}
|
||||
|
||||
|
|
19
views.py
19
views.py
|
@ -9,17 +9,14 @@ from django.db.models import Q
|
|||
class Home(View):
|
||||
|
||||
def get(self, request):
|
||||
|
||||
base_num = Base.objects.count()
|
||||
shop_num = Shop.objects.count()
|
||||
player_num = Player.objects.count()
|
||||
item_num = ItemListing.objects.count()
|
||||
stats = []
|
||||
stats.append(("Players", Player.objects.count()))
|
||||
stats.append(("Bases", Base.objects.count()))
|
||||
stats.append(("Shops", Shop.objects.count()))
|
||||
stats.append(("Items for Sale", Player.objects.count()))
|
||||
|
||||
context = {
|
||||
"num_players": player_num,
|
||||
"num_bases": base_num,
|
||||
"num_shops": shop_num,
|
||||
"num_items": item_num,
|
||||
"stat_list": stats,
|
||||
"current_page": "Home",
|
||||
}
|
||||
|
||||
|
@ -34,9 +31,7 @@ class SearchList(View):
|
|||
|
||||
context["player_list"] = Player.objects.filter(Q(name__icontains=query)).all()
|
||||
|
||||
context["base_list"] = Base.objects.filter(Q(name__icontains=query) | Q(owner__name__icontains=query)).all()
|
||||
|
||||
context["shop_list"] = Shop.objects.filter(Q(name__icontains=query) | Q(owner__name__icontains=query)).all()
|
||||
context["loc_list"] = Location.objects.filter(Q(name__icontains=query) | Q(owner__name__icontains=query)).all()
|
||||
|
||||
return render(request, 'GeoffreyApp/search.html', context=context)
|
||||
|
||||
|
|
Loading…
Reference in New Issue