upgrade mf2py and mf2util
convert TEXT columns to JSONB
This commit is contained in:
parent
46e98853d9
commit
aa7f8ace80
4 changed files with 11 additions and 32 deletions
|
@ -16,8 +16,8 @@ bleach==1.4.1
|
||||||
feedparser>=5.2.0
|
feedparser>=5.2.0
|
||||||
html5lib==0.99999
|
html5lib==0.99999
|
||||||
|
|
||||||
mf2py==0.2.6
|
mf2py==0.2.7
|
||||||
mf2util==0.1.9
|
mf2util==0.2.3
|
||||||
psycopg2==2.6
|
psycopg2==2.6
|
||||||
|
|
||||||
pyOpenSSL==0.15.1
|
pyOpenSSL==0.15.1
|
||||||
|
|
|
@ -2,7 +2,6 @@ from flask.ext.login import LoginManager
|
||||||
from flask.ext.micropub import MicropubClient
|
from flask.ext.micropub import MicropubClient
|
||||||
from flask.ext.sqlalchemy import SQLAlchemy
|
from flask.ext.sqlalchemy import SQLAlchemy
|
||||||
from flask_debugtoolbar import DebugToolbarExtension
|
from flask_debugtoolbar import DebugToolbarExtension
|
||||||
from flask.ext.migrate import Migrate
|
|
||||||
|
|
||||||
|
|
||||||
db = SQLAlchemy()
|
db = SQLAlchemy()
|
||||||
|
@ -10,7 +9,6 @@ micropub = MicropubClient(client_id='https://reader.kylewm.com')
|
||||||
login_mgr = LoginManager()
|
login_mgr = LoginManager()
|
||||||
login_mgr.login_view = 'views.index'
|
login_mgr.login_view = 'views.index'
|
||||||
toolbar = DebugToolbarExtension()
|
toolbar = DebugToolbarExtension()
|
||||||
migrate = Migrate()
|
|
||||||
|
|
||||||
|
|
||||||
def init_app(app):
|
def init_app(app):
|
||||||
|
@ -18,4 +16,3 @@ def init_app(app):
|
||||||
micropub.init_app(app)
|
micropub.init_app(app)
|
||||||
login_mgr.init_app(app)
|
login_mgr.init_app(app)
|
||||||
toolbar.init_app(app)
|
toolbar.init_app(app)
|
||||||
migrate.init_app(app, db)
|
|
||||||
|
|
|
@ -1,26 +1,9 @@
|
||||||
from .extensions import db
|
from .extensions import db
|
||||||
import json
|
|
||||||
|
from sqlalchemy.dialects.postgresql import JSONB
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
|
||||||
class JsonType(db.TypeDecorator):
|
|
||||||
"""Represents an immutable structure as a json-encoded string.
|
|
||||||
http://docs.sqlalchemy.org/en/rel_0_9/core/types.html#marshal-json-strings
|
|
||||||
"""
|
|
||||||
impl = db.Text
|
|
||||||
|
|
||||||
def process_bind_param(self, value, dialect):
|
|
||||||
if value is not None:
|
|
||||||
value = json.dumps(value)
|
|
||||||
|
|
||||||
return value
|
|
||||||
|
|
||||||
def process_result_value(self, value, dialect):
|
|
||||||
if value is not None:
|
|
||||||
value = json.loads(value)
|
|
||||||
return value
|
|
||||||
|
|
||||||
|
|
||||||
entry_to_reply_context = db.Table(
|
entry_to_reply_context = db.Table(
|
||||||
'entry_to_reply_context', db.Model.metadata,
|
'entry_to_reply_context', db.Model.metadata,
|
||||||
db.Column('entry_id', db.Integer, db.ForeignKey('entry.id'), index=True),
|
db.Column('entry_id', db.Integer, db.ForeignKey('entry.id'), index=True),
|
||||||
|
@ -33,7 +16,7 @@ class User(db.Model):
|
||||||
# domain = db.Column(db.String(256))
|
# domain = db.Column(db.String(256))
|
||||||
micropub_endpoint = db.Column(db.String(512))
|
micropub_endpoint = db.Column(db.String(512))
|
||||||
access_token = db.Column(db.String(512))
|
access_token = db.Column(db.String(512))
|
||||||
settings = db.Column(JsonType)
|
settings = db.Column(JSONB)
|
||||||
|
|
||||||
# Flask-Login integration
|
# Flask-Login integration
|
||||||
def is_authenticated(self):
|
def is_authenticated(self):
|
||||||
|
@ -134,7 +117,7 @@ class Entry(db.Model):
|
||||||
content = db.Column(db.Text)
|
content = db.Column(db.Text)
|
||||||
content_cleaned = db.Column(db.Text)
|
content_cleaned = db.Column(db.Text)
|
||||||
# other properties
|
# other properties
|
||||||
properties = db.Column(JsonType)
|
properties = db.Column(JSONB)
|
||||||
reply_context = db.relationship(
|
reply_context = db.relationship(
|
||||||
'Entry', secondary='entry_to_reply_context',
|
'Entry', secondary='entry_to_reply_context',
|
||||||
primaryjoin=id == entry_to_reply_context.c.entry_id,
|
primaryjoin=id == entry_to_reply_context.c.entry_id,
|
||||||
|
@ -142,7 +125,6 @@ class Entry(db.Model):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
self.subscription = None
|
self.subscription = None
|
||||||
self._syndicated_copies = []
|
self._syndicated_copies = []
|
||||||
|
|
||||||
|
@ -152,8 +134,8 @@ class Entry(db.Model):
|
||||||
return self.properties.get(key, default)
|
return self.properties.get(key, default)
|
||||||
|
|
||||||
def set_property(self, key, value):
|
def set_property(self, key, value):
|
||||||
self.properties = ({} if self.properties is None
|
if self.properties is None:
|
||||||
else dict(self.properties))
|
self.properties = {}
|
||||||
self.properties[key] = value
|
self.properties[key] = value
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
|
|
@ -391,7 +391,6 @@ def process_html_feed_for_new_entries(feed, content, backfill, now):
|
||||||
if was_bytes:
|
if was_bytes:
|
||||||
content = content.encode()
|
content = content.encode()
|
||||||
|
|
||||||
|
|
||||||
parsed = mf2util.interpret_feed(
|
parsed = mf2util.interpret_feed(
|
||||||
mf2py.parse(url=feed.feed, doc=content), feed.feed)
|
mf2py.parse(url=feed.feed, doc=content), feed.feed)
|
||||||
hfeed = parsed.get('entries', [])
|
hfeed = parsed.get('entries', [])
|
||||||
|
@ -453,6 +452,7 @@ def hentry_to_entry(hentry, feed, backfill, now):
|
||||||
if value:
|
if value:
|
||||||
entry.set_property(prop, value)
|
entry.set_property(prop, value)
|
||||||
|
|
||||||
|
current_app.logger.debug('entry properties %s', entry.properties)
|
||||||
return entry
|
return entry
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue