Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add public votes panel #72

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions templates/includes/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
{{ menu_item('Miis', 'list_miis', 'fa-smile') }}
{{ menu_item('Concierge', 'list_concierge', 'fa-star') }}
{{ menu_item('Categories and Movies', 'list_categories', 'fa-video') }}
{{ menu_item('Movie Votes', 'votes_list_categories', 'fa-video') }}
{{ menu_item('Pay Categories and Movies', 'list_pay_categories', 'fa-film') }}
{{ menu_item('Rooms', 'list_room', 'fa-door-closed') }}
{{ menu_item('Posters', 'list_posters', 'fa-scroll') }}
Expand All @@ -51,6 +52,7 @@
<p class="menu-label">
I wonder if hotels also have room servers
</p>
{{ menu_item('Movie Votes', 'votes_list_categories', 'fa-video') }}
<ul class="menu-list">
<figure class="image is-2by3">
<img src="/static/images/loginbo.png">
Expand Down
70 changes: 70 additions & 0 deletions templates/vote_category_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{% extends "generic/base_manage.html" %}

{% block type_name %}categories{% endblock %}
{% block type_name_singular %}category{% endblock %}

{% block table_listing %}

<p>
There is a total of {{ votes['count'] }} vote entries.
<br><br>
◎ {{ votes['vote.4'] }} ・ 〇 {{ votes['vote.3'] }} ・ △ {{ votes['vote.2'] }} ・ × {{ votes['vote.1'] }}
<br>
♂ {{ votes['gender.1'] }} ({{ ((votes['gender.1'] / votes['count']) * 100)|round|int }}%)
♀ {{ votes['gender.2'] }} ({{ ((votes['gender.2'] / votes['count']) * 100)|round|int }}%)
<br><br>
</p>

<table class="table is-fullwidth is-hoverable is-striped">
<thead>
<tr>
<th scope="col">Category ID</th>
<th scope="col">Name</th>
<th scope="col">Thumbnail</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
{% for category in categories.items %}
<tr>
<td>{{ category.category_id }}</td>
<td>{{ category.name }}</td>
<td>
<img src="{{ url_for('votes_get_category_thumbnail', category=category.category_id) }}"
alt="Thumbnail for category ID {{ categories.category_id }}"
width="50%"
/>
</td>
<td>
<div class="field has-addons">
<p class="control">
<a href="{{ url_for('votes_list_movies', category=category.category_id) }}" class="button is-link">
<span class="icon is-small">
<i class="fas fa-list"></i>
</span>
<span>List Movies</span>
</a>
</p>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}

{% block add_footer %}
{% if categories.has_prev %}
<a href="{{ url_for('votes_list_categories', page=categories.prev_num) }}">&lt; Previous</a>
{% else %}
&lt; Previous
{% endif %}
|
{% if categories.has_next %}
<a href="{{ url_for('votes_list_categories', page=categories.next_num) }}">Next &gt;</a>
{% else %}
Next &gt;
{% endif %}
<br/>
{% endblock %}
75 changes: 75 additions & 0 deletions templates/vote_movie_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{% extends "generic/base_manage.html" %}

{% block type_name %}movies{% endblock %}
{% block type_name_singular %}movie{% endblock %}

{% block table_listing %}
<br>
<a href="{{ url_for('votes_list_categories') }}">Return to Category Listing</a>
<table class="table is-fullwidth is-hoverable is-striped">
<thead>
<tr>
<th scope="col">Movie ID</th>
<th scope="col">Name</th>
<th scope="col">Length</th>
<th scope="col">Thumbnail</th>
<th scope="col">Votes</th>
</tr>
</thead>
<tbody>
{% for movie in movies.items %}
<tr>
<td>{{ movie.movie_id }}</td>
<td>{{ movie.title }}</td>
<td>{{ movie.length }}</td>
<td><img src="{{ url_for('votes_get_movie_thumbnail', movie_id=movie.movie_id) }}"
alt="Thumbnail for {{ movie.movie_id }}"/></td>
<td>
<div class="field has-addons">
<p class="control">
{{ votes[movie.movie_id]['count'] }} votes
<br>
◎ {{ votes[movie.movie_id]['vote.4'] }} ・ 〇 {{ votes[movie.movie_id]['vote.3'] }} ・ △ {{ votes[movie.movie_id]['vote.2'] }} ・ × {{ votes[movie.movie_id]['vote.1'] }}
<br>
♂ {{ votes[movie.movie_id]['gender.1'] }} ({{ ((votes[movie.movie_id]['gender.1'] / votes[movie.movie_id]['count']) * 100)|round|int }}%)
♀ {{ votes[movie.movie_id]['gender.2'] }} ({{ ((votes[movie.movie_id]['gender.2'] / votes[movie.movie_id]['count']) * 100)|round|int }}%)
</p>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}

{% block add_footer %}
<!-- Previous/Next -->
{% if movies.has_prev %}
<a href="{{ url_for('votes_list_movies', category=category_id, page=movies.prev_num) }}">&lt; Previous</a>
{% else %}
&lt; Previous
{% endif %}
|
{% if movies.has_next %}
<a href="{{ url_for('votes_list_movies', category=category_id, page=movies.next_num) }}">Next &gt;</a>
{% else %}
Next &gt;
{% endif %}
<br/>

