Incredibly basic first pass of a website for Geoffrey

+ Added an index page with a dynamic count
+ Added a List page for each model
+ Selling command improvements
doc_update
Joey Hines 2018-12-13 19:58:59 -06:00
parent bfa34b3d2c
commit efe12b5b21
11 changed files with 177 additions and 13 deletions

View File

@ -151,15 +151,23 @@ def selling(item_name):
items = []
if len(item_name) == 0:
raise EmptryString
query = ItemListing.objects.filter(item_name__icontains=item_name).values()
#items = ItemListing.objects.annotate(normalized_price=F('price') / F('amount'))\
# .filter(item_name__icontains=item_name).order_by('normalized_price')
if len(query) == 0:
shops = ItemListing.objects.annotate(normalized_price=F('price') / F('amount'))\
.filter(item_name__icontains=item_name).order_by('normalized_price').values('shop_id').distinct()
if len(shops) == 0:
raise ItemNotFound
for item in query:
items.append(item)
for shop_id in shops:
shop = Shop.objects.get(pk=shop_id['shop_id']).json
item_query = ItemListing.objects.annotate(normalized_price=F('price') / F('amount')).\
filter(item_name__icontains=item_name).order_by('normalized_price').all()
item_list = []
for item in item_query:
item_list.append(item)
shop["items"] = item_list
items.append(shop)
return items

View File

@ -14,6 +14,9 @@ class Player(models.Model):
def json(self):
return {"Name": self.name, "MC UUID": self.mc_uuid, "Discord UUID": self.discord_uuid}
def __str__(self):
return self.name
class Location(models.Model):
DIMENSIONS = (

View File

@ -0,0 +1,5 @@
.sidebar-nav {
margin-top: 20px;
padding: 0;
list-style: none;
}

View File

@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
{% block title %}<title>GeoffreyApp</title>{% endblock %}
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<!-- Add additional CSS in static file -->
{% load static %}
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
</head>
<body>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-sm-2">
{% block sidebar %}
<ul class="sidebar-nav">
<li><a href="{% url 'GeoffreyHome' %}">Home</a></li>
<li><a href="{% url 'GeoffreyPlayers' %}">Players</a></li>
<li><a href="{% url 'GeoffreyBases' %}">Bases</a></li>
<li><a href="{% url 'GeoffreyShops' %}">Shops</a></li>
<li><a href="{% url 'GeoffreyItems' %}">Items</a></li>
</ul>
{% endblock %}
</div>
<div class="col-sm-10 ">{% block content %}{% endblock %}</div>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,17 @@
{% 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 %}
{% endblock %}

View File

@ -0,0 +1,13 @@
{% extends "GeoffreyApp/base.html" %}
{% block content %}
<h1>Geoffrey Minecraft Database Home</h1>
<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>
{% endblock %}

View File

@ -0,0 +1,17 @@
{% extends "GeoffreyApp/base.html" %}
{% block content %}
<h1>Items</h1>
{% 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 %}
{% endblock %}

View File

@ -0,0 +1,17 @@
{% extends "GeoffreyApp/base.html" %}
{% block content %}
<h1>Players</h1>
{% 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 %}
{% endblock %}

View File

@ -0,0 +1,17 @@
{% 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 %}
{% endblock %}

View File

@ -1,7 +1,11 @@
from django.urls import path
from django.conf.urls import url
from . import views
urlpatterns = [
path('', views.index, name='index'),
url(r'^home$', views.Home.as_view(), name='GeoffreyHome'),
url(r'^player$', views.PlayerList.as_view(), name='GeoffreyPlayers'),
url(r'^shops$', views.ShopList.as_view(), name='GeoffreyShops'),
url(r'^bases$', views.BaseList.as_view(), name='GeoffreyBases'),
url(r'^items$', views.ItemListingList.as_view(), name='GeoffreyItems'),
]

View File

@ -1,9 +1,39 @@
from django.shortcuts import render
from django.http import HttpResponse
import subprocess, os
from django.views.generic import View
from GeoffreyApp.models import *
from django.views import generic
# Create your views here.
def index(request):
return HttpResponse("Geoffrey is here!")
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()
context = {
"num_players": player_num,
"num_bases": base_num,
"num_shops": shop_num,
"num_items": item_num,
}
return render(request, 'GeoffreyApp/home.html', context=context)
class PlayerList(generic.ListView):
model = Player
class ShopList(generic.ListView):
model = Shop
class BaseList(generic.ListView):
model = Base
class ItemListingList(generic.ListView):
model = ItemListing