Skip to content

Commit

Permalink
This commit does 2 things.
Browse files Browse the repository at this point in the history
1. more importantly, it gets the current master of the site running
   effectively with newere dependencies (with fewer security holes!)
2. it implements a 70% piece of pinned articles. Missing: 1) article
   pinning doesn't work, 2) migration isn't written so it's not
deployable.
  • Loading branch information
echarlie committed Mar 29, 2024
1 parent 5965d14 commit 358ad26
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 14 deletions.
9 changes: 5 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ flask==2.2.5
# flask-sqlalchemy
# flask-wtf
# sentry-sdk
flask-caching==1.8.0
flask-caching==2.1.0
# via -r requirements.in
flask-migrate==2.5.2
# via -r requirements.in
flask-restful==0.3.7
# via -r requirements.in
flask-sqlalchemy==2.4.1
flask-sqlalchemy==3.0.1
# via
# -r requirements.in
# flask-migrate
flask-wtf==0.14.2
flask-wtf==1.2.0
# via -r requirements.in
google-api-python-client==1.7.11
# via -r requirements.in
Expand Down Expand Up @@ -160,7 +160,7 @@ six==1.13.0
# google-auth
# python-dateutil
# sqlalchemy-utils
sqlalchemy==1.3.11
sqlalchemy==1.4.18
# via
# -r requirements.in
# alembic
Expand All @@ -185,6 +185,7 @@ werkzeug==3.0.1
# via flask
wtforms==2.2.1
# via flask-wtf
feedwerk==1.2.0

# The following packages are considered to be unsafe in a requirements file:
# setuptools
6 changes: 4 additions & 2 deletions wuvt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy
from flask_wtf.csrf import CSRFProtect
from werkzeug.contrib.cache import RedisCache
#from werkzeug.contrib.cache import RedisCache

This comment has been minimized.

Copy link
@mutantmonkey

mutantmonkey Mar 31, 2024

Member

Why not just remove this?

from flask_caching.backends import RedisCache
import json
import humanize
import os
import redis
Expand Down Expand Up @@ -82,7 +84,7 @@ def wants_json(self):
if config_path.endswith('.py'):
app.config.from_pyfile(config_path, silent=True)
else:
app.config.from_json(config_path, silent=True)
app.config.from_file(config_path, load=json.load, silent=True)

app.request_class = JSONRequest
app.jinja_env.filters.update({
Expand Down
6 changes: 4 additions & 2 deletions wuvt/admin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
from flask import abort, flash, jsonify, make_response, render_template, \
redirect, request, url_for
from werkzeug import secure_filename
from werkzeug.utils import secure_filename

from wuvt import app, auth_manager, cache, db, redis_conn
from wuvt.auth import current_user, login_required
Expand Down Expand Up @@ -358,7 +358,8 @@ def article_add():
author_id=form.author_id.data,
summary=form.summary.data,
content=form.content.data,
published=form.published.data)
published=form.published.data,
pinned_article=form.pinned_article.data)
article.front_page = form.front_page.data
if article.published is True:
article.datetime = datetime.datetime.utcnow()
Expand Down Expand Up @@ -421,6 +422,7 @@ def article_edit(art_id):
article.summary = form.summary.data
article.content = form.content.data
article.front_page = form.front_page.data
article.pinned_article = form.pinned_article.data
article.render_html()