<!-- First/Last -->
<!-- Ensure we are not on the first page. -->
{% if movies.page != 1 %}
<a href="{{ url_for('votes_list_movies', category=category_id, page=1) }}">&lt;&lt; First</a>
{% else %}
&lt;&lt; First
{% endif %}
|
<!-- Ensure we are not on the last page. -->
{% if movies.page != movies.pages %}
<a href="{{ url_for('votes_list_movies', category=category_id, page=movies.pages) }}">Last &gt;&gt;</a>
{% else %}
Last &gt;&gt;
{% endif %}
{% endblock %}
1 change: 1 addition & 0 deletions theunderground/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
room_types,
room_data,
pay_posters,
votes
)
150 changes: 150 additions & 0 deletions theunderground/votes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import os
import config

from flask import (
render_template,
redirect,
flash,
send_from_directory,
request,
url_for,
)
from flask_login import login_required
from flask_wtf.file import FileRequired
from werkzeug import exceptions

from asset_data import NormalCategoryAsset
from models import Categories, Movies, EvaluateData, db
from room import app, s3
from theunderground.forms import CategoryForm
from theunderground.operations import manage_delete_item
from theunderground.mobiclip import (
get_category_list,
validate_mobiclip,
get_mobiclip_length,
save_movie_data,
delete_movie_data,
get_movie_path,
)


@app.route("/theunderground/votes")
def votes_list_categories():
page_num = request.args.get("page", default=1, type=int)

categories = Categories.query.order_by(Categories.category_id.asc()).paginate(
page=page_num, per_page=15, error_out=False
)

votes = {}
evaluatedata = movie_vote = EvaluateData.query

movie_vote_count = evaluatedata.count()

movie_vote_t1 = evaluatedata.filter_by(vote=1).count()
movie_vote_t2 = evaluatedata.filter_by(vote=2).count()
movie_vote_t3 = evaluatedata.filter_by(vote=3).count()
movie_vote_t4 = evaluatedata.filter_by(vote=4).count()

movie_gender_t1 = evaluatedata.filter_by(gender=1).count()
movie_gender_t2 = evaluatedata.filter_by(gender=2).count()

movie_blood_t0 = evaluatedata.filter_by(blood=0).count()
movie_blood_t1 = evaluatedata.filter_by(blood=1).count()
movie_blood_t2 = evaluatedata.filter_by(blood=2).count()
movie_blood_t3 = evaluatedata.filter_by(blood=3).count()
movie_blood_t4 = evaluatedata.filter_by(blood=4).count()

votes = {
"count": movie_vote_count,
"vote.1": movie_vote_t1,
"vote.2": movie_vote_t2,
"vote.3": movie_vote_t3,
"vote.4": movie_vote_t4,
"gender.1": movie_gender_t1,
"gender.2": movie_gender_t2,
"blood.0": movie_blood_t0,
"blood.1": movie_blood_t1,
"blood.2": movie_blood_t2,
"blood.3": movie_blood_t3,
"blood.4": movie_blood_t4,
"blood.avg": 0,
"age.avg": 0
}

return render_template(
"vote_category_list.html",
categories=categories,
votes=votes,
type_length=categories.total,
type_max_count=64,
)

@app.route("/theunderground/votes/<category>/thumbnail.jpg")
def votes_get_category_thumbnail(category):
if s3:
return redirect(f"{config.url1_cdn_url}/list/category/img/{category}.img")

return NormalCategoryAsset(category).send_file()

@app.route("/theunderground/votes/<category>")
def votes_list_movies(category):
# Get our current page, or start from scratch.
page_num = request.args.get("page", default=1, type=int)

# We want at most 20 movies per page.
movies = Movies.query.filter(Movies.category_id == category).paginate(
page=page_num, per_page=20, error_out=False
)

votes = {}
evaluatedata = movie_vote = EvaluateData.query

for movie in movies.items:
movie_vote = evaluatedata.filter_by(movie_id=movie.movie_id)

movie_vote_count = movie_vote.count()

movie_vote_t1 = movie_vote.filter_by(vote=1).count()
movie_vote_t2 = movie_vote.filter_by(vote=2).count()
movie_vote_t3 = movie_vote.filter_by(vote=3).count()
movie_vote_t4 = movie_vote.filter_by(vote=4).count()

movie_gender_t1 = movie_vote.filter_by(gender=1).count()
movie_gender_t2 = movie_vote.filter_by(gender=2).count()

votes[movie.movie_id] = {
"count": movie_vote_count,
"vote.1": movie_vote_t1,
"vote.2": movie_vote_t2,
"vote.3": movie_vote_t3,
"vote.4": movie_vote_t4,
"gender.1": movie_gender_t1,
"gender.2": movie_gender_t2,
"blood.0": 0,
"blood.1": 0,
"blood.2": 0,
"blood.3": 0,
"blood.4": 0,
"blood.avg": 0,
"age.avg": 0
}

print(votes)

return render_template(
"vote_movie_list.html",
movies=movies,
votes=votes,
category_id=category,
type_length=movies.total,
type_max_count=64,
)

@app.route("/theunderground/movies/<movie_id>/thumbnail.jpg")
def votes_get_movie_thumbnail(movie_id):
movie_dir = get_movie_path(movie_id)
if s3:
return redirect(f"{config.url1_cdn_url}/{movie_dir}/{movie_id}.img")

return send_from_directory(movie_dir, f"{movie_id}.img")
Loading