ready for version 0.2

This commit is contained in:
nocci 2025-04-22 13:45:13 +02:00
parent 3a79036ec4
commit 4bebbb27e4
9 changed files with 157 additions and 37 deletions

View File

@ -317,7 +317,6 @@ DOCKER_END
# 6. docker-compose.yml
cat <<COMPOSE_END > docker-compose.yml
version: '3.8'
services:
steam-manager:

View File

@ -1,9 +1,7 @@
FROM python:3.10-slim
# Shell explizit setzen
SHELL ["/bin/bash", "-c"]
# Datenbankordner erstellen und Berechtigungen setzen
RUN mkdir -p /app/data && chmod -R a+rwX /app/data
WORKDIR /app
@ -14,7 +12,6 @@ COPY . .
ARG UID=1000
ARG GID=1000
RUN groupadd -g $GID appuser && useradd -u $UID -g $GID -m appuser && chown -R appuser:appuser /app
USER appuser

View File

@ -1,10 +1,12 @@
from flask import Flask, render_template, request, redirect, url_for, flash, make_response, session, abort
from flask import Flask, render_template, request, redirect, url_for, flash, make_response, session, abort, send_file
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager, UserMixin, login_user, logout_user, login_required, current_user
from flask_babel import Babel, _
from werkzeug.security import generate_password_hash, check_password_hash
from datetime import datetime
import os
import io
import csv
app = Flask(__name__)
app.config['SECRET_KEY'] = os.urandom(24)
@ -14,7 +16,6 @@ app.config['BABEL_DEFAULT_LOCALE'] = 'de'
app.config['BABEL_SUPPORTED_LOCALES'] = ['de', 'en']
app.config['BABEL_TRANSLATION_DIRECTORIES'] = 'translations'
db = SQLAlchemy(app)
login_manager = LoginManager(app)
login_manager.login_view = 'login'
@ -138,7 +139,7 @@ def add_game():
recipient=request.form.get('recipient', ''),
notes=request.form.get('notes', ''),
url=url,
steam_appid=steam_appid, # <- jetzt wird sie gesetzt!
steam_appid=steam_appid,
redeem_date=datetime.strptime(request.form['redeem_date'], '%Y-%m-%d') if request.form['redeem_date'] else None,
user_id=current_user.id
)
@ -151,45 +152,37 @@ def add_game():
flash(_('Error: ') + str(e), 'danger')
return render_template('add_game.html')
@app.route('/edit/<int:game_id>', methods=['GET', 'POST'])
@login_required
def edit_game(game_id):
game = db.session.get(Game, game_id) # SQLAlchemy 2.x-kompatibel
game = db.session.get(Game, game_id)
if not game or game.owner != current_user:
return _("Not allowed!"), 403
if request.method == 'POST':
try:
# Steam AppID aus Formular oder URL extrahieren
url = request.form.get('url', '')
steam_appid = request.form.get('steam_appid', '').strip()
if not steam_appid:
steam_appid = extract_steam_appid(url)
# Aktualisiere alle Felder
game.name = request.form['name']
game.steam_key = request.form['steam_key']
game.status = request.form['status']
game.recipient = request.form.get('recipient', '')
game.notes = request.form.get('notes', '')
game.url = url
game.steam_appid = steam_appid # <- FEHLTE HIER
game.steam_appid = steam_appid
game.redeem_date = datetime.strptime(request.form['redeem_date'], '%Y-%m-%d') if request.form['redeem_date'] else None
db.session.commit()
flash(_('Changes saved!'), 'success')
return redirect(url_for('index'))
except Exception as e:
db.session.rollback()
flash(_('Error: ') + str(e), 'danger')
return render_template('edit_game.html',
game=game,
redeem_date=game.redeem_date.strftime('%Y-%m-%d') if game.redeem_date else '')
@app.route('/delete/<int:game_id>', methods=['POST'])
@login_required
def delete_game(game_id):
@ -205,6 +198,57 @@ def delete_game(game_id):
flash(_('Error deleting: ') + str(e), 'danger')
return redirect(url_for('index'))
# --- Import/Export Funktionen ---
@app.route('/export', methods=['GET'])
@login_required
def export_games():
games = Game.query.filter_by(user_id=current_user.id).all()
output = io.StringIO()
writer = csv.writer(output)
writer.writerow(['Name', 'Steam Key', 'Status', 'Recipient', 'Notes', 'URL', 'Created', 'Redeem by', 'Steam AppID'])
for game in games:
writer.writerow([
game.name, game.steam_key, game.status, game.recipient, game.notes,
game.url, game.created_at.strftime('%Y-%m-%d %H:%M:%S') if game.created_at else '',
game.redeem_date.strftime('%Y-%m-%d') if game.redeem_date else '',
game.steam_appid
])
output.seek(0)
return send_file(
io.BytesIO(output.getvalue().encode('utf-8')),
mimetype='text/csv',
as_attachment=True,
download_name='games_export.csv'
)
@app.route('/import', methods=['GET', 'POST'])
@login_required
def import_games():
if request.method == 'POST':
file = request.files.get('file')
if file and file.filename.endswith('.csv'):
stream = io.StringIO(file.stream.read().decode("UTF8"), newline=None)
reader = csv.DictReader(stream)
for row in reader:
new_game = Game(
name=row['Name'],
steam_key=row['Steam Key'],
status=row['Status'],
recipient=row.get('Recipient', ''),
notes=row.get('Notes', ''),
url=row.get('URL', ''),
created_at=datetime.strptime(row['Created'], '%Y-%m-%d %H:%M:%S') if row.get('Created') else datetime.utcnow(),
redeem_date=datetime.strptime(row['Redeem by'], '%Y-%m-%d') if row.get('Redeem by') else None,
steam_appid=row.get('Steam AppID', ''),
user_id=current_user.id
)
db.session.add(new_game)
db.session.commit()
flash(_('Import erfolgreich!'), 'success')
return redirect(url_for('index'))
flash(_('Bitte eine gültige CSV-Datei hochladen.'), 'danger')
return render_template('import.html')
if __name__ == '__main__':
with app.app_context():

