Rewrite data layer using SqlAlchemy Part 1

This commit is contained in:
2019-10-14 19:02:25 +02:00
parent f6a38cc2db
commit fccd75d6c5
51 changed files with 1297 additions and 658 deletions

View File

@@ -0,0 +1,68 @@
{% extends "bootstrap/base.html" %}
{% block title %}- Estus Shots{% endblock %}
{% block scripts %}
<script type="text/javascript" src="{{ url_for('static', filename='js/estus-shots.js') }}"></script>
{% endblock %}
{% block styles %}
{{ super() }}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.1/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<link rel="stylesheet" href="/static/dark_theme.css">
<link rel="stylesheet" href="/static/custom.css">
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
{% endblock %}
{% block navbar %}
{% set nav_bar = [
('/season', 'seasons', 'Seasons', 'fas fa-calendar'),
('/player', 'players', 'Players', 'fas fa-users'),
('/enemy', 'enemies', 'Enemies', 'fas fa-skull-crossbones'),
('/drink', 'drinks', 'Drinks', 'fas fa-beer')
]-%}
<div class="container">
<nav class="navbar navbar-expand-lg bg-dark navbar-dark">
<a class="navbar-brand">
<img class="brand-icon" alt="" src="/static/img/brand.png">
Estus Shots
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
{% for href, id, caption, icon in nav_bar %}
<li class="nav-item{% if id == active_page %} active{% endif %}">
<a class="nav-link" href="{{ href|e }}">
<i class="{{ icon|e }} icon-primary"></i> {{ caption|e }}
</a>
</li>
{% endfor %}
</ul>
<ul class="nav navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="/logout">Logout</a>
</li>
</ul>
</div>
</nav>
</div>
{% endblock %}
{% block content %}
<div class="container">
{% block page %}
{% endblock %}
<div>
{% block footer %}
&copy; Sauf Software by D⁵: <a href="#">Durstiger Donnerstag Digital Drinking Divison</a>.
{% endblock %}
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,48 @@
{% extends "base.html" %}drink_save
{% set active_page = "drinks" %}
{% block title %}Drinks {{ super() }}{% endblock %}
{% block page %}
{% if g.is_editor %}
<div class="btn-toolbar" role="toolbar">
<a class="btn btn-primary" href="{{ url_for('new_drink') }}" role="button">
<span class="fas fa-plus"></span> Drink
</a>
</div>
{% endif %}
{% if not model.drinks %}
There are no drinks.
{% else %}
<table class="table table-hover table-striped table-bordered">
<thead>
<tr>
{% for prop, caption in model.columns %}
<th scope="col" class="col-sm-auto text-center">{{ caption }}</th>
{% endfor %}
{% if g.is_editor %}
<th scope="col" class="col-sm-auto text-center"></th>
{% endif %}
</tr>
</thead>
<tbody>
{% for drink in model.drinks %}
<tr>
{% for prop, caption in model.columns %}
<td class="col-sm-auto text-center">{{ drink[prop] }}</td>
{% endfor %}
{% if g.is_editor %}
<td class="col-sm-auto text-center">
<a class="btn btn-default" href="{{ url_for('drink_edit', drink_id = drink.id) }}">
<span class="fas fa-pencil-alt"></span>
</a>
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
{% endblock %}

View File

