mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-10 15:07:35 +01:00
Use consistent quotes
This commit is contained in:
parent
9ddc29e41f
commit
0385590922
@ -5,10 +5,10 @@ from flask.ext import markdown
|
|||||||
from flask_github import GitHub
|
from flask_github import GitHub
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config.from_pyfile('../config.cfg')
|
app.config.from_pyfile("../config.cfg")
|
||||||
|
|
||||||
menu.Menu(app=app)
|
menu.Menu(app=app)
|
||||||
markdown.Markdown(app, extensions=['fenced_code'])
|
markdown.Markdown(app, extensions=["fenced_code"])
|
||||||
github = GitHub(app)
|
github = GitHub(app)
|
||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
|
@ -54,8 +54,8 @@ class User(db.Model, UserMixin):
|
|||||||
|
|
||||||
# User authentication information
|
# User authentication information
|
||||||
username = db.Column(db.String(50), nullable=False, unique=True)
|
username = db.Column(db.String(50), nullable=False, unique=True)
|
||||||
password = db.Column(db.String(255), nullable=False, server_default='')
|
password = db.Column(db.String(255), nullable=False, server_default="")
|
||||||
reset_password_token = db.Column(db.String(100), nullable=False, server_default='')
|
reset_password_token = db.Column(db.String(100), nullable=False, server_default="")
|
||||||
|
|
||||||
rank = db.Column(db.Enum(UserRank))
|
rank = db.Column(db.Enum(UserRank))
|
||||||
|
|
||||||
@ -68,11 +68,11 @@ class User(db.Model, UserMixin):
|
|||||||
confirmed_at = db.Column(db.DateTime())
|
confirmed_at = db.Column(db.DateTime())
|
||||||
|
|
||||||
# User information
|
# User information
|
||||||
active = db.Column('is_active', db.Boolean, nullable=False, server_default='0')
|
active = db.Column("is_active", db.Boolean, nullable=False, server_default="0")
|
||||||
display_name = db.Column(db.String(100), nullable=False, server_default='')
|
display_name = db.Column(db.String(100), nullable=False, server_default="")
|
||||||
|
|
||||||
# Content
|
# Content
|
||||||
packages = db.relationship('Package', backref='author', lazy='dynamic')
|
packages = db.relationship("Package", backref="author", lazy="dynamic")
|
||||||
|
|
||||||
def __init__(self, username):
|
def __init__(self, username):
|
||||||
import datetime
|
import datetime
|
||||||
@ -108,7 +108,7 @@ class Package(db.Model):
|
|||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
|
||||||
# Basic details
|
# Basic details
|
||||||
author_id = db.Column(db.Integer, db.ForeignKey('user.id'))
|
author_id = db.Column(db.Integer, db.ForeignKey("user.id"))
|
||||||
name = db.Column(db.String(100), nullable=False)
|
name = db.Column(db.String(100), nullable=False)
|
||||||
title = db.Column(db.String(100), nullable=False)
|
title = db.Column(db.String(100), nullable=False)
|
||||||
shortDesc = db.Column(db.String(200), nullable=False)
|
shortDesc = db.Column(db.String(200), nullable=False)
|
||||||
@ -124,8 +124,8 @@ class Package(db.Model):
|
|||||||
forums = db.Column(db.Integer, nullable=False)
|
forums = db.Column(db.Integer, nullable=False)
|
||||||
|
|
||||||
# Releases
|
# Releases
|
||||||
releases = db.relationship('PackageRelease', backref='package',
|
releases = db.relationship("PackageRelease", backref="package",
|
||||||
lazy='dynamic', order_by=db.desc("package_release_releaseDate"))
|
lazy="dynamic", order_by=db.desc("package_release_releaseDate"))
|
||||||
|
|
||||||
def getDetailsURL(self):
|
def getDetailsURL(self):
|
||||||
return url_for("package_page",
|
return url_for("package_page",
|
||||||
@ -180,7 +180,7 @@ class Package(db.Model):
|
|||||||
class PackageRelease(db.Model):
|
class PackageRelease(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
|
||||||
package_id = db.Column(db.Integer, db.ForeignKey('package.id'))
|
package_id = db.Column(db.Integer, db.ForeignKey("package.id"))
|
||||||
title = db.Column(db.String(100), nullable=False)
|
title = db.Column(db.String(100), nullable=False)
|
||||||
releaseDate = db.Column(db.DateTime, nullable=False)
|
releaseDate = db.Column(db.DateTime, nullable=False)
|
||||||
url = db.Column(db.String(100), nullable=False)
|
url = db.Column(db.String(100), nullable=False)
|
||||||
|
@ -15,13 +15,13 @@ def domain(url):
|
|||||||
return urlparse(url).netloc
|
return urlparse(url).netloc
|
||||||
|
|
||||||
# TODO: remove on production!
|
# TODO: remove on production!
|
||||||
@app.route('/static/<path:path>')
|
@app.route("/static/<path:path>")
|
||||||
def send_static(path):
|
def send_static(path):
|
||||||
return send_from_directory('static', path)
|
return send_from_directory("static", path)
|
||||||
|
|
||||||
@app.route('/')
|
@app.route("/")
|
||||||
@menu.register_menu(app, '.', 'Home')
|
@menu.register_menu(app, ".", "Home")
|
||||||
def home_page():
|
def home_page():
|
||||||
return render_template('index.html')
|
return render_template("index.html")
|
||||||
|
|
||||||
from . import users, githublogin, packages
|
from . import users, githublogin, packages
|
||||||
|
@ -7,7 +7,7 @@ from app import app, github
|
|||||||
from app.models import *
|
from app.models import *
|
||||||
|
|
||||||
|
|
||||||
@app.route('/user/github/start/')
|
@app.route("/user/github/start/")
|
||||||
def github_signin_page():
|
def github_signin_page():
|
||||||
return github.authorize("public_repo,repo")
|
return github.authorize("public_repo,repo")
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ def _do_login_user(user, remember_me=False):
|
|||||||
|
|
||||||
# Check if user account has been disabled
|
# Check if user account has been disabled
|
||||||
if not _call_or_get(user.is_active):
|
if not _call_or_get(user.is_active):
|
||||||
flash('Your account has not been enabled.', 'error')
|
flash("Your account has not been enabled.", "error")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Check if user has a confirmed email address
|
# Check if user has a confirmed email address
|
||||||
@ -36,15 +36,15 @@ def _do_login_user(user, remember_me=False):
|
|||||||
if user_manager.enable_email and user_manager.enable_confirm_email \
|
if user_manager.enable_email and user_manager.enable_confirm_email \
|
||||||
and not current_app.user_manager.enable_login_without_confirm_email \
|
and not current_app.user_manager.enable_login_without_confirm_email \
|
||||||
and not user.has_confirmed_email():
|
and not user.has_confirmed_email():
|
||||||
url = url_for('user.resend_confirm_email')
|
url = url_for("user.resend_confirm_email")
|
||||||
flash("Your email address has not yet been confirmed", 'error')
|
flash("Your email address has not yet been confirmed", "error")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Use Flask-Login to sign in user
|
# Use Flask-Login to sign in user
|
||||||
login_user(user, remember=remember_me)
|
login_user(user, remember=remember_me)
|
||||||
signals.user_logged_in.send(current_app._get_current_object(), user=user)
|
signals.user_logged_in.send(current_app._get_current_object(), user=user)
|
||||||
|
|
||||||
flash('You have signed in successfully.', 'success')
|
flash("You have signed in successfully.", "success")
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -59,10 +59,10 @@ def _login_user(user):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/user/github/callback/')
|
@app.route("/user/github/callback/")
|
||||||
@github.authorized_handler
|
@github.authorized_handler
|
||||||
def github_authorized(oauth_token):
|
def github_authorized(oauth_token):
|
||||||
next_url = request.args.get('next')
|
next_url = request.args.get("next")
|
||||||
if oauth_token is None:
|
if oauth_token is None:
|
||||||
flash("Authorization failed [err=gh-oauth-login-failed]", "danger")
|
flash("Authorization failed [err=gh-oauth-login-failed]", "danger")
|
||||||
return redirect(url_for("user.login"))
|
return redirect(url_for("user.login"))
|
||||||
|
@ -24,24 +24,24 @@ def doPackageList(type):
|
|||||||
if search is not None:
|
if search is not None:
|
||||||
query = query.filter(Package.title.contains(search))
|
query = query.filter(Package.title.contains(search))
|
||||||
|
|
||||||
return render_template('packages.html', title=title, packages=query.all(), query=search)
|
return render_template("packages.html", title=title, packages=query.all(), query=search)
|
||||||
|
|
||||||
@app.route('/packages/')
|
@app.route("/packages/")
|
||||||
def packages_page():
|
def packages_page():
|
||||||
return doPackageList(None)
|
return doPackageList(None)
|
||||||
|
|
||||||
@app.route('/mods/')
|
@app.route("/mods/")
|
||||||
@menu.register_menu(app, '.mods', 'Mods', order=11)
|
@menu.register_menu(app, ".mods", "Mods", order=11)
|
||||||
def mods_page():
|
def mods_page():
|
||||||
return doPackageList(PackageType.MOD)
|
return doPackageList(PackageType.MOD)
|
||||||
|
|
||||||
@app.route('/games/')
|
@app.route("/games/")
|
||||||
@menu.register_menu(app, '.games', 'Games', order=12)
|
@menu.register_menu(app, ".games", "Games", order=12)
|
||||||
def games_page():
|
def games_page():
|
||||||
return doPackageList(PackageType.GAME)
|
return doPackageList(PackageType.GAME)
|
||||||
|
|
||||||
@app.route('/texturepacks/')
|
@app.route("/texturepacks/")
|
||||||
@menu.register_menu(app, '.txp', 'Texture Packs', order=13)
|
@menu.register_menu(app, ".txp", "Texture Packs", order=13)
|
||||||
def txp_page():
|
def txp_page():
|
||||||
return doPackageList(PackageType.TXP)
|
return doPackageList(PackageType.TXP)
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ def canSeeWorkQueue():
|
|||||||
Permission.APPROVE_RELEASE.check(current_user) or \
|
Permission.APPROVE_RELEASE.check(current_user) or \
|
||||||
Permission.APPROVE_CHANGES.check(current_user)
|
Permission.APPROVE_CHANGES.check(current_user)
|
||||||
|
|
||||||
@menu.register_menu(app, '.todo', "Work Queue", order=20, visible_when=canSeeWorkQueue)
|
@menu.register_menu(app, ".todo", "Work Queue", order=20, visible_when=canSeeWorkQueue)
|
||||||
@app.route("/todo/")
|
@app.route("/todo/")
|
||||||
@login_required
|
@login_required
|
||||||
def todo_page():
|
def todo_page():
|
||||||
@ -65,7 +65,7 @@ def todo_page():
|
|||||||
if canApproveRel:
|
if canApproveRel:
|
||||||
releases = PackageRelease.query.filter_by(approved=False).all()
|
releases = PackageRelease.query.filter_by(approved=False).all()
|
||||||
|
|
||||||
return render_template('todo.html', title="Reports and Work Queue",
|
return render_template("todo.html", title="Reports and Work Queue",
|
||||||
approve_new=packages, releases=releases,
|
approve_new=packages, releases=releases,
|
||||||
canApproveNew=canApproveNew, canApproveRel=canApproveRel)
|
canApproveNew=canApproveNew, canApproveRel=canApproveRel)
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ def package_page(type, author, name):
|
|||||||
package = getPageByInfo(type, author, name)
|
package = getPageByInfo(type, author, name)
|
||||||
releases = getReleases(package)
|
releases = getReleases(package)
|
||||||
|
|
||||||
return render_template('package_details.html', package=package, releases=releases)
|
return render_template("package_details.html", package=package, releases=releases)
|
||||||
|
|
||||||
|
|
||||||
class PackageForm(FlaskForm):
|
class PackageForm(FlaskForm):
|
||||||
@ -107,11 +107,11 @@ class PackageForm(FlaskForm):
|
|||||||
website = StringField("Website URL", [Optional(), URL()])
|
website = StringField("Website URL", [Optional(), URL()])
|
||||||
issueTracker = StringField("Issue Tracker URL", [Optional(), URL()])
|
issueTracker = StringField("Issue Tracker URL", [Optional(), URL()])
|
||||||
forums = IntegerField("Forum Topic ID", [InputRequired(), NumberRange(0,999999)])
|
forums = IntegerField("Forum Topic ID", [InputRequired(), NumberRange(0,999999)])
|
||||||
submit = SubmitField('Save')
|
submit = SubmitField("Save")
|
||||||
|
|
||||||
@menu.register_menu(app, '.new', 'Create', order=21, visible_when=lambda: current_user.is_authenticated)
|
@menu.register_menu(app, ".new", "Create", order=21, visible_when=lambda: current_user.is_authenticated)
|
||||||
@app.route("/new/", methods=['GET', 'POST'])
|
@app.route("/new/", methods=["GET", "POST"])
|
||||||
@app.route("/<type>s/<author>/<name>/edit/", methods=['GET', 'POST'])
|
@app.route("/<type>s/<author>/<name>/edit/", methods=["GET", "POST"])
|
||||||
@login_required
|
@login_required
|
||||||
def create_edit_package_page(type=None, author=None, name=None):
|
def create_edit_package_page(type=None, author=None, name=None):
|
||||||
package = None
|
package = None
|
||||||
@ -137,7 +137,7 @@ def create_edit_package_page(type=None, author=None, name=None):
|
|||||||
db.session.commit() # save
|
db.session.commit() # save
|
||||||
return redirect(package.getDetailsURL()) # redirect
|
return redirect(package.getDetailsURL()) # redirect
|
||||||
|
|
||||||
return render_template('package_create_edit.html', package=package, form=form)
|
return render_template("package_create_edit.html", package=package, form=form)
|
||||||
|
|
||||||
@app.route("/<type>s/<author>/<name>/approve/")
|
@app.route("/<type>s/<author>/<name>/approve/")
|
||||||
@login_required
|
@login_required
|
||||||
@ -163,16 +163,16 @@ class CreatePackageReleaseForm(FlaskForm):
|
|||||||
uploadOpt = RadioField ("File", choices=[("vcs", "From VCS Commit or Branch"), ("upload", "File Upload")])
|
uploadOpt = RadioField ("File", choices=[("vcs", "From VCS Commit or Branch"), ("upload", "File Upload")])
|
||||||
vcsLabel = StringField("VCS Commit or Branch", default="master")
|
vcsLabel = StringField("VCS Commit or Branch", default="master")
|
||||||
fileUpload = FileField("File Upload")
|
fileUpload = FileField("File Upload")
|
||||||
submit = SubmitField('Save')
|
submit = SubmitField("Save")
|
||||||
|
|
||||||
class EditPackageReleaseForm(FlaskForm):
|
class EditPackageReleaseForm(FlaskForm):
|
||||||
name = StringField("Name")
|
name = StringField("Name")
|
||||||
title = StringField("Title")
|
title = StringField("Title")
|
||||||
url = StringField("URL", [URL])
|
url = StringField("URL", [URL])
|
||||||
approved = BooleanField("Is Approved")
|
approved = BooleanField("Is Approved")
|
||||||
submit = SubmitField('Save')
|
submit = SubmitField("Save")
|
||||||
|
|
||||||
@app.route("/<type>s/<author>/<name>/releases/new/", methods=['GET', 'POST'])
|
@app.route("/<type>s/<author>/<name>/releases/new/", methods=["GET", "POST"])
|
||||||
@login_required
|
@login_required
|
||||||
def create_release_page(type, author, name):
|
def create_release_page(type, author, name):
|
||||||
package = getPageByInfo(type, author, name)
|
package = getPageByInfo(type, author, name)
|
||||||
@ -193,9 +193,9 @@ def create_release_page(type, author, name):
|
|||||||
else:
|
else:
|
||||||
raise Exception("Unimplemented option = file upload")
|
raise Exception("Unimplemented option = file upload")
|
||||||
|
|
||||||
return render_template('package_release_new.html', package=package, form=form)
|
return render_template("package_release_new.html", package=package, form=form)
|
||||||
|
|
||||||
@app.route("/<type>s/<author>/<name>/releases/<id>/", methods=['GET', 'POST'])
|
@app.route("/<type>s/<author>/<name>/releases/<id>/", methods=["GET", "POST"])
|
||||||
@login_required
|
@login_required
|
||||||
def edit_release_page(type, author, name, id):
|
def edit_release_page(type, author, name, id):
|
||||||
user = User.query.filter_by(username=author).first()
|
user = User.query.filter_by(username=author).first()
|
||||||
@ -233,4 +233,4 @@ def edit_release_page(type, author, name, id):
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
return redirect(package.getDetailsURL())
|
return redirect(package.getDetailsURL())
|
||||||
|
|
||||||
return render_template('package_release_edit.html', package=package, release=release, form=form)
|
return render_template("package_release_edit.html", package=package, release=release, form=form)
|
||||||
|
@ -18,14 +18,14 @@ class MyRegisterForm(RegisterForm):
|
|||||||
# Define the User profile form
|
# Define the User profile form
|
||||||
class UserProfileForm(FlaskForm):
|
class UserProfileForm(FlaskForm):
|
||||||
display_name = StringField("Display name")
|
display_name = StringField("Display name")
|
||||||
submit = SubmitField('Save')
|
submit = SubmitField("Save")
|
||||||
|
|
||||||
@app.route('/user/', methods=['GET'])
|
@app.route("/user/", methods=["GET"])
|
||||||
@login_required
|
@login_required
|
||||||
def self_user_profile_page():
|
def self_user_profile_page():
|
||||||
return redirect(url_for("user_profile_page", username=current_user.username))
|
return redirect(url_for("user_profile_page", username=current_user.username))
|
||||||
|
|
||||||
@app.route('/user/<username>/', methods=['GET', 'POST'])
|
@app.route("/user/<username>/", methods=["GET", "POST"])
|
||||||
def user_profile_page(username):
|
def user_profile_page(username):
|
||||||
user = User.query.filter_by(username=username).first()
|
user = User.query.filter_by(username=username).first()
|
||||||
if not user:
|
if not user:
|
||||||
@ -37,7 +37,7 @@ def user_profile_page(username):
|
|||||||
form = UserProfileForm(formdata=request.form, obj=current_user)
|
form = UserProfileForm(formdata=request.form, obj=current_user)
|
||||||
|
|
||||||
# Process valid POST
|
# Process valid POST
|
||||||
if request.method=='POST' and form.validate():
|
if request.method=="POST" and form.validate():
|
||||||
# Copy form fields to user_profile fields
|
# Copy form fields to user_profile fields
|
||||||
form.populate_obj(current_user)
|
form.populate_obj(current_user)
|
||||||
|
|
||||||
@ -45,8 +45,8 @@ def user_profile_page(username):
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
# Redirect to home page
|
# Redirect to home page
|
||||||
return redirect(url_for('home_page'))
|
return redirect(url_for("home_page"))
|
||||||
|
|
||||||
# Process GET or invalid POST
|
# Process GET or invalid POST
|
||||||
return render_template('users/user_profile_page.html',
|
return render_template("users/user_profile_page.html",
|
||||||
user=user, form=form)
|
user=user, form=form)
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
from app import app
|
from app import app
|
||||||
|
|
||||||
app.run(host='0.0.0.0', port=5000, debug=True)
|
app.run(host="127.0.0.1", port=5000, debug=True)
|
||||||
|
3
runprod.py
Normal file
3
runprod.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
from app import app
|
||||||
|
|
||||||
|
app.run(host="0.0.0.0", port=5123, debug=False)
|
5
setup.py
5
setup.py
@ -17,6 +17,11 @@ if not os.path.isfile("db.sqlite"):
|
|||||||
ruben.rank = UserRank.EDITOR
|
ruben.rank = UserRank.EDITOR
|
||||||
db.session.add(ruben)
|
db.session.add(ruben)
|
||||||
|
|
||||||
|
ez = User("Shara")
|
||||||
|
ez.github_username = "Ezhh"
|
||||||
|
ez.rank = UserRank.EDITOR
|
||||||
|
db.session.add(ez)
|
||||||
|
|
||||||
jeija = User("Jeija")
|
jeija = User("Jeija")
|
||||||
jeija.github_username = "Jeija"
|
jeija.github_username = "Jeija"
|
||||||
db.session.add(jeija)
|
db.session.add(jeija)
|
||||||
|
Loading…
Reference in New Issue
Block a user