2023-01-10 18:12:55 +00:00
|
|
|
from flask import Blueprint, flash, g, redirect, render_template, request, url_for, jsonify, current_app
|
2023-01-10 14:40:43 +00:00
|
|
|
from werkzeug.exceptions import abort
|
|
|
|
from werkzeug.utils import secure_filename
|
|
|
|
from gallery.auth import login_required
|
|
|
|
from gallery.db import get_db
|
2023-01-10 15:41:39 +00:00
|
|
|
import os
|
2023-01-10 18:12:55 +00:00
|
|
|
import datetime
|
|
|
|
dt = datetime.datetime.now()
|
|
|
|
|
2023-01-10 14:40:43 +00:00
|
|
|
blueprint = Blueprint('gallery', __name__)
|
|
|
|
|
|
|
|
|
|
|
|
@blueprint.route('/')
|
|
|
|
def index():
|
2023-01-10 18:12:55 +00:00
|
|
|
db = get_db()
|
|
|
|
images = db.execute(
|
|
|
|
'SELECT * FROM posts'
|
|
|
|
' ORDER BY created_at DESC'
|
|
|
|
).fetchall()
|
|
|
|
|
|
|
|
return render_template('index.html', images=images)
|
2023-01-10 14:40:43 +00:00
|
|
|
|
|
|
|
@blueprint.route('/group')
|
|
|
|
def groups():
|
2023-01-11 10:53:01 +00:00
|
|
|
return render_template('group.html', group_id='gwa gwa')
|
2023-01-10 14:40:43 +00:00
|
|
|
|
|
|
|
@blueprint.route('/group/<int:id>')
|
|
|
|
def group(id):
|
2023-01-11 10:53:01 +00:00
|
|
|
return render_template('group.html', group_id=id)
|
2023-01-10 14:40:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
@blueprint.route('/upload', methods=('GET', 'POST'))
|
|
|
|
@login_required
|
|
|
|
def upload():
|
|
|
|
if request.method == 'POST':
|
|
|
|
file = request.files['file']
|
|
|
|
form = request.form
|
|
|
|
|
2023-01-10 15:41:39 +00:00
|
|
|
if not file:
|
2023-01-10 14:40:43 +00:00
|
|
|
flash('No selected file')
|
2023-01-10 15:41:39 +00:00
|
|
|
return abort(404)
|
2023-01-11 15:25:35 +00:00
|
|
|
if not secure_filename(file.filename).lower().split('.')[-1] in current_app.config['ALLOWED_EXTENSIONS']:
|
|
|
|
abort(403)
|
|
|
|
|
|
|
|
file_name = file_name = f"GWAGWA_{dt.year}{dt.month}{dt.day}-{dt.microsecond}.{secure_filename(file.filename).lower().split('.')[-1]}"
|
|
|
|
file.save(os.path.join(current_app.config['UPLOAD_FOLDER']+'/original', file_name))
|
2023-01-10 18:12:55 +00:00
|
|
|
|
|
|
|
db = get_db()
|
|
|
|
db.execute(
|
|
|
|
'INSERT INTO posts (file_name, author_id, description, alt)'
|
|
|
|
' VALUES (?, ?, ?, ?)',
|
|
|
|
(file_name, g.user['id'], form['description'], form['alt'])
|
|
|
|
)
|
|
|
|
db.commit()
|
2023-01-10 15:41:39 +00:00
|
|
|
|
2023-01-10 18:12:55 +00:00
|
|
|
return 'Gwa Gwa'
|
2023-01-11 10:53:01 +00:00
|
|
|
|
|
|
|
# GET, or in human language, when you visit the page
|
2023-01-10 14:40:43 +00:00
|
|
|
return render_template('upload.html')
|
|
|
|
|
|
|
|
|
|
|
|
@blueprint.route('/profile')
|
|
|
|
def profile():
|
|
|
|
return render_template('profile.html', user_id='gwa gwa')
|
|
|
|
|
|
|
|
|
|
|
|
@blueprint.route('/profile/<int:id>')
|
|
|
|
def profile_id(id):
|
|
|
|
return render_template('profile.html', user_id=id)
|
|
|
|
|
|
|
|
|
|
|
|
@blueprint.route('/settings')
|
|
|
|
@login_required
|
|
|
|
def settings():
|
|
|
|
return render_template('settings.html')
|