mirror of
https://github.com/Derpy-Leggies/OnlyLegs.git
synced 2025-06-29 03:26:16 +00:00
Correct code I did done yesterday
This commit is contained in:
parent
d1b3afdb22
commit
8357241487
10 changed files with 62 additions and 18 deletions
|
@ -58,7 +58,9 @@ def create_app(test_config=None):
|
||||||
UPLOAD_FOLDER=os.path.join(USER_DIR, 'uploads'),
|
UPLOAD_FOLDER=os.path.join(USER_DIR, 'uploads'),
|
||||||
ALLOWED_EXTENSIONS=conf['upload']['allowed-extensions'],
|
ALLOWED_EXTENSIONS=conf['upload']['allowed-extensions'],
|
||||||
MAX_CONTENT_LENGTH=1024 * 1024 * conf['upload']['max-size'],
|
MAX_CONTENT_LENGTH=1024 * 1024 * conf['upload']['max-size'],
|
||||||
WEBSITE=conf['website'],
|
ADMIN_CONF=conf['admin'],
|
||||||
|
UPLOAD_CONF=conf['upload'],
|
||||||
|
WEBSITE_CONF=conf['website'],
|
||||||
)
|
)
|
||||||
|
|
||||||
if test_config is None:
|
if test_config is None:
|
||||||
|
|
|
@ -49,6 +49,48 @@ def file(file_name):
|
||||||
return send_from_directory(os.path.dirname(thumb), os.path.basename(thumb))
|
return send_from_directory(os.path.dirname(thumb), os.path.basename(thumb))
|
||||||
|
|
||||||
|
|
||||||
|
# @blueprint.route('/page', methods=['get'])
|
||||||
|
# def page():
|
||||||
|
# """
|
||||||
|
# Returns a json object with all the images
|
||||||
|
# info required to generate a page
|
||||||
|
# """
|
||||||
|
# page_num = request.args.get('page', default=1, type=int)
|
||||||
|
# limit = current_app.config['UPLOAD_CONF']['max-load']
|
||||||
|
|
||||||
|
# if not page_num:
|
||||||
|
# abort(400, 'No page number specified')
|
||||||
|
# if not isinstance(page_num, int):
|
||||||
|
# abort(400, 'Page number is not a number')
|
||||||
|
# if int(page_num) < 1:
|
||||||
|
# abort(400, 'Page number is less than 1')
|
||||||
|
|
||||||
|
# # get the total number of images in the database
|
||||||
|
# # calculate the total number of pages, and make sure the page number is valid
|
||||||
|
# total_images = db_session.query(db.Posts.id).count()
|
||||||
|
# pages = ceil(max(total_images, limit) / limit)
|
||||||
|
# if page_num > pages:
|
||||||
|
# abort(404, 'You have gone above and beyond, but this isnt a fairy tale.')
|
||||||
|
|
||||||
|
# # get the images for the current page
|
||||||
|
# images = (db_session.query(db.Posts.filename, db.Posts.alt, db.Posts.colours,
|
||||||
|
# db.Posts.created_at, db.Posts.id)
|
||||||
|
# .order_by(db.Posts.id.desc())
|
||||||
|
# .offset((page_num - 1) * limit)
|
||||||
|
# .limit(limit)
|
||||||
|
# .all())
|
||||||
|
# image_list = []
|
||||||
|
# for image in images:
|
||||||
|
# image_list.append({
|
||||||
|
# 'id': image.id,
|
||||||
|
# 'filename': image.filename,
|
||||||
|
# 'alt': image.alt,
|
||||||
|
# 'colours': image.colours,
|
||||||
|
# 'created_at': image.created_at,
|
||||||
|
# })
|
||||||
|
# return jsonify(image_list)
|
||||||
|
|
||||||
|
|
||||||
@blueprint.route('/upload', methods=['POST'])
|
@blueprint.route('/upload', methods=['POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def upload():
|
def upload():
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{% extends 'layout.html' %}
|
{% extends 'layout.html' %}
|
||||||
{% block page_index %}
|
{% block page_index %}
|
||||||
{% if return_page > 1 %}?page={{ return_page }}{% endif %}{% endblock %}
|
{% if return_page %}?page={{ return_page }}{% endif %}{% endblock %}
|
||||||
{% block head %}
|
{% block head %}
|
||||||
<meta property="og:image" content="{{ url_for('api.file', file_name=image.filename) }}"/>
|
<meta property="og:image" content="{{ url_for('api.file', file_name=image.filename) }}"/>
|
||||||
<meta name="theme-color" content="rgb({{ image.colours.0.0 }}{{ image.colours.0.1 }}{{ image.colours.0.2 }})"/>
|
<meta name="theme-color" content="rgb({{ image.colours.0.0 }}{{ image.colours.0.1 }}{{ image.colours.0.2 }})"/>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="banner-small">
|
<div class="banner-small">
|
||||||
<div class="banner-content">
|
<div class="banner-content">
|
||||||
<h1 class="banner-header">{{ config.WEBSITE.name }}</h1>
|
<h1 class="banner-header">{{ config.WEBSITE_CONF.name }}</h1>
|
||||||
{% if total_images == 0 %}
|
{% if total_images == 0 %}
|
||||||
<p class="banner-info">0 images D:</p>
|
<p class="banner-info">0 images D:</p>
|
||||||
{% elif total_images == 69 %}
|
{% elif total_images == 69 %}
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<title>{{ config.WEBSITE.name }}</title>
|
<title>{{ config.WEBSITE_CONF.name }}</title>
|
||||||
|
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<meta name="description" content="{{ config.WEBSITE.motto }}"/>
|
<meta name="description" content="{{ config.WEBSITE_CONF.motto }}"/>
|
||||||
<meta name="author" content="{{ config.WEBSITE.author }}"/>
|
<meta name="author" content="{{ config.WEBSITE_CONF.author }}"/>
|
||||||
|
|
||||||
<meta property="og:title" content="{{ config.WEBSITE.name }}"/>
|
<meta property="og:title" content="{{ config.WEBSITE_CONF.name }}"/>
|
||||||
<meta property="og:description" content="{{ config.WEBSITE.motto }}"/>
|
<meta property="og:description" content="{{ config.WEBSITE_CONF.motto }}"/>
|
||||||
<meta property="og:type" content="website"/>
|
<meta property="og:type" content="website"/>
|
||||||
|
|
||||||
<meta name="twitter:title" content="{{ config.WEBSITE.name }}"/>
|
<meta name="twitter:title" content="{{ config.WEBSITE_CONF.name }}"/>
|
||||||
<meta name="twitter:description" content="{{ config.WEBSITE.motto }}"/>
|
<meta name="twitter:description" content="{{ config.WEBSITE_CONF.motto }}"/>
|
||||||
<meta name="twitter:card" content="summary_large_image">
|
<meta name="twitter:card" content="summary_large_image">
|
||||||
|
|
||||||
<link rel="manifest" href="static/manifest.json"/>
|
<link rel="manifest" href="static/manifest.json"/>
|
||||||
|
|
|
@ -96,7 +96,7 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="banner-small">
|
<div class="banner-small">
|
||||||
<div class="banner-content">
|
<div class="banner-content">
|
||||||
<h1 class="banner-header">{{ config.WEBSITE.name }}</h1>
|
<h1 class="banner-header">{{ config.WEBSITE_CONF.name }}</h1>
|
||||||
{% if groups|length == 0 %}
|
{% if groups|length == 0 %}
|
||||||
<p class="banner-info">No groups!!!!</p>
|
<p class="banner-info">No groups!!!!</p>
|
||||||
{% elif groups|length == 69 %}
|
{% elif groups|length == 69 %}
|
||||||
|
|
|
@ -136,5 +136,4 @@ def group_post(group_id, image_id):
|
||||||
if prev_url:
|
if prev_url:
|
||||||
prev_url = url_for('group.group_post', group_id=group_id, image_id=prev_url[0])
|
prev_url = url_for('group.group_post', group_id=group_id, image_id=prev_url[0])
|
||||||
|
|
||||||
return render_template('image.html', image=image, next_url=next_url,
|
return render_template('image.html', image=image, next_url=next_url, prev_url=prev_url)
|
||||||
prev_url=prev_url, return_page=0)
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ Onlylegs - Image View
|
||||||
"""
|
"""
|
||||||
from math import ceil
|
from math import ceil
|
||||||
|
|
||||||
from flask import Blueprint, abort, render_template, url_for
|
from flask import Blueprint, abort, render_template, url_for, current_app
|
||||||
|
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
from gallery import db
|
from gallery import db
|
||||||
|
@ -63,11 +63,11 @@ def image(image_id):
|
||||||
total_images = (db_session.query(db.Posts.id)
|
total_images = (db_session.query(db.Posts.id)
|
||||||
.order_by(db.Posts.id.desc())
|
.order_by(db.Posts.id.desc())
|
||||||
.all())
|
.all())
|
||||||
limit = 100
|
limit = current_app.config['UPLOAD_CONF']['max-load']
|
||||||
|
|
||||||
# If the number of items is less than the limit, no point of calculating the page
|
# If the number of items is less than the limit, no point of calculating the page
|
||||||
if len(total_images) <= limit:
|
if len(total_images) <= limit:
|
||||||
return_page = 1
|
return_page = None
|
||||||
else:
|
else:
|
||||||
# How many pages should there be
|
# How many pages should there be
|
||||||
for i in range(ceil(len(total_images) / limit)):
|
for i in range(ceil(len(total_images) / limit)):
|
||||||
|
|
|
@ -3,7 +3,7 @@ Onlylegs Gallery - Index view
|
||||||
"""
|
"""
|
||||||
from math import ceil
|
from math import ceil
|
||||||
|
|
||||||
from flask import Blueprint, render_template, request
|
from flask import Blueprint, render_template, request, current_app
|
||||||
from werkzeug.exceptions import abort
|
from werkzeug.exceptions import abort
|
||||||
|
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
|
@ -26,7 +26,7 @@ def index():
|
||||||
|
|
||||||
# pagination, defaults to page 1 if no page is specified
|
# pagination, defaults to page 1 if no page is specified
|
||||||
page = request.args.get('page', default=1, type=int)
|
page = request.args.get('page', default=1, type=int)
|
||||||
limit = 100
|
limit = current_app.config['UPLOAD_CONF']['max-load']
|
||||||
|
|
||||||
# get the total number of images in the database
|
# get the total number of images in the database
|
||||||
# calculate the total number of pages, and make sure the page number is valid
|
# calculate the total number of pages, and make sure the page number is valid
|
||||||
|
|
|
@ -116,6 +116,7 @@ class Configuration:
|
||||||
'webp': 'webp',
|
'webp': 'webp',
|
||||||
},
|
},
|
||||||
'max-size': 69,
|
'max-size': 69,
|
||||||
|
'max-load': 50,
|
||||||
'rename': 'GWA_{{username}}_{{time}}',
|
'rename': 'GWA_{{username}}_{{time}}',
|
||||||
},
|
},
|
||||||
'website': {
|
'website': {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue