Display following/followed users on the profile page

This commit was merged in pull request #42.
This commit is contained in:
2018-07-09 13:04:55 +02:00
부모 ba1a660b1a
커밋 f1fab33c8d
2개의 변경된 파일46개의 추가작업 그리고 0개의 파일을 삭제

파일 보기

@@ -194,6 +194,32 @@ class Profile(db.Model): # pylint: disable=too-few-public-methods
return f'<Profile {self.id}(@{username}{domain})>'
@property
def followed_list(self):
"""List of profiles this profile is following
"""
# This will always be empty for remote profiles
if not self.user:
return []
return Profile.query \
.join(UserFollow.followed) \
.filter(UserFollow.follower == self)
@property
def follower_list(self):
"""List of profiles that follow this profile
"""
# This will always be empty for remote profiles
if not self.user:
return []
return Profile.query \
.join(UserFollow.follower) \
.filter(UserFollow.followed == self)
class Event(db.Model):
"""Database model for events
@@ -404,9 +430,13 @@ class UserFollow(db.Model):
#: The ID of the profile that is following the other
follower_id = db.Column(db.Integer(), db.ForeignKey('profiles.id'), primary_key=True)
follower = db.relationship('Profile', foreign_keys=[follower_id])
#: The ID of the profile being followed
followed_id = db.Column(db.Integer(), db.ForeignKey('profiles.id'), primary_key=True)
followed = db.relationship('Profile', foreign_keys=[followed_id])
#: The timestamp when the follow was initiated
initiated_at = db.Column(db.DateTime(), default=datetime.utcnow, nullable=False)

파일 보기

@@ -8,4 +8,20 @@
{% if profile.user != current_user %}
<a href="{{ url_for('follow_user', username=profile.user.username) }}">{% trans %}Follow{% endtrans %}
{% endif %}
<h2>
{% trans %}Follows{% endtrans %}
</h2>
{% for followed in profile.followed_list %}
{{ followed }}
{% endfor %}
<h2>
{% trans %}Followers{% endtrans %}
</h2>
{% for follower in profile.follower_list %}
{{ follower }}
{% endfor %}
{% endblock content %}