diff options
author | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2016-10-04 11:39:25 +0200 |
---|---|---|
committer | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2016-10-04 11:39:25 +0200 |
commit | e36f64813e6f12d541d69bdb1619dbf29b2d8c92 (patch) | |
tree | 4fa59353ed38f9c0ccc87ed9de5410a40bb91248 /src/web/models | |
parent | Removed duplicate glyphicon. (diff) | |
download | newspipe-e36f64813e6f12d541d69bdb1619dbf29b2d8c92.tar.gz newspipe-e36f64813e6f12d541d69bdb1619dbf29b2d8c92.tar.bz2 newspipe-e36f64813e6f12d541d69bdb1619dbf29b2d8c92.zip |
Fixed a bug when removing a user who have feeds in categories.
Diffstat (limited to 'src/web/models')
-rw-r--r-- | src/web/models/article.py | 17 | ||||
-rw-r--r-- | src/web/models/category.py | 5 | ||||
-rw-r--r-- | src/web/models/feed.py | 17 | ||||
-rw-r--r-- | src/web/models/user.py | 15 |
4 files changed, 41 insertions, 13 deletions
diff --git a/src/web/models/article.py b/src/web/models/article.py index 880cd561..46293f40 100644 --- a/src/web/models/article.py +++ b/src/web/models/article.py @@ -20,15 +20,15 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. __author__ = "Cedric Bonhomme" -__version__ = "$Revision: 0.4 $" +__version__ = "$Revision: 0.5 $" __date__ = "$Date: 2013/11/05 $" -__revision__ = "$Date: 2016/05/02 $" +__revision__ = "$Date: 2016/10/04 $" __copyright__ = "Copyright (c) Cedric Bonhomme" __license__ = "GPLv3" from bootstrap import db from datetime import datetime -from sqlalchemy import asc, desc +from sqlalchemy import asc, desc, Index from web.models.right_mixin import RightMixin @@ -41,14 +41,19 @@ class Article(db.Model, RightMixin): content = db.Column(db.String()) readed = db.Column(db.Boolean(), default=False) like = db.Column(db.Boolean(), default=False) - date = db.Column(db.DateTime(), default=datetime.now) - updated_date = db.Column(db.DateTime(), default=datetime.now) - retrieved_date = db.Column(db.DateTime(), default=datetime.now) + date = db.Column(db.DateTime(), default=datetime.utcnow) + updated_date = db.Column(db.DateTime(), default=datetime.utcnow) + retrieved_date = db.Column(db.DateTime(), default=datetime.utcnow) user_id = db.Column(db.Integer(), db.ForeignKey('user.id')) feed_id = db.Column(db.Integer(), db.ForeignKey('feed.id')) category_id = db.Column(db.Integer(), db.ForeignKey('category.id')) + # index + idx_article_uid = Index('user_id') + idx_article_uid_cid = Index('user_id', 'category_id') + idx_article_uid_fid = Index('user_id', 'feed_id') + # api whitelists @staticmethod def _fields_base_write(): diff --git a/src/web/models/category.py b/src/web/models/category.py index c35db52e..15b616bf 100644 --- a/src/web/models/category.py +++ b/src/web/models/category.py @@ -7,8 +7,13 @@ class Category(db.Model, RightMixin): id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String()) + # relationships user_id = db.Column(db.Integer, db.ForeignKey('user.id')) + feeds = db.relationship('Feed', cascade='all,delete-orphan') + articles = db.relationship('Article', + cascade='all,delete-orphan') + # index idx_category_uid = Index('user_id') # api whitelists diff --git a/src/web/models/feed.py b/src/web/models/feed.py index a866ac57..0e36bc79 100644 --- a/src/web/models/feed.py +++ b/src/web/models/feed.py @@ -28,7 +28,8 @@ __license__ = "GPLv3" from bootstrap import db from datetime import datetime -from sqlalchemy import desc +from sqlalchemy import desc, Index +from sqlalchemy.orm import validates from web.models.right_mixin import RightMixin @@ -42,7 +43,7 @@ class Feed(db.Model, RightMixin): link = db.Column(db.String()) site_link = db.Column(db.String(), default="") enabled = db.Column(db.Boolean(), default=True) - created_date = db.Column(db.DateTime(), default=datetime.now) + created_date = db.Column(db.DateTime(), default=datetime.utcnow) filters = db.Column(db.PickleType, default=[]) # cache handling @@ -62,6 +63,10 @@ class Feed(db.Model, RightMixin): cascade='all,delete-orphan', order_by=desc("date")) + # index + idx_feed_uid_cid = Index('user_id', 'category_id') + idx_feed_uid = Index('user_id') + # api whitelists @staticmethod def _fields_base_write(): @@ -72,5 +77,13 @@ class Feed(db.Model, RightMixin): def _fields_base_read(): return {'id', 'user_id', 'icon_url', 'last_retrieved'} + @validates('title') + def validates_title(self, key, value): + return str(value).strip() + + @validates('description') + def validates_description(self, key, value): + return str(value).strip() + def __repr__(self): return '<Feed %r>' % (self.title) diff --git a/src/web/models/user.py b/src/web/models/user.py index 2e5d2f55..1e7e3ec0 100644 --- a/src/web/models/user.py +++ b/src/web/models/user.py @@ -35,6 +35,8 @@ from flask_login import UserMixin from bootstrap import db from web.models.right_mixin import RightMixin +from web.models.category import Category +from web.models.feed import Feed class User(db.Model, UserMixin, RightMixin): @@ -49,8 +51,8 @@ class User(db.Model, UserMixin, RightMixin): is_public_profile = db.Column(db.Boolean(), default=False) webpage = db.Column(db.String(), default="") - date_created = db.Column(db.DateTime(), default=datetime.now) - last_seen = db.Column(db.DateTime(), default=datetime.now) + date_created = db.Column(db.DateTime(), default=datetime.utcnow) + last_seen = db.Column(db.DateTime(), default=datetime.utcnow) refresh_rate = db.Column(db.Integer, default=60) # in minutes # user rights @@ -59,9 +61,12 @@ class User(db.Model, UserMixin, RightMixin): is_api = db.Column(db.Boolean(), default=False) # relationship - feeds = db.relationship('Feed', backref='subscriber', lazy='dynamic', - cascade='all,delete-orphan') - categories = db.relationship('Category', cascade='all, delete-orphan') + categories = db.relationship('Category', backref='user', + cascade='all, delete-orphan', + foreign_keys=[Category.user_id]) + feeds = db.relationship('Feed', backref='user', + cascade='all, delete-orphan', + foreign_keys=[Feed.user_id]) @staticmethod def _fields_base_write(): |