forked from gergely/calendar-social
Follow users
This commit is contained in:
parent
4cbebb9c5a
commit
ba1a660b1a
@ -266,5 +266,26 @@ class CalendarSocialApp(Flask):
|
|||||||
|
|
||||||
return render_template('profile-details.html', profile=profile)
|
return render_template('profile-details.html', profile=profile)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
@route('/profile/@<string:username>/follow')
|
||||||
|
def follow_user(username):
|
||||||
|
"""View for following a user
|
||||||
|
"""
|
||||||
|
|
||||||
|
from .models import db, Profile, User, UserFollow
|
||||||
|
|
||||||
|
profile = current_user.profile
|
||||||
|
|
||||||
|
if profile is None:
|
||||||
|
abort(404)
|
||||||
|
|
||||||
|
if profile.user != current_user:
|
||||||
|
follow = UserFollow(follower_id=current_user.profile,
|
||||||
|
followed_id=profile,
|
||||||
|
accepted_at=datetime.utcnow())
|
||||||
|
db.session.add(follow)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return redirect(url_for('display_profile', username=username))
|
||||||
|
|
||||||
app = CalendarSocialApp(__name__)
|
app = CalendarSocialApp(__name__)
|
||||||
|
@ -395,3 +395,20 @@ class AuditLog(db.Model):
|
|||||||
message = f'Audit: [{ip}] [{user.id}] ' + cls.get_message(log_type, user=user.username)
|
message = f'Audit: [{ip}] [{user.id}] ' + cls.get_message(log_type, user=user.username)
|
||||||
|
|
||||||
logger.info(message)
|
logger.info(message)
|
||||||
|
|
||||||
|
|
||||||
|
class UserFollow(db.Model):
|
||||||
|
"""Database model for user follows
|
||||||
|
"""
|
||||||
|
|
||||||
|
#: The ID of the profile that is following the other
|
||||||
|
follower_id = db.Column(db.Integer(), db.ForeignKey('profiles.id'), primary_key=True)
|
||||||
|
|
||||||
|
#: The ID of the profile being followed
|
||||||
|
followed_id = db.Column(db.Integer(), db.ForeignKey('profiles.id'), primary_key=True)
|
||||||
|
|
||||||
|
#: The timestamp when the follow was initiated
|
||||||
|
initiated_at = db.Column(db.DateTime(), default=datetime.utcnow, nullable=False)
|
||||||
|
|
||||||
|
#: The timestamp when the follow was accepted
|
||||||
|
accepted_at = db.Column(db.DateTime(), nullable=True)
|
||||||
|
@ -5,4 +5,7 @@
|
|||||||
{{ profile.name }}
|
{{ profile.name }}
|
||||||
<small>@{{ profile.user.username}}</small>
|
<small>@{{ profile.user.username}}</small>
|
||||||
</h1>
|
</h1>
|
||||||
|
{% if profile.user != current_user %}
|
||||||
|
<a href="{{ url_for('follow_user', username=profile.user.username) }}">{% trans %}Follow{% endtrans %}
|
||||||
|
{% endif %}
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
Loading…
Reference in New Issue
Block a user