initial commit
This commit is contained in:
+110
@@ -0,0 +1,110 @@
|
||||
# Created by .ignore support plugin (hsz.mobi)
|
||||
### Python template
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# pyenv
|
||||
.python-version
|
||||
|
||||
# celery beat schedule file
|
||||
celerybeat-schedule
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
|
||||
# custom
|
||||
.idea/
|
||||
*.db
|
||||
@@ -0,0 +1,33 @@
|
||||
import os
|
||||
from flask import Flask, render_template, redirect, url_for, request
|
||||
|
||||
from peewee import fn
|
||||
|
||||
from model import Rides, connect
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
db_path = os.getenv("WIE_RIJD_DB", 'wie_rijd.db')
|
||||
|
||||
|
||||
@app.route('/')
|
||||
def root():
|
||||
nrides = fn.COUNT(Rides.date).alias('amount')
|
||||
amounts = Rides.select(Rides.name, nrides).group_by(Rides.name).order_by(nrides.desc())
|
||||
|
||||
return render_template('list.html', title="hello", persons=amounts)
|
||||
|
||||
|
||||
@app.route('/add', methods=["POST"])
|
||||
def add_entry():
|
||||
Rides.create(name=request.form.get('name'))
|
||||
return redirect(url_for('root'))
|
||||
|
||||
|
||||
@app.before_first_request
|
||||
def init():
|
||||
connect(db_path)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
||||
@@ -0,0 +1,28 @@
|
||||
from datetime import datetime
|
||||
from typing import Union
|
||||
|
||||
from peewee import Proxy, Database, Model, CharField, DateTimeField, SqliteDatabase, CompositeKey
|
||||
|
||||
db: Union[Database, Proxy] = Proxy()
|
||||
|
||||
|
||||
class BaseModel(Model):
|
||||
class Meta:
|
||||
database = db
|
||||
|
||||
|
||||
class Rides(BaseModel):
|
||||
class Meta:
|
||||
primary_key = CompositeKey('name', 'date')
|
||||
name: str = CharField()
|
||||
date: datetime = DateTimeField(default=datetime.now)
|
||||
|
||||
|
||||
models = [Rides]
|
||||
|
||||
|
||||
def connect(db_name: str):
|
||||
sqlite = SqliteDatabase(db_name)
|
||||
sqlite.connect()
|
||||
db.initialize(sqlite)
|
||||
db.create_tables(models)
|
||||
@@ -0,0 +1,2 @@
|
||||
flask >= 1.1.1
|
||||
peewee >= 3.9.6
|
||||
+10038
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+7013
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+10598
File diff suppressed because it is too large
Load Diff
+2
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,63 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport"
|
||||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>{{ title }}</title>
|
||||
<link rel="stylesheet" href="/static/bootstrap-4.3.1-dist/css/bootstrap.min.css">
|
||||
<script src="/static/jquery-3.4.1/js/jquery-3.4.1.min.js"></script>
|
||||
<script src="/static/bootstrap-4.3.1-dist/js/bootstrap.bundle.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-dark bg-dark">
|
||||
<span class="navbar-brand mb-0 h1">Ritten</span>
|
||||
</nav>
|
||||
<div class="h-100"></div>
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<h1>Gereden ritten</h1>
|
||||
<div class="col-md-12">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<th scope="col">Naam</th>
|
||||
<th scope="col">Aantal</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for person in persons %}
|
||||
<tr>
|
||||
<td>{{ person.name }}</td>
|
||||
<td>{{ person.amount }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<h2>Nieuwe rit toevoegen</h2>
|
||||
<div class="col-md-12">
|
||||
|
||||
<form action="add" method="post">
|
||||
<div class="form-group">
|
||||
<label for="selectName">Naam</label>
|
||||
<div class="input-group">
|
||||
<select name="name" id="selectName" class="custom-select">
|
||||
{% for person in persons %}
|
||||
<option value="{{ person.name }}">{{ person.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<div class="input-group-append">
|
||||
|
||||
<input type="submit" value="submit" class="btn btn-primary">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user