Move to a node-based content management system

This commit is contained in:
Raoul Snyman 2021-01-29 21:19:48 -07:00
parent 045e452f5b
commit 92122b465e
No known key found for this signature in database
GPG Key ID: 423F9B322D9BEF2C
14 changed files with 565 additions and 70 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
*.egg-info
__pycache__
*.pyc
*.pyo
*.pyd
*.sqlite

View File

@ -1,3 +1,4 @@
email-validator
Flask
Flask-Admin
Flask-Login

View File

@ -29,6 +29,7 @@ from flask_mail import Mail
from flask_themes2 import Themes, packaged_themes_loader, theme_paths_loader, load_themes_from
from flask_user import UserManager
from scribeengine.admin import admin
from scribeengine.config import read_config_from_file
from scribeengine.db import db
from scribeengine.models import User
@ -61,14 +62,13 @@ def create_app(config_file=None):
Mail(application)
Themes(application, app_identifier='ScribeEngine', loaders=[
_scribeengine_themes_loader, packaged_themes_loader, theme_paths_loader])
print(application.root_path)
print(application.theme_manager.themes)
# Set up database
db.init_app(application)
db.create_all(app=application)
# Setup Flask-User
UserManager(application, db, User)
# Register all the blueprints
application.register_blueprint(admin)
application.register_blueprint(blog)
application.register_blueprint(account)
# Return the application object

42
scribeengine/admin.py Normal file
View File

@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# ScribeEngine - Open Source Blog Software #
# --------------------------------------------------------------------------- #
# Copyright (c) 2010-2017 Raoul Snyman #
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
"""
The :mod:`~scribeengine.admin` module sets up the admin interface
"""
from flask import Blueprint
# from scribeengine.db import session
from scribeengine.helpers import render_admin
from scribeengine.models import Post
admin = Blueprint('admin', __name__, url_prefix='/admin')
@admin.route('', methods=['GET'])
def index():
return render_admin('index.html')
@admin.route('/posts', methods=['GET'])
def posts():
posts = Post.query.limit(10).all()
return render_admin('posts.html', posts=posts)

View File

@ -39,3 +39,4 @@ Boolean = db.Boolean
DateTime = db.DateTime
relationship = db.relationship
backref = db.backref
session = db.session

View File