@@ -0,0 +1,52 @@
{% extends "base.html" %}
{% set active_page = "enemies" %}
{% block title %}Enemies {{ super() }}{% endblock %}
{% block page %}
{% if g.is_editor %}
<div class="btn-toolbar" role="toolbar">
<a class="btn btn-primary" href="{{ url_for('enemy_new') }}" role="button">
<span class="fas fa-plus"></span> Enemy
</a>
</div>
{% endif %}
{% if not model.enemies %}
There are no enemies.
{% else %}
<table class="table table-hover table-striped table-bordered">
<thead>
<tr>
<th scope="col" class="col-sm-auto text-center">Name</th>
<th scope="col" class="col-sm-auto text-center">Season</th>
<th scope="col" class="col-sm-auto text-center">Boss Enemy</th>
{% if g.is_editor %}
<th scope="col" class="col-sm-auto text-center">Editor</th>
{% endif %}
</tr>
</thead>
<tbody>
{% for enemy in model.enemies %}
<tr>
<td class="col-sm-auto text-center">{{ enemy.name }}</td>
<td class="col-sm-auto text-center">{{ enemy.season.game }}</td>
<td class="col-sm-auto text-center">
{% if enemy.boss %}
<span class="fas fa-check"></span>
{% endif %}
</td>
{% if g.is_editor %}
<td class="col-sm-auto text-center">
<a class="btn btn-default" href="{{ url_for('enemy_edit', enemy_id = enemy.id) }}">
<span class="fas fa-pencil-alt"></span>
</a>
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
{% endblock %}

View File

