diff --git a/api/commands.py b/api/commands.py index 9ff7e8d..43da6e4 100644 --- a/api/commands.py +++ b/api/commands.py @@ -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 diff --git a/models.py b/models.py index 26ac7e6..53f0435 100644 --- a/models.py +++ b/models.py @@ -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 = ( diff --git a/static/css/style.css b/static/css/style.css new file mode 100644 index 0000000..d7009ee --- /dev/null +++ b/static/css/style.css @@ -0,0 +1,5 @@ +.sidebar-nav { + margin-top: 20px; + padding: 0; + list-style: none; +} \ No newline at end of file diff --git a/templates/GeoffreyApp/base.html b/templates/GeoffreyApp/base.html new file mode 100644 index 0000000..21357ef --- /dev/null +++ b/templates/GeoffreyApp/base.html @@ -0,0 +1,33 @@ + + + + + {% block title %}GeoffreyApp{% endblock %} + + + + {% load static %} + + + + +
+
+
+ {% block sidebar %} + + {% endblock %} +
+
{% block content %}{% endblock %}
+
+
+ + diff --git a/templates/GeoffreyApp/base_list.html b/templates/GeoffreyApp/base_list.html new file mode 100644 index 0000000..e062039 --- /dev/null +++ b/templates/GeoffreyApp/base_list.html @@ -0,0 +1,17 @@ +{% extends "GeoffreyApp/base.html" %} + +{% block content %} +

Bases

+ {% if base_list %} + + {% else %} +

There are no bases in the database :pepethonk:

+ {% endif %} + +{% endblock %} diff --git a/templates/GeoffreyApp/home.html b/templates/GeoffreyApp/home.html new file mode 100644 index 0000000..205fff9 --- /dev/null +++ b/templates/GeoffreyApp/home.html @@ -0,0 +1,13 @@ +{% extends "GeoffreyApp/base.html" %} + +{% block content %} +

Geoffrey Minecraft Database Home

+

Geoffrey is a database for storing information on Players, Bases, Shops, Towns, and more!

+

Current Database Count:

+ +{% endblock %} \ No newline at end of file diff --git a/templates/GeoffreyApp/itemlisting_list.html b/templates/GeoffreyApp/itemlisting_list.html new file mode 100644 index 0000000..312095a --- /dev/null +++ b/templates/GeoffreyApp/itemlisting_list.html @@ -0,0 +1,17 @@ +{% extends "GeoffreyApp/base.html" %} + +{% block content %} +

Items

+ {% if itemlisting_list %} + + {% else %} +

There are no items for sale in the database :pepethonk:

+ {% endif %} + +{% endblock %} diff --git a/templates/GeoffreyApp/player_list.html b/templates/GeoffreyApp/player_list.html new file mode 100644 index 0000000..cd0e952 --- /dev/null +++ b/templates/GeoffreyApp/player_list.html @@ -0,0 +1,17 @@ +{% extends "GeoffreyApp/base.html" %} + +{% block content %} +

Players

+ {% if player_list %} + + {% else %} +

There are no players in the database :pepethonk:

+ {% endif %} + +{% endblock %} \ No newline at end of file diff --git a/templates/GeoffreyApp/shop_list.html b/templates/GeoffreyApp/shop_list.html new file mode 100644 index 0000000..451a8c3 --- /dev/null +++ b/templates/GeoffreyApp/shop_list.html @@ -0,0 +1,17 @@ +{% extends "GeoffreyApp/base.html" %} + +{% block content %} +

Shops

+ {% if shop_list %} + + {% else %} +

There are no shops in the database :pepethonk:

+ {% endif %} + +{% endblock %} diff --git a/urls.py b/urls.py index 2cf4473..b48b11b 100644 --- a/urls.py +++ b/urls.py @@ -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'), ] diff --git a/views.py b/views.py index 4058397..e236c6a 100644 --- a/views.py +++ b/views.py @@ -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 +