try:
Expand Down
1 change: 1 addition & 0 deletions wuvt/blog/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ArticleForm(FlaskForm):
validators=[validators.DataRequired()])
published = BooleanField('Published', default=False)
front_page = BooleanField('Front Page', default=False)
pinned_article = BooleanField('Pin to Front Page', default=False)
summary = StringField('Summary', filters=[strip_field],
validators=[validators.DataRequired()])
content = StringField('Content', filters=[strip_field],
Expand Down
3 changes: 3 additions & 0 deletions wuvt/blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class Article(db.Model):
html_content = db.Column(db.UnicodeText().with_variant(db.UnicodeText(length=2**1), 'mysql'))
published = db.Column(db.Boolean, default=False, nullable=False)
front_page = db.Column(db.Boolean, default=False, nullable=False)
pinned_article = db.Column(db.Boolean, default=False, nullable=False)


def __init__(self, title, slug, category_id, author_id, summary,
content=None, published=False):
Expand Down Expand Up @@ -90,6 +92,7 @@ class ArticleRevision(db.Model):
content = db.Column(db.UnicodeText().with_variant(db.UnicodeText(length=2**1), 'mysql'))
html_summary = db.Column(db.UnicodeText().with_variant(db.UnicodeText(length=2**1), 'mysql'))
html_content = db.Column(db.UnicodeText().with_variant(db.UnicodeText(length=2**1), 'mysql'))
pinned_article = db.Column(db.Boolean, default=False, nullable=False)

def __init__(self, article_id, author_id, title, summary, content=None):
self.article_id = article_id
Expand Down
11 changes: 6 additions & 5 deletions wuvt/blog/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from flask import abort, current_app, redirect, render_template, request, \
url_for
from urllib.parse import urljoin
from werkzeug.contrib.atom import AtomFeed
#from werkzeug.contrib.atom import AtomFeed
from feedwerk.atom import AtomFeed

from .. import cache, db
from . import bp
Expand Down Expand Up @@ -36,7 +37,7 @@ def category(slug, page=1):
articles = Article.query.filter(Article.category_id == category.id).\
filter_by(published=True).\
order_by(db.desc(Article.datetime)).\
paginate(page, current_app.config['POSTS_PER_PAGE'])
paginate(page=page, max_per_page=current_app.config['POSTS_PER_PAGE'])

return render_template('category.html',
category=category,
Expand Down Expand Up @@ -89,9 +90,9 @@ def article(slug):
@bp.route('/index/<int:page>')
def index(page=1):
articles = Article.query.filter_by(published=True, front_page=True).\
order_by(db.desc(Article.datetime)).paginate(
page,
current_app.config['POSTS_PER_PAGE'])
order_by(Article.pinned_article==True,db.desc(Article.datetime)).paginate(
page=page,
max_per_page=current_app.config['POSTS_PER_PAGE'])
return render_template('index.html', articles=articles)


Expand Down
3 changes: 2 additions & 1 deletion wuvt/playlists/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import dateutil.parser
import re
import requests
from werkzeug.contrib.atom import AtomFeed
#from werkzeug.contrib.atom import AtomFeed
from feedwerk.atom import AtomFeed

from . import bp
from .view_utils import call_api, make_external, \
Expand Down
14 changes: 14 additions & 0 deletions wuvt/templates/admin/article_add.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ <h1>Create Article</h1>
{% endfor %}
</div>
</div>
<div class="form-group{% if form.pinned_article.errors|length > 0 %} has-error{% endif %}">
<div class="col-sm-3">
</div>
<div class="col-sm-9 checkbox">
<label>
<input type="checkbox" name="pinned_article" id="id_pinned_article" value="" />
<strong>Pin article to front page</strong>
</label>
{% for error in form.pinned_article.errors %}
<div class="help-block">{{ error }}</div>
{% endfor %}
</div>
</div>

<div class="form-group{% if form.summary.errors|length > 0 %} has-error{% endif %}">
<label for="id_summary" class="col-sm-3 control-label">Summary</label>
<div class="col-sm-9">
Expand Down
14 changes: 14 additions & 0 deletions wuvt/templates/admin/article_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ <h1>Edit Article</h1>
{% endfor %}
</div>
</div>
<div class="form-group{% if form.pinned_article.errors|length > 0 %} has-error{% endif %}">
<div class="col-sm-3">
</div>
<div class="col-sm-9 checkbox">
<label>
<input type="checkbox" name="pinned_article" id="id_pinned_article" value="" />
<strong>Pin article to front page</strong>
</label>
{% for error in form.pinned_article.errors %}
<div class="help-block">{{ error }}</div>
{% endfor %}
</div>
</div>

<div class="form-group{% if form.summary.errors|length > 0 %} has-error{% endif %}">
<label for="id_summary" class="col-sm-3 control-label">Summary</label>
<div class="col-sm-9">
Expand Down

0 comments on commit 358ad26

Please sign in to comment.