Commit things that haven't been committed for a few days

This commit is contained in:
xenia 2019-06-17 10:53:59 +02:00
parent 1074cf0e0a
commit 2f7474f898
7 changed files with 63 additions and 17 deletions

View File

@ -1,23 +1,26 @@
from flask import Blueprint, render_template, g, session, redirect, request, url_for, flash, current_app, abort
import secrets
from datetime import datetime
import re
from sqlalchemy import func
from ..models import *
from ..markdown import *
from ..util import *
article_provider = Blueprint("article", __name__, template_folder='templates')
blacklisted_titles = ["new", "by-id"]
allowed_titles = re.compile(r"^[a-zA-Z0-9 \(\)\.\,:;]+$")
def urlify(title):
return title.replace(" ", "_")
class DefaultSection:
def __init__(self, articles):
self.title = "No Section"
self.articles = articles
def unurlify(title):
return title.replace("_", " ")
@article_provider.route("/")
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>")
@ -55,9 +58,7 @@ def new():
return render_template("article_new.html",
csrf=csrf, article_title=article_title,
article_content=article_content)
if (len(article_title) == 0
or article_title in blacklisted_titles
or not allowed_titles.match(article_title)):
if not title_valid(article_title):
flash("Invalid title", "error")
return render_template("article_new.html",
csrf=csrf, article_title=article_title,

View File

@ -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 %}

View File

@ -6,7 +6,7 @@ User List
{% block content %}
<h2>
User list
User List
</h2>
<ul>
{% for user in users %}

View File

@ -8,13 +8,13 @@ __all__ = ["user_provider"]
user_provider = Blueprint("user", __name__, template_folder='templates')
@user_provider.route("/")
def show_user_list():
def list():
users = User.query.all()
# TODO: pagination...
return render_template("user_list.html", users=users)
@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
if is_self:
user = g.wl_user

View File

@ -1,6 +1,8 @@
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from .util import urlify
db = SQLAlchemy()
migrate = Migrate(None, db)
@ -23,8 +25,6 @@ class Section(db.Model):
def __repr__(self):
return f"<Section \"{self.title}\">"
DEFAULT_SECTION = 1
class Article(db.Model):
__tablename__ = "articles"
id = db.Column(db.Integer, primary_key=True)
@ -35,6 +35,9 @@ class Article(db.Model):
def __repr__(self):
return f"<Article \"{self.title}\">"
def title_urlify(self):
return urlify(self.title)
class ArticleRevision(db.Model):
__tablename__ = "articlerevisions"
id = db.Column(db.Integer, primary_key=True)

View File

@ -16,7 +16,7 @@
<input type="text" name="q" placeholder="Search" />
</form>
</li>
<li><a href="/sections">Sections</a></li>
<li><a href="{{ url_for("article.index") }}">Article Index</a></li>
{% if not g.wl_user %}
<li>
<a href="{{ url_for("session.login") }}?redirect={{ request.path }}">

17
wikilain/util.py Normal file
View File

@ -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))