aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rwxr-xr-xmanager.py16
-rw-r--r--migrations/versions/4b5c161e1ced_.py32
-rw-r--r--pyaggr3g470r/__init__.py1
-rw-r--r--pyaggr3g470r/models/__init__.py38
-rw-r--r--requirements.txt1
6 files changed, 75 insertions, 14 deletions
diff --git a/.gitignore b/.gitignore
index ea272450..e0aaa490 100644
--- a/.gitignore
+++ b/.gitignore
@@ -21,3 +21,4 @@ pyaggr3g470r/var/indexdir/
# Virtualenv
venv
+build
diff --git a/manager.py b/manager.py
new file mode 100755
index 00000000..ca772b60
--- /dev/null
+++ b/manager.py
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+
+from flask.ext.script import Manager
+from flask.ext.migrate import Migrate, MigrateCommand
+
+from pyaggr3g470r import app, db
+
+
+Migrate(app, db)
+
+manager = Manager(app)
+manager.add_command('db', MigrateCommand)
+
+
+if __name__ == '__main__':
+ manager.run()
diff --git a/migrations/versions/4b5c161e1ced_.py b/migrations/versions/4b5c161e1ced_.py
new file mode 100644
index 00000000..e740e827
--- /dev/null
+++ b/migrations/versions/4b5c161e1ced_.py
@@ -0,0 +1,32 @@
+"""empty message
+
+Revision ID: 4b5c161e1ced
+Revises: None
+Create Date: 2015-01-17 01:04:10.187285
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '4b5c161e1ced'
+down_revision = None
+
+from alembic import op
+import sqlalchemy as sa
+
+
+def upgrade():
+ ### commands auto generated by Alembic - please adjust! ###
+ op.add_column('feed', sa.Column('error_count', sa.Integer(), nullable=True))
+ op.add_column('feed', sa.Column('last_error', sa.String(), nullable=True))
+ op.add_column('feed', sa.Column('last_refreshed', sa.DateTime(), nullable=True))
+ op.add_column('user', sa.Column('refresh_rate', sa.Integer(), nullable=True))
+ ### end Alembic commands ###
+
+
+def downgrade():
+ ### commands auto generated by Alembic - please adjust! ###
+ op.drop_column('user', 'refresh_rate')
+ op.drop_column('feed', 'last_refreshed')
+ op.drop_column('feed', 'last_error')
+ op.drop_column('feed', 'error_count')
+ ### end Alembic commands ###
diff --git a/pyaggr3g470r/__init__.py b/pyaggr3g470r/__init__.py
index 4ba54095..0138b4d3 100644
--- a/pyaggr3g470r/__init__.py
+++ b/pyaggr3g470r/__init__.py
@@ -24,6 +24,7 @@ app.config['RECAPTCHA_USE_SSL'] = True
app.config['RECAPTCHA_PUBLIC_KEY'] = conf.RECAPTCHA_PUBLIC_KEY
app.config['RECAPTCHA_PRIVATE_KEY'] = conf.RECAPTCHA_PRIVATE_KEY
+
if conf.ON_HEROKU:
from flask_sslify import SSLify
sslify = SSLify(app)
diff --git a/pyaggr3g470r/models/__init__.py b/pyaggr3g470r/models/__init__.py
index 2618ed73..906d1f8c 100644
--- a/pyaggr3g470r/models/__init__.py
+++ b/pyaggr3g470r/models/__init__.py
@@ -36,22 +36,25 @@ from flask.ext.login import UserMixin
from pyaggr3g470r import db
+
class User(db.Model, UserMixin):
"""
Represent a user.
"""
- id = db.Column(db.Integer, primary_key = True)
- nickname = db.Column(db.String(), unique = True)
- email = db.Column(db.String(254), index = True, unique = True)
+ id = db.Column(db.Integer, primary_key=True)
+ nickname = db.Column(db.String(), unique=True)
+ email = db.Column(db.String(254), index=True, unique=True)
pwdhash = db.Column(db.String())
- roles = db.relationship('Role', backref = 'user', lazy = 'dynamic')
+ roles = db.relationship('Role', backref='user', lazy='dynamic')
activation_key = db.Column(db.String(128), default =
hashlib.sha512(
str(random.getrandbits(256)).encode("utf-8")
).hexdigest()[:86])
date_created = db.Column(db.DateTime(), default=datetime.now)
last_seen = db.Column(db.DateTime(), default=datetime.now)
- feeds = db.relationship('Feed', backref = 'subscriber', lazy = 'dynamic', cascade='all,delete-orphan')
+ feeds = db.relationship('Feed', backref='subscriber', lazy='dynamic',
+ cascade='all,delete-orphan')
+ refresh_rate = db.Column(db.Integer, default=60) # in minutes
@staticmethod
def make_valid_nickname(nickname):
@@ -92,8 +95,8 @@ class Role(db.Model):
"""
Represent a role.
"""
- id = db.Column(db.Integer, primary_key = True)
- name = db.Column(db.String(), unique = True)
+ id = db.Column(db.Integer, primary_key=True)
+ name = db.Column(db.String(), unique=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
@@ -102,7 +105,7 @@ class Feed(db.Model):
"""
Represent a station.
"""
- id = db.Column(db.Integer, primary_key = True)
+ id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(), default="No title")
description = db.Column(db.String(), default="FR")
link = db.Column(db.String())
@@ -110,8 +113,12 @@ class Feed(db.Model):
email_notification = db.Column(db.Boolean(), default=False)
enabled = db.Column(db.Boolean(), default=True)
created_date = db.Column(db.DateTime(), default=datetime.now)
- articles = db.relationship('Article', backref = 'source', lazy = 'dynamic', cascade='all,delete-orphan',
- order_by=desc("Article.date"))
+ last_refreshed = db.Column(db.DateTime(), default=datetime(1970, 1, 1))
+ last_error = db.Column(db.String(), default="")
+ error_count = db.Column(db.Integer(), default=0)
+ articles = db.relationship('Article', backref='source', lazy='dynamic',
+ cascade='all,delete-orphan',
+ order_by=desc("Article.date"))
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
@@ -124,8 +131,7 @@ class Feed(db.Model):
"description": self.description,
"link": self.link,
"site_link": self.site_link,
- "nb_articles": self.articles.count(),
- }
+ "nb_articles": self.articles.count()}
class Article(db.Model):
@@ -149,13 +155,17 @@ class Article(db.Model):
"""
Returns the previous article (older).
"""
- return Article.query.filter(Article.date < self.date, Article.feed_id == self.feed_id).order_by(desc("Article.date")).first()
+ return Article.query.filter(Article.date < self.date,
+ Article.feed_id == self.feed_id)\
+ .order_by(desc("Article.date")).first()
def next_article(self):
"""
Returns the next article (newer).
"""
- return Article.query.filter(Article.date > self.date, Article.feed_id == self.feed_id).order_by(asc("Article.date")).first()
+ return Article.query.filter(Article.date > self.date,
+ Article.feed_id == self.feed_id)\
+ .order_by(asc("Article.date")).first()
def __repr__(self):
return json.dumps({
diff --git a/requirements.txt b/requirements.txt
index 4f9a082f..b2f96657 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -14,6 +14,7 @@ Flask-WTF
Flask-RESTful
Flask-Babel
Flask-SSLify
+Flask-Migrate
WTForms
python-postmark
whoosh
bgstack15