@ -51,3 +51,11 @@ def render(template, **context):
"""
context.update({'site': get_site_details(), 'archives': []})
return render_theme_template(get_current_theme(), template, **context)
def render_admin(template, **context):
"""
Render a template, after selecting a theme
"""
context.update({'site': get_site_details()})
return render_theme_template('admin', template, **context)

View File

@ -22,18 +22,13 @@
"""
The :mod:`~scribeengine.models` module contains all the database models
"""
from datetime import datetime
from box import Box
from flask_user import UserMixin
from sqlalchemy import func
from scribeengine.db import Model, Table, Column, ForeignKey, String, Text, Integer, Boolean, DateTime, \
relationship, backref
categories_posts = Table(
'categories_posts',
Column('category_id', Integer, ForeignKey('categories.id'), primary_key=True),
Column('post_id', Integer, ForeignKey('posts.id'), primary_key=True)
)
relationship
permissions_roles = Table(
@ -43,10 +38,10 @@ permissions_roles = Table(
)
posts_tags = Table(
'posts_tags',
Column('post_id', Integer, ForeignKey('posts.id'), primary_key=True),
Column('tag_id', Integer, ForeignKey('tags.id'), primary_key=True)
nodes_taxonomies = Table(
'nodes_terms',
Column('node_id', Integer, ForeignKey('nod.id'), primary_key=True),
Column('taxonomy_id', Integer, ForeignKey('taxonomy.id'), primary_key=True)
)
@ -57,32 +52,90 @@ roles_users = Table(
)
class Category(Model):
class Taxonomy(Model):
"""
This is a category for blog posts.
This is a grouping of related terms, like a tags or categories
"""
__tablename__ = 'categories'
__tablename__ = 'taxonomies'
id = Column(Integer, primary_key=True)
name = Column(String(100), nullable=False)
description = Column(Text)
url = Column(String(255), nullable=False, index=True, unique=True)
slug = Column(String(255), nullable=False, index=True, unique=True)
def __str__(self):
return self.name
class Comment(Model):
class Node(Model):
"""
All blog posts have comments. This is a single comment.
Nodes are the basic content type
"""
__tablename__ = 'comments'
__tablename__ = 'nodes'
id = Column(Integer, primary_key=True)
post_id = Column(Integer, ForeignKey('posts.id'), nullable=True)
user_id = Column(Integer, ForeignKey('users.id'), nullable=False)
title = Column(String(100), nullable=False)
body = Column(Text, nullable=False)
status = Column(String(10), default='moderated')
created = Column(DateTime, server_default=func.now())
modified = Column(DateTime, server_default=func.now())
slug = Column(String(255), nullable=False, index=True, unique=True)
type = Column(String(255), nullable=False, index=True)
created = Column(DateTime, nullable=False, default=datetime.utcnow)
modified = Column(DateTime, nullable=False, default=datetime.utcnow)
revision_id = Column(Integer, ForeignKey('revisions.id'), nullable=False, index=True)
current_revision = relationship('Revision', backref='node')
@property
def complete(self):
"""Return a "full" or "complete" node, with all fields and data"""
node_dict = Box({
'id': self.id,
'slug': self.slug,
'type': self.type,
'created': self.created,
'modified': self.modified,
'title': self.current_revision.title,
'body': self.current_revision.body,
'format': self.current_revision.format
})
for field in self.fields:
node_dict[field.name] = {
'name': field.name,
'type': field.type,
'title': field.field.title,
'data': field.data
}
return node_dict
class Revision(Model):
"""
A version of a node
"""
__tablename__ = 'revisions'
id = Column(Integer, primary_key=True)
version = Column(String(255), nullable=False)
title = Column(String(255), nullable=False)
body = Column(Text)
format = Column(Text, nullable=False)
slug = Column(String(255), nullable=False)
created = Column(DateTime, nullable=False, index=True, default=datetime.utcnow)
node_id = Column(Integer, ForeignKey('nodes.id'), nullable=False)
node = relationship('Node', backref='revisions')
class Field(Model):
"""
A field is a model for extra field types on nodes
"""
__tablename__ = 'fields'
id = Column(Integer, primary_key=True)
name = Column(String(255), nullable=False, unique=True, index=True)
type = Column(String(255), nullable=False)
title = Column(String(255), nullable=False)
description = Column(Text)
created = Column(DateTime, nullable=False, default=datetime.utcnow)
modified = Column(DateTime, nullable=False, default=datetime.utcnow)
class File(Model):
@ -99,6 +152,9 @@ class File(Model):
path = Column(String(255))
size = Column(Integer, default=0)
def __str__(self):
return self.filename
class MediaType(Model):
"""
@ -111,20 +167,8 @@ class MediaType(Model):
files = relationship('File', backref='media_type')
class Page(Model):
"""
A page on the blog. This is separate from a blog entry, for things like
about pages.
"""
__tablename__ = 'pages'
id = Column(Integer, primary_key=True)
title = Column(String(255), nullable=False)
body = Column(Text)
url = Column(String(255), nullable=False, index=True, unique=True)
created = Column(DateTime, server_default=func.now())
modified = Column(DateTime, server_default=func.now())
def __str__(self):
return self.title
class Permission(Model):
@ -137,26 +181,8 @@ class Permission(Model):
name = Column(String(80), nullable=False, index=True)
description = Column(Text)
class Post(Model):
"""
The most import part of all of this, the blog post.
"""
__tablename__ = 'posts'
id = Column(Integer, primary_key=True)
user_id = Column(Integer, ForeignKey('users.id'), nullable=False)
title = Column(String(255), nullable=False, index=True)
body = Column(Text, nullable=False, index=True)
url = Column(String(255), nullable=False, index=True)
status = Column(String(10), default='draft', index=True)
comment_status = Column(String(10), default='open')
created = Column(DateTime, server_default=func.now())
modified = Column(DateTime, server_default=func.now())
categories = relationship('Category', backref='posts', secondary=categories_posts)
comments = relationship('Comment', backref='post', order_by='Comment.created.asc()')
tags = relationship('Tag', backref=backref('posts', order_by='Post.created.desc()'), secondary=posts_tags)
def __str__(self):
return self.name
class Role(Model):
@ -171,16 +197,23 @@ class Role(Model):
permissions = relationship('Permission', backref='roles', secondary=permissions_roles)
def __str__(self):
return self.name
class Tag(Model):
class Term(Model):
"""
A tag, an unstructured category, for blog posts.
A term is an item in a taxonomy. A term can be a category name, or a tag in a blog post.
"""
__tablename__ = 'tags'
__tablename__ = 'terms'
id = Column(Integer, primary_key=True)
name = Column(String(100), nullable=False)
url = Column(String(255), nullable=False, index=True)
slug = Column(String(255), nullable=False, index=True)
taxonomy_id = Column(Integer, ForeignKey('taxonomies.id'))
def __str__(self):
return self.name
class User(Model, UserMixin):
@ -204,7 +237,7 @@ class User(Model, UserMixin):
comments = relationship('Comment', backref='user')
files = relationship('File', backref='user')
posts = relationship('Post', backref='user')
posts = relationship('Post', backref='author')
roles = relationship('Role', backref='users', secondary=roles_users)
def has_permission(self, permission):
@ -229,6 +262,9 @@ class User(Model, UserMixin):
else:
return False
def __str__(self):
return str(id(self))
class Variable(Model):
"""

View File

@ -0,0 +1,12 @@
{
"application": "ScribeEngine",
"identifier": "admin",
"name": "Admin",
"author": "Raoul Snyman",
"description": "A basic theme built using Bootstrap 4 and based on Bootstrap 4's blog example",
"website": "https://scribeengine.org",
"license": "GPL3+",
"preview": "screenshot.png",
"doctype": "html5",
"version": "0.1"
}

View File

@ -0,0 +1,100 @@
body {
font-size: .875rem;
}
.feather {
width: 16px;
height: 16px;
vertical-align: text-bottom;
}
/*
* Sidebar
*/
.sidebar {
position: fixed;
top: 0;
/* rtl:raw:
right: 0;
*/
bottom: 0;
/* rtl:remove */
left: 0;
z-index: 100; /* Behind the navbar */
padding: 48px 0 0; /* Height of navbar */
box-shadow: inset -1px 0 0 rgba(0, 0, 0, .1);
}
@media (max-width: 767.98px) {
.sidebar {
top: 5rem;
}
}
.sidebar-sticky {
position: relative;
top: 0;
height: calc(100vh - 48px);
padding-top: .5rem;
overflow-x: hidden;
overflow-y: auto; /* Scrollable contents if viewport is shorter than content. */
}
.sidebar .nav-link {
font-weight: 500;
color: #333;
}
.sidebar .nav-link .feather {
margin-right: 4px;
color: #727272;
}
.sidebar .nav-link.active {
color: #007bff;
}
.sidebar .nav-link:hover .feather,
.sidebar .nav-link.active .feather {
color: inherit;
}
.sidebar-heading {
font-size: .75rem;
text-transform: uppercase;
}
/*
* Navbar
*/
.navbar-brand {
padding-top: .75rem;
padding-bottom: .75rem;
font-size: 1rem;
background-color: rgba(0, 0, 0, .25);
box-shadow: inset -1px 0 0 rgba(0, 0, 0, .25);
}
.navbar .navbar-toggler {
top: .25rem;
right: 1rem;
}
.navbar .form-control {
padding: .75rem 1rem;
border-width: 0;
border-radius: 0;
}
.form-control-dark {
color: #fff;
background-color: rgba(255, 255, 255, .1);
border-color: rgba(255, 255, 255, .1);
}
.form-control-dark:focus {
border-color: transparent;
box-shadow: 0 0 0 3px rgba(255, 255, 255, .25);
}

View File

@ -0,0 +1,283 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>{{title}}</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Playfair+Display:700,900">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<!-- Favicons -->
<link rel="apple-touch-icon" href="/docs/5.0/assets/img/favicons/apple-touch-icon.png" sizes="180x180">
<link rel="icon" href="/docs/5.0/assets/img/favicons/favicon-32x32.png" sizes="32x32" type="image/png">
<link rel="icon" href="/docs/5.0/assets/img/favicons/favicon-16x16.png" sizes="16x16" type="image/png">
<link rel="manifest" href="/docs/5.0/assets/img/favicons/manifest.json">
<link rel="mask-icon" href="/docs/5.0/assets/img/favicons/safari-pinned-tab.svg" color="#7952b3">
<link rel="icon" href="/docs/5.0/assets/img/favicons/favicon.ico">
<meta name="theme-color" content="#7952b3">
<style>
.bd-placeholder-img {
font-size: 1.125rem;
text-anchor: middle;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}
@media (min-width: 768px) {
.bd-placeholder-img-lg {
font-size: 3.5rem;
}
}
</style>
<link rel="stylesheet" href="{{ theme_static('css/dashboard.css') }}">
</head>
<body>
<header class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0 shadow">
<a class="navbar-brand col-md-3 col-lg-2 me-0 px-3" href="#">ScribeEngine</a>
<button class="navbar-toggler position-absolute d-md-none collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#sidebarMenu" aria-controls="sidebarMenu" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<input class="form-control form-control-dark w-100" type="text" placeholder="Search" aria-label="Search">
<ul class="navbar-nav px-3">
<li class="nav-item text-nowrap">
<a class="nav-link" href="#">Sign out</a>
</li>
</ul>
</header>
<div class="container-fluid">
<div class="row">
<nav id="sidebarMenu" class="col-md-3 col-lg-2 d-md-block bg-light sidebar collapse">
<div class="position-sticky pt-3">
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">
<span data-feather="home"></span>
Dashboard
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<span data-feather="file"></span>
Posts
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<span data-feather="shopping-cart"></span>
Comments
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<span data-feather="users"></span>
Categories
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<span data-feather="bar-chart-2"></span>
Tags
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<span data-feather="layers"></span>
Articles
</a>
</li>
</ul>
<h6 class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted">
<span>Saved reports</span>
<a class="link-secondary" href="#" aria-label="Add a new report">
<span data-feather="plus-circle"></span>
</a>
</h6>
<ul class="nav flex-column mb-2">
<li class="nav-item">
<a class="nav-link" href="#">
<span data-feather="file-text"></span>
Current month
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<span data-feather="file-text"></span>
Last quarter
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<span data-feather="file-text"></span>
Social engagement
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<span data-feather="file-text"></span>
Year-end sale
</a>
</li>
</ul>
</div>
</nav>
<main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2">Dashboard</h1>
<div class="btn-toolbar mb-2 mb-md-0">
<div class="btn-group me-2">
<button type="button" class="btn btn-sm btn-outline-secondary">Share</button>
<button type="button" class="btn btn-sm btn-outline-secondary">Export</button>
</div>
<button type="button" class="btn btn-sm btn-outline-secondary dropdown-toggle">
<span data-feather="calendar"></span>
This week
</button>
</div>
</div>
<canvas class="my-4 w-100" id="myChart" width="900" height="380"></canvas>
<h2>Section title</h2>
<div class="table-responsive">
<table class="table table-striped table-sm">
<thead>
<tr>
<th>#</th>
<th>Header</th>
<th>Header</th>
<th>Header</th>
<th>Header</th>
</tr>
</thead>
<tbody>
<tr>
<td>1,001</td>
<td>Lorem</td>
<td>ipsum</td>
<td>dolor</td>
<td>sit</td>
</tr>
<tr>
<td>1,002</td>
<td>amet</td>
<td>consectetur</td>
<td>adipiscing</td>
<td>elit</td>
</tr>
<tr>
<td>1,003</td>
<td>Integer</td>
<td>nec</td>
<td>odio</td>
<td>Praesent</td>
</tr>
<tr>
<td>1,003</td>
<td>libero</td>
<td>Sed</td>
<td>cursus</td>
<td>ante</td>
</tr>
<tr>
<td>1,004</td>
<td>dapibus</td>
<td>diam</td>
<td>Sed</td>
<td>nisi</td>
</tr>
<tr>
<td>1,005</td>
<td>Nulla</td>
<td>quis</td>
<td>sem</td>
<td>at</td>
</tr>
<tr>
<td>1,006</td>
<td>nibh</td>
<td>elementum</td>
<td>imperdiet</td>
<td>Duis</td>
</tr>
<tr>
<td>1,007</td>
<td>sagittis</td>
<td>ipsum</td>
<td>Praesent</td>
<td>mauris</td>
</tr>
<tr>
<td>1,008</td>
<td>Fusce</td>
<td>nec</td>
<td>tellus</td>
<td>sed</td>
</tr>
<tr>
<td>1,009</td>
<td>augue</td>
<td>semper</td>
<td>porta</td>
<td>Mauris</td>
</tr>
<tr>
<td>1,010</td>
<td>massa</td>
<td>Vestibulum</td>
<td>lacinia</td>
<td>arcu</td>
</tr>
<tr>
<td>1,011</td>
<td>eget</td>
<td>nulla</td>
<td>Class</td>
<td>aptent</td>
</tr>
<tr>
<td>1,012</td>
<td>taciti</td>
<td>sociosqu</td>
<td>ad</td>
<td>litora</td>
</tr>
<tr>
<td>1,013</td>
<td>torquent</td>
<td>per</td>
<td>conubia</td>
<td>nostra</td>
</tr>
<tr>
<td>1,014</td>
<td>per</td>
<td>inceptos</td>
<td>himenaeos</td>
<td>Curabitur</td>
</tr>
<tr>
<td>1,015</td>
<td>sodales</td>
<td>ligula</td>
<td>in</td>
<td>libero</td>
</tr>
</tbody>
</table>
</div>
</main>
{% block content $}
{$ endblock %}
</div>
</div>
<script src="/docs/5.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons@4.28.0/dist/feather.min.js" integrity="sha384-uO3SXW5IuS1ZpFPKugNNWqTZRRglnUJK6UAZ/gxOX80nxEkN9NcGZTftn6RzhGWE" crossorigin="anonymous"></script><script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js" integrity="sha384-zNy6FEbO50N+Cg5wap8IKA4M/ZnLJgzc6w2NqACZaK0u0FXfOWRRJOnQtpZun8ha" crossorigin="anonymous"></script><script src="dashboard.js"></script>
</body>
</html>

View File

@ -0,0 +1,3 @@
{% extends theme("base.html") %}
{% block content $}
{$ endblock %}

View File

@ -3,7 +3,7 @@
"identifier": "quill",
"name": "Quill",
"author": "Raoul Snyman",
"description": "A basic theme built using Bootstrap 4 and based on Bootstrap 4's blog example",
"description": "An administration theme, based on the Bootstrap dashboard example",
"website": "https://scribeengine.org",
"license": "GPL3+",
"preview": "screenshot.png",

View File

@ -5,13 +5,14 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>{{title}}</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Playfair+Display:700,900">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
<link rel="stylesheet" href="{{ theme_static('css/quill.css') }}">
</head>
<body>
{% include theme("header.html") %}
{% block content %}{% endblock %}
{% include theme("footer.html") %}
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>
</body>
</html>

2
setup.cfg Normal file
View File

@ -0,0 +1,2 @@
[flake8]
max-line-length=120