View File

@ -45,6 +45,8 @@
</ul>
</div>
{% if current_user.is_authenticated %}
<a href="{{ url_for('export_games') }}" class="btn btn-outline-secondary">⬇️ {{ _('Export') }}</a>
<a href="{{ url_for('import_games') }}" class="btn btn-outline-secondary">⬆️ {{ _('Import') }}</a>
<a href="{{ url_for('logout') }}" class="btn btn-danger ms-3">{{ _('Logout') }}</a>
{% endif %}
</div>

View File

@ -0,0 +1,14 @@
{% extends "base.html" %}
{% block content %}
<div class="card p-4 shadow-sm">
<h2 class="mb-4">{{ _('Import Games') }}</h2>
<form method="POST" enctype="multipart/form-data">
<div class="mb-3">
<label class="form-label">{{ _('CSV-Datei auswählen') }}</label>
<input type="file" name="file" class="form-control" accept=".csv" required>
</div>
<button type="submit" class="btn btn-success">{{ _('Importieren') }}</button>
<a href="{{ url_for('index') }}" class="btn btn-outline-secondary">{{ _('Abbrechen') }}</a>
</form>
</div>
{% endblock %}

View File

@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2025-04-21 11:24+0000\n"
"PO-Revision-Date: 2025-04-21 11:24+0000\n"
"POT-Creation-Date: 2025-04-22 11:22+0000\n"
"PO-Revision-Date: 2025-04-22 11:22+0000\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en\n"
"Language-Team: en <LL@li.org>\n"
@ -18,38 +18,46 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.17.0\n"
#: app.py:93
#: app.py:94
msgid "Invalid credentials"
msgstr ""
#: app.py:102
#: app.py:103
msgid "Username already exists"
msgstr ""
#: app.py:147
#: app.py:148
msgid "Game added successfully!"
msgstr ""
#: app.py:151 app.py:186
#: app.py:152 app.py:181
msgid "Error: "
msgstr ""
#: app.py:160 app.py:198
#: app.py:160 app.py:191
msgid "Not allowed!"
msgstr ""
#: app.py:181
#: app.py:177
msgid "Changes saved!"
msgstr ""
#: app.py:202
#: app.py:195
msgid "Game deleted!"
msgstr ""
#: app.py:205
#: app.py:198
msgid "Error deleting: "
msgstr ""
#: app.py:248
msgid "Import erfolgreich!"
msgstr ""
#: app.py:250
msgid "Bitte eine gültige CSV-Datei hochladen."
msgstr ""
#: templates/add_game.html:4 templates/index.html:6
msgid "Add New Game"
msgstr ""
@ -120,6 +128,14 @@ msgid "Dark Mode"
msgstr ""
#: templates/base.html:48
msgid "Export"
msgstr ""
#: templates/base.html:49
msgid "Import"
msgstr ""
#: templates/base.html:50
msgid "Logout"
msgstr ""
@ -131,6 +147,22 @@ msgstr ""
msgid "Steam AppID (optional)"
msgstr ""
#: templates/import.html:4
msgid "Import Games"
msgstr ""
#: templates/import.html:7
msgid "CSV-Datei auswählen"
msgstr ""
#: templates/import.html:10
msgid "Importieren"
msgstr ""
#: templates/import.html:11
msgid "Abbrechen"
msgstr ""
#: templates/index.html:4
msgid "My Games"
msgstr ""

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2025-04-21 11:24+0000\n"
"POT-Creation-Date: 2025-04-22 11:22+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -17,38 +17,46 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.17.0\n"
#: app.py:93
#: app.py:94
msgid "Invalid credentials"
msgstr ""
#: app.py:102
#: app.py:103
msgid "Username already exists"
msgstr ""
#: app.py:147
#: app.py:148
msgid "Game added successfully!"
msgstr ""
#: app.py:151 app.py:186
#: app.py:152 app.py:181
msgid "Error: "
msgstr ""
#: app.py:160 app.py:198
#: app.py:160 app.py:191
msgid "Not allowed!"
msgstr ""
#: app.py:181
#: app.py:177
msgid "Changes saved!"
msgstr ""
#: app.py:202
#: app.py:195
msgid "Game deleted!"
msgstr ""
#: app.py:205
#: app.py:198
msgid "Error deleting: "
msgstr ""
#: app.py:248
msgid "Import erfolgreich!"
msgstr ""
#: app.py:250
msgid "Bitte eine gültige CSV-Datei hochladen."
msgstr ""
#: templates/add_game.html:4 templates/index.html:6
msgid "Add New Game"
msgstr ""
@ -119,6 +127,14 @@ msgid "Dark Mode"
msgstr ""
#: templates/base.html:48
msgid "Export"
msgstr ""
#: templates/base.html:49
msgid "Import"
msgstr ""
#: templates/base.html:50
msgid "Logout"
msgstr ""
@ -130,6 +146,22 @@ msgstr ""
msgid "Steam AppID (optional)"
msgstr ""
#: templates/import.html:4
msgid "Import Games"
msgstr ""
#: templates/import.html:7
msgid "CSV-Datei auswählen"
msgstr ""
#: templates/import.html:10
msgid "Importieren"
msgstr ""
#: templates/import.html:11
msgid "Abbrechen"
msgstr ""
#: templates/index.html:4
msgid "My Games"
msgstr ""