Add package types

This commit is contained in:
rubenwardy 2018-03-20 00:44:47 +00:00
parent ae600582a0
commit bc88027fbe
7 changed files with 45 additions and 16 deletions

@ -9,7 +9,7 @@ First create a Python virtual env:
then use pip: then use pip:
pip install -r requirements.txt pip3 install -r requirements.txt
## Running ## Running
@ -20,11 +20,11 @@ the current session:
Reset the database like so: Reset the database like so:
python setup.py -d python3 setup.py -d
Then run the server: Then run the server:
python rundebug.py python3 rundebug.py
Then view in your web browser: Then view in your web browser:

@ -11,4 +11,5 @@ menu.Menu(app=app)
markdown.Markdown(app, extensions=['fenced_code']) markdown.Markdown(app, extensions=['fenced_code'])
github = GitHub(app) 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 datetime import datetime
from sqlalchemy.orm import validates from sqlalchemy.orm import validates
from flask_user import login_required, UserManager, UserMixin, SQLAlchemyAdapter from flask_user import login_required, UserManager, UserMixin, SQLAlchemyAdapter
import enum
# Initialise database # Initialise database
db = SQLAlchemy(app) db = SQLAlchemy(app)
@ -57,20 +58,34 @@ class UserRoles(db.Model):
user_id = db.Column(db.Integer(), db.ForeignKey('user.id', ondelete='CASCADE')) user_id = db.Column(db.Integer(), db.ForeignKey('user.id', ondelete='CASCADE'))
role_id = db.Column(db.Integer(), db.ForeignKey('role.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): 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)
desc = db.Column(db.Text, nullable=True) desc = db.Column(db.Text, nullable=True)
type = db.Column(db.Enum(PackageType))
# Downloads # Downloads
repo = db.Column(db.String(200), nullable=True) repo = db.Column(db.String(200), nullable=True)
website = db.Column(db.String(200), nullable=True) website = db.Column(db.String(200), nullable=True)
issueTracker = db.Column(db.String(200), nullable=True) issueTracker = db.Column(db.String(200), nullable=True)
forums = db.Column(db.String(200), nullable=False) forums = db.Column(db.String(200), nullable=False)
# Setup Flask-User # Setup Flask-User
db_adapter = SQLAlchemyAdapter(db, User) # Register the User model db_adapter = SQLAlchemyAdapter(db, User) # Register the User model

@ -7,7 +7,7 @@
{% block content %} {% block content %}
<ul> <ul>
{% for p in packages %} {% 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 }} {{ p.title }} by {{ p.author.display_name }}
</a></li> </a></li>
{% else %} {% else %}

@ -14,9 +14,9 @@ cache = SimpleCache()
def send_static(path): def send_static(path):
return send_from_directory('static', path) return send_from_directory('static', path)
import users, githublogin, mods
@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

@ -7,9 +7,21 @@ from app.models import *
@app.route('/mods/') @app.route('/mods/')
@menu.register_menu(app, '.mods', 'Mods') @menu.register_menu(app, '.mods', 'Mods')
def mods_page(): 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) 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>/") @app.route("/<type>s/<author>/<name>/")
def package_page(type, author, name): def package_page(type, author, name):
package = Package.query.filter_by(name=name).first() package = Package.query.filter_by(name=name).first()

@ -19,6 +19,7 @@ if not os.path.isfile("db.sqlite"):
mod1 = Package() mod1 = Package()
mod1.name = "awards" mod1.name = "awards"
mod1.title = "Awards" mod1.title = "Awards"
mod1.type = PackageType.MOD
mod1.author = ruben mod1.author = ruben
mod1.description = "Adds achievements and an API to register new ones." mod1.description = "Adds achievements and an API to register new ones."
mod1.repo = "https://github.com/rubenwardy/awards" mod1.repo = "https://github.com/rubenwardy/awards"