|
@@ -16,7 +16,7 @@ from werkzeug import generate_password_hash, check_password_hash
|
|
from flask import current_app
|
|
from flask import current_app
|
|
from flask.ext.login import UserMixin, AnonymousUserMixin
|
|
from flask.ext.login import UserMixin, AnonymousUserMixin
|
|
from flaskbb.extensions import db, cache
|
|
from flaskbb.extensions import db, cache
|
|
-from flaskbb.forum.models import Post, Topic
|
|
+from flaskbb.forum.models import Post, Topic, topictracker
|
|
|
|
|
|
|
|
|
|
groups_users = db.Table('groups_users',
|
|
groups_users = db.Table('groups_users',
|
|
@@ -90,6 +90,12 @@ class User(db.Model, UserMixin):
|
|
backref=db.backref('users', lazy='dynamic'),
|
|
backref=db.backref('users', lazy='dynamic'),
|
|
lazy='dynamic')
|
|
lazy='dynamic')
|
|
|
|
|
|
|
|
+ tracked_topics = \
|
|
|
|
+ db.relationship("Topic", secondary=topictracker,
|
|
|
|
+ primaryjoin=(topictracker.c.user_id == id),
|
|
|
|
+ backref=db.backref("topicstracked", lazy="dynamic"),
|
|
|
|
+ lazy="dynamic")
|
|
|
|
+
|
|
def __repr__(self):
|
|
def __repr__(self):
|
|
return "Username: %s" % self.username
|
|
return "Username: %s" % self.username
|
|
|
|
|
|
@@ -177,6 +183,29 @@ class User(db.Model, UserMixin):
|
|
return Post.query.filter(Post.user_id == self.id).\
|
|
return Post.query.filter(Post.user_id == self.id).\
|
|
paginate(page, current_app.config['TOPICS_PER_PAGE'], False)
|
|
paginate(page, current_app.config['TOPICS_PER_PAGE'], False)
|
|
|
|
|
|
|
|
+ def track_topic(self, topic):
|
|
|
|
+ """
|
|
|
|
+ Tracks the specified topic
|
|
|
|
+ """
|
|
|
|
+ if not self.is_tracking_topic(topic):
|
|
|
|
+ self.tracked_topics.append(topic)
|
|
|
|
+ return self
|
|
|
|
+
|
|
|
|
+ def untrack_topic(self, topic):
|
|
|
|
+ """
|
|
|
|
+ Untracks the specified topic
|
|
|
|
+ """
|
|
|
|
+ if self.is_following_topic(topic):
|
|
|
|
+ self.tracked_topics.remove(topic)
|
|
|
|
+ return self
|
|
|
|
+
|
|
|
|
+ def is_tracking_topic(self, topic):
|
|
|
|
+ """
|
|
|
|
+ Checks if the user is already tracking this topic
|
|
|
|
+ """
|
|
|
|
+ return self.tracked_topics.filter(
|
|
|
|
+ topictracker.c.topic_id == topic.id).count() > 0
|
|
|
|
+
|
|
def add_to_group(self, group):
|
|
def add_to_group(self, group):
|
|
"""
|
|
"""
|
|
Adds the user to the `group` if he isn't in it.
|
|
Adds the user to the `group` if he isn't in it.
|