Refactor and homepage working
This commit is contained in:
parent
505726c868
commit
00dd65adbe
@ -1,5 +1,5 @@
|
||||
FROM debian
|
||||
|
||||
RUN apt-get update ; apt-get -y upgrade ; \
|
||||
apt-get -y install python3 python3-flask python3-flask-sqlalchemy python3-flask-httpauth python3-pymysql python3-requests python3-bs4 phantomjs ; \
|
||||
apt-get -y install python3 python3-flask python3-flask-sqlalchemy python3-flask-httpauth python3-flaskext.wtf python3-pymysql python3-requests python3-bs4 phantomjs ; \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
38
app.py
38
app.py
@ -1,29 +1,9 @@
|
||||
from os import environ
|
||||
from sys import modules
|
||||
|
||||
import pymysql
|
||||
from flask import Flask
|
||||
from flask_httpauth import HTTPBasicAuth
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||
from flask import redirect, render_template, url_for
|
||||
|
||||
modules["MySQLdb"] = pymysql
|
||||
|
||||
# init DB and migration
|
||||
db_user = environ.get('MYSQL_USER')
|
||||
db_password = environ.get('MYSQL_PASSWORD')
|
||||
db_name = environ.get('MYSQL_DATABASE')
|
||||
db_host = environ.get('MYSQL_HOST')
|
||||
if not db_host or not db_user or not db_password or not db_name:
|
||||
print('Missing connection environment variables')
|
||||
exit()
|
||||
|
||||
app = Flask(__name__)
|
||||
app.wsgi_app = ProxyFix(app.wsgi_app)
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://%s:%s@%s/%s' % (db_user, db_password, db_host, db_name)
|
||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
|
||||
auth = HTTPBasicAuth()
|
||||
db = SQLAlchemy(app)
|
||||
from config import app, auth
|
||||
from models import SearchForm
|
||||
|
||||
|
||||
@auth.verify_password
|
||||
@ -34,8 +14,16 @@ def verify_password(username, password):
|
||||
|
||||
|
||||
@app.route('/')
|
||||
def hello_world():
|
||||
return 'Hello World !'
|
||||
def home():
|
||||
form = SearchForm()
|
||||
if form.validate_on_submit():
|
||||
return redirect(url_for('search', q=form.q))
|
||||
return render_template('home.html', form=form)
|
||||
|
||||
|
||||
@app.route('/search')
|
||||
def search():
|
||||
return 'Hello!'
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
25
config.py
Normal file
25
config.py
Normal file
@ -0,0 +1,25 @@
|
||||
from os import environ, urandom
|
||||
from sys import modules
|
||||
|
||||
import pymysql
|
||||
from flask import Flask
|
||||
from flask_httpauth import HTTPBasicAuth
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
|
||||
modules["MySQLdb"] = pymysql
|
||||
|
||||
# init DB and migration
|
||||
db_user = environ.get('MYSQL_USER')
|
||||
db_password = environ.get('MYSQL_PASSWORD')
|
||||
db_name = environ.get('MYSQL_DATABASE')
|
||||
db_host = environ.get('MYSQL_HOST')
|
||||
if not db_host or not db_user or not db_password or not db_name:
|
||||
print('Missing connection environment variables')
|
||||
exit()
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://%s:%s@%s/%s' % (db_user, db_password, db_host, db_name)
|
||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
|
||||
app.secret_key = urandom(24).hex()
|
||||
auth = HTTPBasicAuth()
|
||||
db = SQLAlchemy(app)
|
10
models.py
10
models.py
@ -1,4 +1,8 @@
|
||||
from app import db
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms.fields.html5 import SearchField
|
||||
from wtforms.validators import DataRequired
|
||||
|
||||
from config import db
|
||||
|
||||
|
||||
class AnimeFolder(db.Model):
|
||||
@ -24,3 +28,7 @@ class AnimeLink(db.Model):
|
||||
vf = db.Column(db.Boolean, nullable=False)
|
||||
title_id = db.Column(db.Integer, db.ForeignKey('title.id'))
|
||||
title = db.relationship('AnimeTitle', back_populates="links")
|
||||
|
||||
|
||||
class SearchForm(FlaskForm):
|
||||
q = SearchField('search', validators=[DataRequired])
|
||||
|
@ -1,6 +1,7 @@
|
||||
Flask==1.0.2
|
||||
Flask-SQLAlchemy==2.1
|
||||
Flask-HTTPAuth==3.2.4
|
||||
Flask-WTF===0.14.2
|
||||
PyMySQL==0.9.3
|
||||
requests==2.21.0
|
||||
beautifulsoup4==4.7.1
|
||||
|
BIN
static/favicons/favicon.ico
Normal file
BIN
static/favicons/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 134 KiB |
3
templates/home.html
Normal file
3
templates/home.html
Normal file
@ -0,0 +1,3 @@
|
||||
{% extends "layout.html" %}
|
||||
{% block title %}Animes torrents search engine{% endblock %}
|
||||
{% block body %}{% endblock %}
|
45
templates/layout.html
Normal file
45
templates/layout.html
Normal file
@ -0,0 +1,45 @@
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=2.0, minimum-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<meta name="description" content="Xefir's animes search engine (っ^‿^)っ">
|
||||
<title>{% block title %}{% endblock %}</title>
|
||||
<link rel="shortcut icon" href="{{ url_for('static', filename='favicons/favicon.ico') }}">
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/bulma.min.css') }}">
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/bulma-tooltip.min.css') }}">
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/font-awesome.min.css') }}">
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar is-dark" role="navigation" aria-label="main navigation">
|
||||
<div class="navbar-start">
|
||||
{% block internal_buttons %}{% endblock %}
|
||||
{% block external_buttons %}{% endblock %}
|
||||
{% block add_button %}{% endblock %}
|
||||
</div>
|
||||
<div class="navbar-end">
|
||||
<form action="{{ url_for('search') }}" class="navbar-item">
|
||||
{{ form.csrf_token }}
|
||||
<div class="field has-addons">
|
||||
<div class="control">
|
||||
{{ form.q(placeholder='Search ...', class='input') }}
|
||||
</div>
|
||||
<div class="control">
|
||||
<button type="submit" class="button is-info">
|
||||
<i class="fa fa-search"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<section class="section" role="main">
|
||||
{% block body %}{% endblock %}
|
||||
</section>
|
||||
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user