Skip to content

Commit

Permalink
Final commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelromon committed Dec 22, 2019
1 parent 589ee21 commit 7e01a90
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 41 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ __pycache__/
*.py[cod]
*$py.class


# Django stuff:
*.log
*.mo
local_settings.py
db.sqlite3
gamehoarder_site/static/images/avatars/*

# Environments
.env
Expand Down
2 changes: 1 addition & 1 deletion game_collection/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class Meta:

class Tag(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name=_("user"))
name = models.CharField(max_length=16, verbose_name=_("name"), unique=True)
name = models.CharField(max_length=16, verbose_name=_("name"))
game_version = models.ManyToManyField(GameVersion, verbose_name=_("game version"))

tag_group = models.ForeignKey(TagGroup, on_delete=models.SET_NULL, blank=True, null=True,
Expand Down
24 changes: 11 additions & 13 deletions game_collection/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,9 @@ def game_view(request, db_id):
"existing_review": review,
"share_text": f"Check out {title.title} on #GameHoarder"
}
try:
context["current_state"] = GameCollectionController.where_is(game_version, request.user)[0],
context["current_item"] = GameCollectionController.where_is(game_version, request.user)[1]
except TypeError:
pass

context["current_state"] = GameCollectionController.where_is(game_version, request.user)[0]
context["current_item"] = GameCollectionController.where_is(game_version, request.user)[1]

return render(request, 'collection/game_view.html', context)

Expand Down Expand Up @@ -465,7 +463,7 @@ def move_game(request, db_id):
"user": user,
"game_version": game_version,
"price": form.cleaned_data["price"],
"date_adquired": datetime.datetime.strptime(form.cleaned_data['date_adquired'], "%m/%d/%Y"),
"date_adquired": datetime.strptime(form.cleaned_data['date_adquired'], "%m/%d/%Y"),
"time_played": form.cleaned_data["time_played"],
}

Expand All @@ -481,27 +479,27 @@ def move_game(request, db_id):
Queue.objects.create(**new_item)

elif new_state == 4:
new_item["date_started"] = datetime.datetime.strptime(form.cleaned_data['date_started'], "%m/%d/%Y")
new_item["date_started"] = datetime.strptime(form.cleaned_data['date_started'], "%m/%d/%Y")

Playing.objects.create(**new_item)

elif new_state == 5:
new_item["date_started"] = datetime.datetime.strptime(form.cleaned_data['date_started'], "%m/%d/%Y")
new_item["date_stopped"] = datetime.datetime.strptime(form.cleaned_data['date_other'], "%m/%d/%Y")
new_item["date_started"] = datetime.strptime(form.cleaned_data['date_started'], "%m/%d/%Y")
new_item["date_stopped"] = datetime.strptime(form.cleaned_data['date_other'], "%m/%d/%Y")

Played.objects.create(**new_item)

elif new_state == 6:
new_item["date_started"] = datetime.datetime.strptime(form.cleaned_data['date_started'], "%m/%d/%Y")
new_item["date_finished"] = datetime.datetime.strptime(form.cleaned_data['date_other'], "%m/%d/%Y")
new_item["date_started"] = datetime.strptime(form.cleaned_data['date_started'], "%m/%d/%Y")
new_item["date_finished"] = datetime.strptime(form.cleaned_data['date_other'], "%m/%d/%Y")

new_item["time_to_finish"] = form.cleaned_data["time_other"]

Finished.objects.create(**new_item)

elif new_state == 7:
new_item["date_started"] = datetime.datetime.strptime(form.cleaned_data['date_started'], "%m/%d/%Y")
new_item["date_abandoned"] = datetime.datetime.strptime(form.cleaned_data['date_other'], "%m/%d/%Y")
new_item["date_started"] = datetime.strptime(form.cleaned_data['date_started'], "%m/%d/%Y")
new_item["date_abandoned"] = datetime.strptime(form.cleaned_data['date_other'], "%m/%d/%Y")

Abandoned.objects.create(**new_item)

Expand Down
2 changes: 1 addition & 1 deletion gamehoarder_api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@

path('users', views.user_list, name='user_list'),
path('users/delete', views.delete_user, name='delete_user'),
path('users/edit', views.edit_user, name='edit_user'),
path('users/edit', views.edit_user, name='api_edit_user'),
path('users/<str:username>', views.user_view, name='api_user_view'),
]
168 changes: 165 additions & 3 deletions gamehoarder_site/templates/collection/collection_summary.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% extends "base_site.html" %}
{% load i18n %}
{% load static %}
{% block title %}{% trans "Collection Summary" %} {% endblock title %}

{% block stylesheets %}
Expand All @@ -8,12 +9,173 @@

{% block content %}
<div class="right_col" role="main">
{# TODO this should be in the settings page #}
<a href="{% url "import_collection" %}" class="btn btn-primary">{% trans "Import Collection" %}</a>
<a href="{% url "import_lists" %}" class="btn btn-primary">{% trans "Import Lists" %}</a>

<div class="row tile_count" id="user-stats">
<div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count">
<span class="count_top"><i class="fa fa-gamepad"></i> Games</span>
<div class="count">[[ info.games ]]</div>
</div>
<div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count">
<span class="count_top"><i class="fa fa-clock-o"></i> Hours</span>
<div class="count">[[ info.hours ]]</div>
</div>
<div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count">
<span class="count_top"><i class="fa fa-archive"></i> Completion Rate</span>
<div class="count">[[ info.completion_rate ]] %</div>
</div>
</div>

<div class="row">
<div class="col-md-5 col-sm-5 ">
<div class="x_panel tile fixed_height_320 overflow_hidden">
<div class="x_title">
<h2>{% trans "Collection Summary" %}</h2>
<ul class="nav navbar-right panel_toolbox" style="min-width: 0">
<li><a class="collapse-link">
<i class="fa fa-chevron-up"></i></a>
</li>
</ul>
<div class="clearfix"></div>
</div>

<div class="x_content">
<table class="" style="width:100%">
<tr>
<th style="width:37%;">

</th>
<th>
<div class="col-lg-7 col-md-7 col-sm-7 ">
<p class="">List</p>
</div>

</th>
</tr>
<tr>
<td>
<canvas id="collectionSummaryPie" height="140" width="140"
style="margin: 15px 10px 10px 0"></canvas>
</td>
<td id="collection-stats">
<table class="tile_info">
<tr>
<td>
<p><i class="fa fa-square blue"></i>{% trans "Queue" %} </p>
</td>
<td>[[ parseFloat((info.queue / info.total) * 100).toFixed(2)]]%</td>
</tr>
<tr>
<td>
<p><i class="fa fa-square green"></i>Playing </p>
</td>
<td>[[ parseFloat((info.playing / info.total) * 100).toFixed(2)]]%</td>
</tr>
<tr>
<td>
<p><i class="fa fa-square purple"></i>Played </p>
</td>
<td>[[ parseFloat((info.played / info.total) * 100).toFixed(2)]]%</td>
</tr>
<tr>
<td>
<p><i class="fa fa-square aero"></i>Finished </p>
</td>
<td>[[ parseFloat((info.finished / info.total) * 100).toFixed(2)]]%</td>
</tr>
<tr>
<td>
<p><i class="fa fa-square red"></i>Abandoned </p>
</td>
<td>[[ parseFloat((info.abandoned / info.total) * 100).toFixed(2)]]%</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>

<div class="row">
<a href="{% url "import_collection" %}" class="btn btn-primary">{% trans "Import Collection" %}</a>
<a href="{% url "import_lists" %}" class="btn btn-primary">{% trans "Import Lists" %}</a>
</div>
</div>
{% endblock content %}

{% block javascripts %}

<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="{% static "/vendors/Chart.js/dist/Chart.min.js" %}"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

<script>

var app = new Vue({
delimiters: ['[[', ']]'],
el: '#user-stats',

data() {
return {
info: null
}
},
mounted() {
axios
.get('{% url "user_stats" %}')
.then(response => (this.info = response.data))
},

});
var app2 = new Vue({
delimiters: ['[[', ']]'],
el: '#collection-stats',

data() {
return {
info: null
}
},
mounted() {
axios
.get('{% url "collection_stats" %}')
.then(response => (this.info = response.data));

this.createChart("collectionSummaryPie", this.info)
},

methods: {
createChart(chartId, chartData) {
var ctx = document.getElementById(chartId);
var myChart = new Chart(ctx, {
type: 'pie',
data: {
labels: ["{% trans 'Queue' %}", '{% trans "Playing" %}', '{% trans "Played" %}', '{% trans "Finished" %}', '{% trans "Abandoned" %}'],
datasets: [{
label: '{% trans "Games" %}',
data: chartData,
backgroundColor: [
'#3498DB',
'#1ABB9C',
'#9B59B6',
'#9CC2CB',
'#E74C3C',
],
}]
},
options: {
legend: {
display: false
},
}
});

}
}
});

</script>

{{ block.super }}
{% endblock javascripts %}
7 changes: 4 additions & 3 deletions gamehoarder_site/templates/landing.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,17 @@ <h2>{% trans "Game Hoarder" %}</h2>
<div class="col-md-4 feature">
<img src="{% static "img/feature-icons/1.png" %}" width="50%" alt="#">
<h4>{% trans "Track your Collection" %}</h4>
<p>{% trans "You can keep track of your game collection!" %}</p>
<p>{% trans "Say goodbye to those long spreadsheets" %}</p>
</div>
<div class="col-md-4 feature">
<img src="{% static "img/feature-icons/2.png" %}" width="50%" alt="#">
<h4>{% trans "Connect with your Friends" %}</h4>
<p>{% trans "You can follow and connect with yout friends¡" %}</p>
<p>{% trans "Everything is better with friends" %}</p>
</div>
<div class="col-md-4 feature">
<img src="{% static "img/feature-icons/3.png" %}" width="50%" alt="#">
<h4>{% trans "Access it Anywhere" %}</h4>
<p>{% trans "Keep it mobile" %}</p>
</div>
</div>
</div>
Expand Down Expand Up @@ -253,7 +254,7 @@ <h5 class="fw-title">{% trans "Contact" %}</h5>
{#TODO there is a better way to do this #}
axios
.get('{% url "stats" %}')
.then(response => (this.info = response.data))
.then(response => (this.info = response.data));

window.setInterval(() => {
axios
Expand Down
19 changes: 10 additions & 9 deletions gamehoarder_site/templates/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ <h2>{{ profile.user.username }}</h2>
<div class="menu_section">
<h3>{% trans "General" %}</h3>
<ul class="nav side-menu">
<li><a href="{% url "profileView" %}"><i class="fa fa-home"></i> {% trans "Home" %} <span class="fa"></span></a></li>
<li><a href="{% url "index" %}"><i class="fa fa-home"></i> {% trans "Home" %} <span
class="fa"></span></a></li>
<li><a href="{% url "search_users" %}"><i class="fa fa-users"></i> {% trans "Users" %} <span
class="fa"></span></a></li>
</ul>
Expand Down Expand Up @@ -59,14 +60,14 @@ <h3>{% trans "Lists" %}</h3>
</li>
<li><a href="{% url "wishlist_table" %}"><i class="fa fa-star"></i> {% trans "Wishlist" %} <span
class="fa"></span></a></li>
<li><a><i class="fa fa-institution"></i> {% trans "Custom" %} <span
class="fa fa-chevron-down"></span></a>
<ul class="nav child_menu">
{% for tag in tags %}
<li><a href="/tag/?tag={{ tag.name }}">{{ tag.name }}</a></li>
{% endfor %}
</ul>
</li>
{# <li><a><i class="fa fa-institution"></i> {% trans "Custom" %} <span#}
{# class="fa fa-chevron-down"></span></a>#}
{# <ul class="nav child_menu">#}
{# {% for tag in tags %}#}
{# <li><a href="/tag/?tag={{ tag.name }}">{{ tag.name }}</a></li>#}
{# {% endfor %}#}
{# </ul>#}
{# </li>#}
</ul>
</div>
</div>
Expand Down
14 changes: 3 additions & 11 deletions gamehoarder_site/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,23 @@
from django.contrib import auth
from django.contrib.auth import authenticate, login
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import Group
from django.db.models import Q
from django.http import HttpResponse, HttpResponseRedirect, JsonResponse
from django.shortcuts import render, redirect
from django.template.context_processors import csrf
from django.urls import reverse
from django.contrib.auth.models import Group

from game_collection.models import Tag, Queue, Played, Playing, Abandoned, Finished
from game_database.functions import GameHoarderDB
from game_database.models import Genre, Platform
from .forms import *
from django.db.models import Q


@login_required(login_url='login')
def index(request):
if not request.user.is_authenticated:
return render(request, "landing.html")

custom = Tag.objects.filter(user=request.user)
profile = Profile.objects.get(user=request.user)
context = {
"tags": custom,
"profile": profile
}
return render(request, "index.html", context)
return profileView(request)


@login_required(login_url='login')
Expand Down

0 comments on commit 7e01a90

Please sign in to comment.