roundabout,
created on Thursday, 4 January 2024, 20:20:39 (1704399639),
received on Wednesday, 31 July 2024, 06:54:40 (1722408880)
Author identity: vlad <vlad.muntoiu@gmail.com>
5211c8e62c28bbb9f5441861797617613db5b62e
app.py
@@ -294,11 +294,24 @@ def logout():
return flask.redirect("/", code=303) @app.route("/<username>/")@app.route("/<username>/", methods=["GET", "POST"])def userProfile(username): user = User.query.filter_by(username=username).first()repos = Repo.query.filter_by(ownerName=username, visibility=2)return flask.render_template("user-profile.html", user=user, repos=repos)oldRelationship = UserFollow.query.filter_by(followerUsername=flask.session.get("username"), followedUsername=username).first() if flask.request.method == "GET": user = User.query.filter_by(username=username).first() repos = Repo.query.filter_by(ownerName=username, visibility=2) return flask.render_template("user-profile.html", user=user, repos=repos, relationship=oldRelationship) elif request.query.get("action") == "follow": if oldRelationship: db.session.delete(oldRelationship) else: relationship = UserFollow( User.query.filter_by(username=db.session.get("username")), User.query.filter_by(username=username) ) db.session.add(relationship) db.session.commit()@app.route("/<username>/<repository>/")
models.py
@@ -69,11 +69,10 @@ with app.app_context():
creationDate = db.Column(db.DateTime, default=datetime.utcnow) repositories = db.relationship("Repo", back_populates="owner") followers = db.relationship("UserFollow", back_populates="followed")follows = db.relationship("UserFollow", back_populates="follower")followers = db.relationship("UserFollow", back_populates="followed", foreign_keys="[UserFollow.followedUsername]") follows = db.relationship("UserFollow", back_populates="follower", foreign_keys="[UserFollow.followerUsername]")repoAccess = db.relationship("RepoAccess", back_populates="user") votes = db.relationship("PostVote", back_populates="user") generatedNotifications = db.relationship("Notification", back_populates="author")favourites = db.relationship("RepoFavourite", back_populates="user") commits = db.relationship("Commit", back_populates="owner")
@@ -221,20 +220,15 @@ with app.app_context():
class UserFollow(db.Model): id = db.Column(db.Integer, primary_key=True) followerUsername = db.Column(db.String(32), db.ForeignKey("follower.username"), nullable=False)followedUsername = db.Column(db.String(32), db.ForeignKey("followed.username"), nullable=False)followerUsername = db.Column(db.String(32), db.ForeignKey("user.username", ondelete="CASCADE"), nullable=False) followedUsername = db.Column(db.String(32), db.ForeignKey("user.username", ondelete="CASCADE"), nullable=False)follower = db.relationship("User", back_populates="follows")followed = db.relationship("User", back_populates="followers")follower = db.relationship("User", back_populates="follows", foreign_keys=[followedUsername]) followed = db.relationship("User", back_populates="followers", foreign_keys=[followerUsername])def __init__(self, user, notification, level):self.userUsername = user.usernameself.notificationID = notification.idself.attentionLevel = leveldef read(self):self.readTime = datetime.utcnowself.attentionLevel = 0def __init__(self, follower, followed): self.followerUsername = follower.username self.followedUsername = followed.usernameclass Notification(db.Model):
templates/user-profile.html
@@ -38,6 +38,13 @@
{% if user.showMail %} <li><a href="mailto:{{ user.email }}"><x-hbox><iconify-icon icon="mdi:email"></iconify-icon>{{ user.email }}</x-hbox></a></li> {% endif %} {% if loggedInUser != user.username %} <li><form action="?action=follow"> <button type="submit"> {% if relationship %}Unfollow{% else %}Follow{% endif %} </button> </form></li> {% endif %}</ul> </x-hbox> <x-vbox>