aboutsummaryrefslogtreecommitdiff
path: root/src/web/models
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2016-02-03 07:11:37 +0100
committerCédric Bonhomme <cedric@cedricbonhomme.org>2016-02-03 07:11:37 +0100
commitda929a367c3f1fe5f3546be82e47111c2fa84ad3 (patch)
tree89380f41b802256d8fdbf724e7d9e63b48209b4a /src/web/models
parentMerge pull request #30 from jaesivsm/master (diff)
parentwriting a bit of doc, moving crawler together (diff)
downloadnewspipe-da929a367c3f1fe5f3546be82e47111c2fa84ad3.tar.gz
newspipe-da929a367c3f1fe5f3546be82e47111c2fa84ad3.tar.bz2
newspipe-da929a367c3f1fe5f3546be82e47111c2fa84ad3.zip
Merge pull request #31 from jaesivsm/master
redoing UI
Diffstat (limited to 'src/web/models')
-rw-r--r--src/web/models/__init__.py3
-rw-r--r--src/web/models/article.py20
-rw-r--r--src/web/models/category.py11
-rw-r--r--src/web/models/feed.py8
-rw-r--r--src/web/models/user.py10
5 files changed, 31 insertions, 21 deletions
diff --git a/src/web/models/__init__.py b/src/web/models/__init__.py
index 54168279..81ebe361 100644
--- a/src/web/models/__init__.py
+++ b/src/web/models/__init__.py
@@ -31,8 +31,9 @@ from .role import Role
from .user import User
from .article import Article
from .icon import Icon
+from .category import Category
-__all__ = ['Feed', 'Role', 'User', 'Article', 'Icon']
+__all__ = ['Feed', 'Role', 'User', 'Article', 'Icon', 'Category']
import os
diff --git a/src/web/models/article.py b/src/web/models/article.py
index 54eefe75..94fedf16 100644
--- a/src/web/models/article.py
+++ b/src/web/models/article.py
@@ -32,22 +32,20 @@ from sqlalchemy import asc, desc
class Article(db.Model):
- """
- Represent an article from a feed.
- """
- id = db.Column(db.Integer, primary_key=True)
+ "Represent an article from a feed."
+ id = db.Column(db.Integer(), primary_key=True)
entry_id = db.Column(db.String())
link = db.Column(db.String())
title = db.Column(db.String())
content = db.Column(db.String())
readed = db.Column(db.Boolean(), default=False)
like = db.Column(db.Boolean(), default=False)
- #notes = db.Column(db.String(), default="")
date = db.Column(db.DateTime(), default=datetime.now)
retrieved_date = db.Column(db.DateTime(), default=datetime.now)
- user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
- feed_id = db.Column(db.Integer, db.ForeignKey('feed.id'))
+ 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'))
def previous_article(self):
"""
@@ -55,7 +53,7 @@ class Article(db.Model):
"""
return Article.query.filter(Article.date < self.date,
Article.feed_id == self.feed_id)\
- .order_by(desc("Article.date")).first()
+ .order_by(desc("date")).first()
def next_article(self):
"""
@@ -63,7 +61,7 @@ class Article(db.Model):
"""
return Article.query.filter(Article.date > self.date,
Article.feed_id == self.feed_id)\
- .order_by(asc("Article.date")).first()
+ .order_by(asc("date")).first()
def __repr__(self):
return "<Article(id=%d, entry_id=%s, title=%r, " \
@@ -81,5 +79,5 @@ class Article(db.Model):
"like": self.like,
"date": self.date,
"retrieved_date": self.retrieved_date,
- "feed_id": getattr(self.source, 'id', None),
- "feed_name": getattr(self.source, 'title', None)}
+ "feed_id": self.feed_id,
+ "category_id": self.category_id}
diff --git a/src/web/models/category.py b/src/web/models/category.py
new file mode 100644
index 00000000..78054809
--- /dev/null
+++ b/src/web/models/category.py
@@ -0,0 +1,11 @@
+from bootstrap import db
+
+
+class Category(db.Model):
+ id = db.Column(db.Integer(), primary_key=True)
+ name = db.Column(db.String())
+
+ user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
+
+ def dump(self):
+ return {key: getattr(self, key) for key in ('id', 'name', 'user_id')}
diff --git a/src/web/models/feed.py b/src/web/models/feed.py
index 59456a7f..7768ee50 100644
--- a/src/web/models/feed.py
+++ b/src/web/models/feed.py
@@ -56,9 +56,10 @@ class Feed(db.Model):
# relationship
icon_url = db.Column(db.String(), db.ForeignKey('icon.url'), default=None)
user_id = db.Column(db.Integer(), db.ForeignKey('user.id'))
+ category_id = db.Column(db.Integer(), db.ForeignKey('category.id'))
articles = db.relationship('Article', backref='source', lazy='dynamic',
cascade='all,delete-orphan',
- order_by=desc("Article.date"))
+ order_by=desc("date"))
def __repr__(self):
return '<Feed %r>' % (self.title)
@@ -66,12 +67,17 @@ class Feed(db.Model):
def dump(self):
return {"id": self.id,
"user_id": self.user_id,
+ "category_id": self.category_id,
"title": self.title,
"description": self.description,
"link": self.link,
"site_link": self.site_link,
"etag": self.etag,
+ "enabled": self.enabled,
+ "filters": self.filters,
"icon_url": self.icon_url,
"error_count": self.error_count,
+ "last_error": self.last_error,
+ "created_date": self.created_date,
"last_modified": self.last_modified,
"last_retrieved": self.last_retrieved}
diff --git a/src/web/models/user.py b/src/web/models/user.py
index c5e70036..d1b9c568 100644
--- a/src/web/models/user.py
+++ b/src/web/models/user.py
@@ -30,7 +30,7 @@ import re
import random
import hashlib
from datetime import datetime
-from werkzeug import generate_password_hash, check_password_hash
+from werkzeug import check_password_hash
from flask.ext.login import UserMixin
from bootstrap import db
@@ -63,12 +63,6 @@ class User(db.Model, UserMixin):
"""
return self.id
- def set_password(self, password):
- """
- Hash the password of the user.
- """
- self.pwdhash = generate_password_hash(password)
-
def check_password(self, password):
"""
Check the password of the user.
@@ -79,7 +73,7 @@ class User(db.Model, UserMixin):
"""
Return True if the user has administrator rights.
"""
- return len([role for role in self.roles if role.name == "admin"]) != 0
+ return "admin" in [role.name for role in self.roles]
def __eq__(self, other):
return self.id == other.id
bgstack15