forked from gergely/calendar-social
Display following/followed users on the profile page
This commit is contained in:
parent
ba1a660b1a
commit
f1fab33c8d
@ -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 %}
|
||||
|
Loading…
Reference in New Issue
Block a user