Commit things that haven't been committed for a few days
This commit is contained in:
parent
1074cf0e0a
commit
2f7474f898
|
@ -1,23 +1,26 @@
|
||||||
from flask import Blueprint, render_template, g, session, redirect, request, url_for, flash, current_app, abort
|
from flask import Blueprint, render_template, g, session, redirect, request, url_for, flash, current_app, abort
|
||||||
import secrets
|
import secrets
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import re
|
|
||||||
from sqlalchemy import func
|
from sqlalchemy import func
|
||||||
|
|
||||||
from ..models import *
|
from ..models import *
|
||||||
from ..markdown import *
|
from ..markdown import *
|
||||||
|
from ..util import *
|
||||||
|
|
||||||
article_provider = Blueprint("article", __name__, template_folder='templates')
|
article_provider = Blueprint("article", __name__, template_folder='templates')
|
||||||
|
|
||||||
blacklisted_titles = ["new", "by-id"]
|
class DefaultSection:
|
||||||
allowed_titles = re.compile(r"^[a-zA-Z0-9 \(\)\.\,:;]+$")
|
def __init__(self, articles):
|
||||||
|
self.title = "No Section"
|
||||||
def urlify(title):
|
self.articles = articles
|
||||||
return title.replace(" ", "_")
|
|
||||||
|
|
||||||
|
|
||||||
def unurlify(title):
|
@article_provider.route("/")
|
||||||
return title.replace("_", " ")
|
def index():
|
||||||
|
sections = Section.query.all()
|
||||||
|
uncat = Article.query.filter_by(section_id=None).all()
|
||||||
|
sections.append(DefaultSection(uncat))
|
||||||
|
return render_template("article_index.html", sections=sections)
|
||||||
|
|
||||||
|
|
||||||
@article_provider.route("/<title>")
|
@article_provider.route("/<title>")
|
||||||
|
@ -55,9 +58,7 @@ def new():
|
||||||
return render_template("article_new.html",
|
return render_template("article_new.html",
|
||||||
csrf=csrf, article_title=article_title,
|
csrf=csrf, article_title=article_title,
|
||||||
article_content=article_content)
|
article_content=article_content)
|
||||||
if (len(article_title) == 0
|
if not title_valid(article_title):
|
||||||
or article_title in blacklisted_titles
|
|
||||||
or not allowed_titles.match(article_title)):
|
|
||||||
flash("Invalid title", "error")
|
flash("Invalid title", "error")
|
||||||
return render_template("article_new.html",
|
return render_template("article_new.html",
|
||||||
csrf=csrf, article_title=article_title,
|
csrf=csrf, article_title=article_title,
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
Articles
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h2>
|
||||||
|
Articles
|
||||||
|
</h2>
|
||||||
|
<ul>
|
||||||
|
{% for section in sections %}
|
||||||
|
<li>
|
||||||
|
{{ section.title }}
|
||||||
|
<ul>
|
||||||
|
{% for article in section.articles %}
|
||||||
|
<a href="{{ url_for("article.show", title=article.title_urlify()) }}">
|
||||||
|
{{ article.title }}
|
||||||
|
</a>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endblock %}
|
|
@ -6,7 +6,7 @@ User List
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h2>
|
<h2>
|
||||||
User list
|
User List
|
||||||
</h2>
|
</h2>
|
||||||
<ul>
|
<ul>
|
||||||
{% for user in users %}
|
{% for user in users %}
|
||||||
|
|
|
@ -8,13 +8,13 @@ __all__ = ["user_provider"]
|
||||||
user_provider = Blueprint("user", __name__, template_folder='templates')
|
user_provider = Blueprint("user", __name__, template_folder='templates')
|
||||||
|
|
||||||
@user_provider.route("/")
|
@user_provider.route("/")
|
||||||
def show_user_list():
|
def list():
|
||||||
users = User.query.all()
|
users = User.query.all()
|
||||||
# TODO: pagination...
|
# TODO: pagination...
|
||||||
return render_template("user_list.html", users=users)
|
return render_template("user_list.html", users=users)
|
||||||
|
|
||||||
@user_provider.route("/<username>")
|
@user_provider.route("/<username>")
|
||||||
def show_user(username):
|
def show(username):
|
||||||
is_self = g.wl_user is not None and username == g.wl_user.username
|
is_self = g.wl_user is not None and username == g.wl_user.username
|
||||||
if is_self:
|
if is_self:
|
||||||
user = g.wl_user
|
user = g.wl_user
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
from flask_sqlalchemy import SQLAlchemy
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
from flask_migrate import Migrate
|
from flask_migrate import Migrate
|
||||||
|
|
||||||
|
from .util import urlify
|
||||||
|
|
||||||
db = SQLAlchemy()
|
db = SQLAlchemy()
|
||||||
migrate = Migrate(None, db)
|
migrate = Migrate(None, db)
|
||||||
|
|
||||||
|
@ -23,8 +25,6 @@ class Section(db.Model):
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<Section \"{self.title}\">"
|
return f"<Section \"{self.title}\">"
|
||||||
|
|
||||||
DEFAULT_SECTION = 1
|
|
||||||
|
|
||||||
class Article(db.Model):
|
class Article(db.Model):
|
||||||
__tablename__ = "articles"
|
__tablename__ = "articles"
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
@ -35,6 +35,9 @@ class Article(db.Model):
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<Article \"{self.title}\">"
|
return f"<Article \"{self.title}\">"
|
||||||
|
|
||||||
|
def title_urlify(self):
|
||||||
|
return urlify(self.title)
|
||||||
|
|
||||||
class ArticleRevision(db.Model):
|
class ArticleRevision(db.Model):
|
||||||
__tablename__ = "articlerevisions"
|
__tablename__ = "articlerevisions"
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
<input type="text" name="q" placeholder="Search" />
|
<input type="text" name="q" placeholder="Search" />
|
||||||
</form>
|
</form>
|
||||||
</li>
|
</li>
|
||||||
<li><a href="/sections">Sections</a></li>
|
<li><a href="{{ url_for("article.index") }}">Article Index</a></li>
|
||||||
{% if not g.wl_user %}
|
{% if not g.wl_user %}
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ url_for("session.login") }}?redirect={{ request.path }}">
|
<a href="{{ url_for("session.login") }}?redirect={{ request.path }}">
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
import re
|
||||||
|
|
||||||
|
blacklisted_titles = ["new", "by-id"]
|
||||||
|
allowed_titles = re.compile(r"^[a-zA-Z0-9 \(\)\.\,:;]+$")
|
||||||
|
|
||||||
|
def urlify(title):
|
||||||
|
return title.replace(" ", "_")
|
||||||
|
|
||||||
|
|
||||||
|
def unurlify(title):
|
||||||
|
return title.replace("_", " ")
|
||||||
|
|
||||||
|
|
||||||
|
def title_valid(title):
|
||||||
|
return (len(article_title) > 0
|
||||||
|
and article_title not in blacklisted_titles
|
||||||
|
and allowed_titles.match(article_title))
|
Loading…
Reference in New Issue