mirror of
https://github.com/minetest/contentdb.git
synced 2024-12-22 22:12:24 +01:00
Add package types
This commit is contained in:
parent
ae600582a0
commit
bc88027fbe
@ -9,7 +9,7 @@ First create a Python virtual env:
|
||||
|
||||
then use pip:
|
||||
|
||||
pip install -r requirements.txt
|
||||
pip3 install -r requirements.txt
|
||||
|
||||
## Running
|
||||
|
||||
@ -20,11 +20,11 @@ the current session:
|
||||
|
||||
Reset the database like so:
|
||||
|
||||
python setup.py -d
|
||||
python3 setup.py -d
|
||||
|
||||
Then run the server:
|
||||
|
||||
python rundebug.py
|
||||
python3 rundebug.py
|
||||
|
||||
Then view in your web browser:
|
||||
|
||||
|
@ -11,4 +11,5 @@ menu.Menu(app=app)
|
||||
markdown.Markdown(app, extensions=['fenced_code'])
|
||||
github = GitHub(app)
|
||||
|
||||
import models, views
|
||||
from . import models
|
||||
from .views import *
|
||||
|
@ -4,6 +4,7 @@ from app import app
|
||||
from datetime import datetime
|
||||
from sqlalchemy.orm import validates
|
||||
from flask_user import login_required, UserManager, UserMixin, SQLAlchemyAdapter
|
||||
import enum
|
||||
|
||||
# Initialise database
|
||||
db = SQLAlchemy(app)
|
||||
@ -57,6 +58,19 @@ class UserRoles(db.Model):
|
||||
user_id = db.Column(db.Integer(), db.ForeignKey('user.id', ondelete='CASCADE'))
|
||||
role_id = db.Column(db.Integer(), db.ForeignKey('role.id', ondelete='CASCADE'))
|
||||
|
||||
class PackageType(enum.Enum):
|
||||
MOD = "Mod"
|
||||
GAME = "Game"
|
||||
TXP = "Texture Pack"
|
||||
|
||||
def getTitle(self):
|
||||
if self == PackageType.MOD:
|
||||
return "Mod"
|
||||
elif self == PackageType.GAME:
|
||||
return "Game"
|
||||
else:
|
||||
return "TXP"
|
||||
|
||||
class Package(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
|
||||
@ -65,6 +79,7 @@ class Package(db.Model):
|
||||
name = db.Column(db.String(100), nullable=False)
|
||||
title = db.Column(db.String(100), nullable=False)
|
||||
desc = db.Column(db.Text, nullable=True)
|
||||
type = db.Column(db.Enum(PackageType))
|
||||
|
||||
# Downloads
|
||||
repo = db.Column(db.String(200), nullable=True)
|
||||
|
@ -7,7 +7,7 @@
|
||||
{% block content %}
|
||||
<ul>
|
||||
{% for p in packages %}
|
||||
<li><a href="{{ url_for('package_page', type='mod', author=p.author.username, name=p.name) }}">
|
||||
<li><a href="{{ url_for('package_page', type=p.type.getTitle()|lower, author=p.author.username, name=p.name) }}">
|
||||
{{ p.title }} by {{ p.author.display_name }}
|
||||
</a></li>
|
||||
{% else %}
|
||||
|
@ -14,9 +14,9 @@ cache = SimpleCache()
|
||||
def send_static(path):
|
||||
return send_from_directory('static', path)
|
||||
|
||||
import users, githublogin, mods
|
||||
|
||||
@app.route('/')
|
||||
@menu.register_menu(app, '.', 'Home')
|
||||
def home_page():
|
||||
return render_template('index.html')
|
||||
|
||||
from . import users, githublogin, packages
|
||||
|
@ -7,9 +7,21 @@ from app.models import *
|
||||
@app.route('/mods/')
|
||||
@menu.register_menu(app, '.mods', 'Mods')
|
||||
def mods_page():
|
||||
packages = Package.query.all()
|
||||
packages = Package.query.filter_by(type=PackageType.MOD).all()
|
||||
return render_template('packages.html', title="Mods", packages=packages)
|
||||
|
||||
@app.route('/games/')
|
||||
@menu.register_menu(app, '.games', 'Games')
|
||||
def games_page():
|
||||
packages = Package.query.filter_by(type=PackageType.GAME).all()
|
||||
return render_template('packages.html', title="Games", packages=packages)
|
||||
|
||||
@app.route('/texturepacks/')
|
||||
@menu.register_menu(app, '.txp', 'Texture Packs')
|
||||
def txp_page():
|
||||
packages = Package.query.filter_by(type=PackageType.TXP).all()
|
||||
return render_template('packages.html', title="Texture Packs", packages=packages)
|
||||
|
||||
@app.route("/<type>s/<author>/<name>/")
|
||||
def package_page(type, author, name):
|
||||
package = Package.query.filter_by(name=name).first()
|
||||
|
1
setup.py
1
setup.py
@ -19,6 +19,7 @@ if not os.path.isfile("db.sqlite"):
|
||||
mod1 = Package()
|
||||
mod1.name = "awards"
|
||||
mod1.title = "Awards"
|
||||
mod1.type = PackageType.MOD
|
||||
mod1.author = ruben
|
||||
mod1.description = "Adds achievements and an API to register new ones."
|
||||
mod1.repo = "https://github.com/rubenwardy/awards"
|
||||
|
Loading…
Reference in New Issue
Block a user