@@ -0,0 +1,133 @@
{% extends "base.html" %}
{% set active_page = "seasons" %}
{% block title %}{{ model.title }} {{ super() }}{% endblock %}
{% block page %}
{% if g.is_editor %}
<div class="btn-toolbar" role="toolbar">
<a class="btn btn-primary" role="button"
href="{{ url_for('episode_edit', season_id = model.season.id, episode_id = model.episode.id) }}">
<span class="fas fa-pencil-alt"></span> Edit Episode
</a>
<a class="btn btn-primary" role="button"
href="{{ url_for("event_new", ep_id = model.episode.id, s_id = model.season.id) }}" >
<span class="fas fa-plus"></span> Event
</a>
</div>
{% endif %}
<div class="row">
<div class="col-sm-6">
<!--region Info Card-->
<div class="card">
<div class="card-header text-center">
{{ model.episode.code }}: {{ model.episode.title }}
</div>
<div class="card-body">
<div class="card-text">
<ul class="list-group list-group-flush">
<li class="list-group-item">
<span class="font-weight-bold">Date:</span>
{{ model.episode.date }}
</li>
<li class="list-group-item">
<span class="font-weight-bold">Start:</span>
{{ model.episode.start|format_time }}
</li>
<li class="list-group-item">
<span class="font-weight-bold">End:</span>
{{ model.episode.end|format_time }}
</li>
<li class="list-group-item">
<span class="font-weight-bold">Play Time:</span>
{{ model.episode.playtime }}
</li>
<li class="list-group-item">
<span class="font-weight-bold">Enemies Defeated:</span>
{{ model.events.victory_count }}
</li>
<li class="list-group-item">
<span class="font-weight-bold">Deaths:</span>
{{ model.events.defeat_count }}
</li>
</ul>
</div>
</div>
</div>
<!--endregion-->
<hr>
<!--region Player Card-->
<div class="card">
<div class="card-header text-center">
Players in this episode
</div>
<div class="card-body">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th scope="col" class="col-sm-auto text-center">Name</th>
</tr>
</thead>
<tbody>
{% for player in model.players %}
<tr>
<td class="col-sm-auto text-center">{{ player.name }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<!--endregion-->
</div>
<div class="col-sm-6">
{% if model.events %}
<div class="card">
<div class="card-header text-center">
Event List
</div>
<div class="card-body">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th scope="col" class="col-sm-auto text-center">Time</th>
<th scope="col" class="col-sm-auto text-center">Type</th>
<th scope="col" class="col-sm-auto text-center">Player</th>
<th scope="col" class="col-sm-auto text-center">Enemy</th>
</tr>
</thead>
<tbody>
{% for entry in model.events.entries %}
<tr>
<td class="col-sm-auto text-center">{{ entry.time }}</td>
<td class="col-sm-auto text-center">{{ entry.type.name }}</td>
<td class="col-sm-auto text-center">{{ entry.type.player_name }}</td>
<td class="col-sm-auto text-center">{{ entry.type.enemy_name }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% else %}
<div class="card">
<div class="card-header text-center">
Event List
</div>
<div class="card-body">
<div class="alert alert-info">Nothing did happen yet</div>
</div>
</div>
{% endif %}
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,58 @@
{% extends "base.html" %}
{% set active_page = "seasons" %}
{% block title %}{{ model.season_code }} - Episodes{% endblock %}
{% block content %}
{% if g.is_editor %}
<div class="btn-toolbar" role="toolbar">
<a class="btn btn-primary" href="{{ url_for("episode_new", season_id = model.season_id)}}" role="button">
<span class="fas fa-plus"></span>Episode
</a>
</div>
{% endif %}
{% if not model.player_list %}
<div class="alert alert-info">There are no episodes.</div>
{% else %}
<table class="table table-hover table-striped table-bordered">
<thead>
<tr>
<th scope="col" class="col-sm-auto text-center">#</th>
<th scope="col" class="col-sm-auto text-center">Title</th>
<th scope="col" class="col-sm-auto text-center">Date</th>
<th scope="col" class="col-sm-auto text-center">From - To</th>
<th scope="col" class="col-sm-auto text-center">Playtime</th>
<th scope="col" class="col-sm-auto text-center">Stats</th>
{% if g.is_editor %}
<th scope="col" class="col-sm-auto text-center">Editor</th>
{% endif %}
</tr>
</thead>
<tbody>
{% for item in model.episodes %}
<tr>
<td class="col-sm-auto text-center">{{ item.code }}</td>
<td class="col-sm-auto text-center">{{ item.title }}</td>
<td class="col-sm-auto text-center">{{ item.date }}</td>
<td class="col-sm-auto text-center">{{ item.start }} - {{ item.end }}</td>
<td class="col-sm-auto text-center">{{ item.duration }}</td>
<td class="col-sm-auto text-center">
<a class="btn btn-default" href="{{ url_for("episode_stats", episode_id = item.id) }}">
<span class="fas fa-eye"></span>
</a>
</td>
{% if g.is_editor %}
<td class="col-sm-auto text-center">
<a class="btn btn-default" href="{{ url_for("episode_edit", episode_id = item.id, season_id = model.season_id) }}">
<span class="fas fa-pencil-alt"></span>
</a>
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
{% endblock %}

View File

@@ -0,0 +1,95 @@
{% extends "base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{% set active_page = "seasons" %}
{% block title %}{{ model.page_title }} {{ super() }}{% endblock %}
{% block page %}
<div class="text-center">
<h1>{{ model.form_title }}</h1>
{% if model.errors %}
<div class="alert alert-danger">
{% for field, errors in model.errors.items() %}
<div>
<strong class="text-capitalize">{{ field }}</strong>:
{{ errors|join(', ') }}
</div>
{% endfor %}
</div>
{% endif %}
<form action="{{ model.post_url }}" method="post">
{{ form.hidden_tag() }}
<div class="form-group row required">
<div class="col-lg-2">
{{ form.event_type.label(class_="form-control-label") }}
</div>
<div class="col-lg-10">
{{ form.event_type(class_="form-control") }}
</div>
</div>
<div class="form-group row required">
<div class="col-lg-2">
{{ form.time.label(class_="form-control-label") }}
</div>
<div class="col-lg-10 row">
<div class="col">
{{ form.time(class_="form-control") }}
</div>
<div class="col">
<button type="button" class="btn btn-default btn-block"
onclick="editorModule.setCurrentTime('time')">Now</button>
</div>
</div>
</div>
<div class="form-group row required">
<div class="col-lg-2">
{{ form.player.label(class_="form-control-label") }}
</div>
<div class="col-lg-10">
{{ form.player(class_="form-control") }}
</div>
</div>
<div class="form-group row required">
<div class="col-lg-2">
{{ form.enemy.label(class_="form-control-label") }}
</div>
<div class="col-lg-10">
{{ form.enemy(class_="form-control") }}
</div>
</div>
<div class="form-group row">
<div class="col-lg-2">
{{ form.comment.label(class_="form-control-label") }}
</div>
<div class="col-lg-10">
{{ form.comment(class_="form-control") }}
</div>
</div>
<div class="penalty-container">
{% for penalty in form.penalties %}
{{ penalty.hidden_tag() }}
<div class="penalty-item">
{{ penalty.penalty_id }}
{{ penalty.player_id }}
{{ penalty.player }}
<label class="form-control-label">{{ penalty.player.data }}</label>
{{ penalty.drink }}
</div>
{% endfor %}
</div>
<div class="offset-lg-2 col-lg-10">
{{ form.submit_button(class_="btn btn-primary") }}
</div>
</form>
</div>
{% endblock %}

View File

@@ -0,0 +1,25 @@
{% extends "base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{% set active_page = model.active_page %}
{% block title %}{{ model.page_title }} {{ super() }}{% endblock %}
{% block page %}
<div class="text-center">
<h1>{{ model.form_title }}</h1>
{% if model.errors %}
<div class="alert alert-danger">
{% for field, errors in model.errors.items() %}
<div>
<strong class="text-capitalize">{{ field }}</strong>:
{{ errors|join(', ') }}
</div>
{% endfor %}
</div>
{% endif %}
<form action="{{ model.post_url }}" method="post">
{{ wtf.quick_form(form, button_map={'submit_button': 'primary'}, form_type='horizontal', horizontal_columns=('lg', 2, 10)) }}
</form>
</div>
{% endblock %}

View File

@@ -0,0 +1,37 @@
{% extends "bootstrap/base.html" %}
{% block title %}Estus Shots{% endblock %}
{% block styles %}
{{ super() }}
<link rel="stylesheet" href="/static/dark_theme.css">
<link rel="stylesheet" href="/static/custom.css">
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
{% endblock %}
{% block body_attribs %}
style="background-image: url(/static/img/elite.png), url(/static/img/solaire300x300.png);
background-repeat: no-repeat, no-repeat;
background-position: left bottom, right bottom;"
{% endblock %}
{% block content %}
<div class="container vertical-center">
<div class="card text-center mx-auto" style="width: 15rem">
<img src="/static/img/estus.png" alt="Login" style="height: 15rem">
<div class="card-body">
<form method="post">
<div class="form-group">
<label for="password">Password</label>
<input type="password" id="password" name="password" class="form-control">
</div>
<button type="submit" class="btn btn-primary">Enter</button>
</form>
</div>
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,46 @@
{% extends "base.html" %}
{% set active_page = "players" %}
{% block title %}Players {{ super() }}{% endblock %}
{% block page %}
{% if g.is_editor %}
<div class="btn-toolbar" role="toolbar">
<a class="btn btn-primary" href="{{ url_for('player_new') }}" role="button"><span class="fas fa-plus"></span> Player</a>
</div>
{% endif %}
{% if not model.player_list %}
There are no players.
{% else %}
<table class="table table-hover table-striped table-bordered">
<thead>
<tr>
{% for prop, caption in model.columns %}
<th scope="col" class="col-sm-auto text-center">{{ caption }}</th>
{% endfor %}
{% if g.is_editor %}
<th scope="col" class="col-sm-auto text-center">Edit</th>
{% endif %}
</tr>
</thead>
<tbody>
{% for player in model.player_list %}
<tr>
{% for prop, caption in model.columns %}
<td class="col-sm-auto text-center">{{ player[prop] }}</td>
{% endfor %}
{% if g.is_editor %}
<td class="col-sm-auto text-center">
<a class="btn btn-default" href="{{ url_for('player_edit', player_id = player.id) }}">
<span class="fas fa-pencil-alt"></span>
</a>
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
{% endblock %}

View File

@@ -0,0 +1,59 @@
{% extends "base.html" %}
{% set active_page = "seasons" %}
{% block title %}Seasons {{ super() }}{% endblock %}
{% block page %}
{% if g.is_editor %}
<div class="btn-toolbar" role="toolbar">
<a class="btn btn-primary" href="{{ url_for("season_new") }}" role="button"><span class="fas fa-plus"></span> Season</a>
</div>
{% endif %}
{% if not model.seasons %}
There are no seasons.
{% else %}
<table class="table table-hover table-striped table-bordered">
<thead>
<tr>
{% for prop, caption in model.columns %}
<th scope="col" class="col-sm-auto text-center">{{ caption }}</th>
{% endfor %}
{# Show #}
<th scope="col" class="col-sm-auto text-center">View</th>
{% if g.is_editor %}
{# Edit #}
<th scope="col" class="col-sm-auto text-center">Editor</th>
{% endif %}
</tr>
</thead>
<tbody>
{% for item in model.seasons %}
<tr>
{% for prop, caption in model.columns %}
<td class="col-sm-auto text-center">{{ item[prop] }}</td>
{% endfor %}
<td class="col-sm-auto text-center">
<a class="btn btn-default" href="{{ url_for("season_overview", season_id = item.id) }}">
<span class="fas fa-eye"></span></a>
</td>
{% if g.is_editor %}
<td class="col-sm-auto text-center">
<a class="btn btn-default" href="{{ url_for('season_edit', season_id = item.id) }}">
<span class="fas fa-pencil-alt"></span>
</a>
<a class="btn btn-default" href="{{ url_for("episode_new", season_id = item.id) }}">
<span class="fas fa-plus"></span> Episode
</a>
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
{% endblock %}

View File

@@ -0,0 +1,83 @@
{% extends "base.html" %}
{% set active_page = "seasons" %}
{% block title %}{{ model.title }} {{ super() }}{% endblock %}
{% block content %}
<div class="container">
<div class="row">
{# Overview #}
<div class="col-4">
<div class="card">
<div class="card-header text-center">
{{ model.title }}
</div>
<div class="card-body">
<h5 class="card-title">Infos</h5>
{% for item in model.season_info %}
<div class="card-text">
<ul class="list-group list-group-flush">
<li class="list-group-item">
<span class="font-weight-bold">{{ item }}:</span>
{{ model.season_info[item] }}
</li>
</ul>
</div>
{% endfor %}
</div>
</div>
</div>
{# Episode List #}
<div class="col">
<div class="card">
<div class="card-header text-center">Episodes</div>
<div class="card-body">
{% if not model.episodes %}
<div class="alert alert-info">No Episodes in this Season</div>
{% else %}
<table class="table table-striped table-bordered">
<thead>
<tr>
<th scope="col" class="col-sm-auto text-center">#</th>
<th scope="col" class="col-sm-auto text-center">Date</th>
<th scope="col" class="col-sm-auto text-center">Title</th>
<th scope="col" class="col-sm-auto text-center">View</th>
{% if g.is_editor %}
<th scope="col" class="col-sm-auto text-center">Editor</th>
{% endif %}
</tr>
</thead>
<tbody>
{% for item in model.episodes %}
<tr>
<td class="col-sm-auto text-center">{{ item.code }}</td>
<td class="col-sm-auto text-center">{{ item.date }}</td>
<td class="col-sm-auto text-center">{{ item.title }}</td>
<td class="col-sm-auto text-center">
<a class="btn btn-default" href="{{ url_for('episode_detail', season_id = item.season_id, episode_id = item.id) }}">
<span class="fas fa-eye"></span></a>
</td>
{% if g.is_editor %}
<td class="col-sm-auto text-center">
<a class="btn btn-default" href="{{ url_for('episode_edit', season_id = item.season_id, episode_id = item.id) }}">
<span class="fas fa-pencil-alt"></span>
</a>
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
</div>
</div>
</div>
</div>
</div>
{% endblock %}