roundabout,
created on Friday, 5 January 2024, 20:36:58 (1704487018),
received on Wednesday, 31 July 2024, 06:54:40 (1722408880)
Author identity: vlad <vlad.muntoiu@gmail.com>
65e057ebec0a1bd330951a900097042ffb2bbd4e
app.py
@@ -299,20 +299,29 @@ def userProfile(username):
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 flask.request.args.get("action") == "follow":if oldRelationship:db.session.delete(oldRelationship)else:relationship = UserFollow(flask.session.get("username"),username)db.session.add(relationship)db.session.commit()return flask.redirect("?", code=303)match flask.request.args.get("action"): case "repositories": repos = Repo.query.filter_by(ownerName=username, visibility=2) return flask.render_template("user-profile-repositories.html", user=user, repos=repos, relationship=oldRelationship) case "followers": return flask.render_template("user-profile-followers.html", user=user, repos=repos, relationship=oldRelationship) case _: return flask.render_template("user-profile-overview.html", user=user, relationship=oldRelationship) elif flask.request.method == "POST": match flask.request.args.get("action"): case "follow": if oldRelationship: db.session.delete(oldRelationship) else: relationship = UserFollow( flask.session.get("username"), username ) db.session.add(relationship) db.session.commit() return flask.redirect("?", code=303)@app.route("/<username>/<repository>/")
templates/user-profile-overview.html
@@ -0,0 +1,49 @@
{% extends "user-profile.html" %} {% block content %} <x-frame style="--width: 768px;"> <x-vbox> <x-hbox style="align-items: center;"> <img src="/info/{{ user.username }}/avatar" class="avatar" style="width: 128px; height: 128px;"> <x-vbox class="nopad"> {% if user.displayName and user.displayName != user.username %} <hgroup id="username"> <h1>{{ user.displayName }}</h1> <p>{{ user.username }}</p> </hgroup> {% else %} <h1 class="headline">{{ user.username }}</h1> {% endif %} </x-vbox> <div class="flexible-space"></div> <ul class="noindent" style="list-style: none; text-align: end;"> {% if user.URL %} <li><a href="{{ user.URL }}"><x-hbox><iconify-icon icon="ic:outline-web"></iconify-icon>{{ user.URL }}</x-hbox></a></li> {% endif %} {% if user.companyURL %} <li><a href="{{ user.companyURL }}"><x-hbox><iconify-icon icon="ic:baseline-business-center"></iconify-icon>{{ user.company }}</x-hbox></a></li> {% elif user.company %} <li><x-hbox><iconify-icon icon="ic:baseline-business-center"></iconify-icon>{{ user.company }}</x-hbox></li> {% endif %} {% if user.location %} <li><x-hbox><iconify-icon icon="mdi:map-marker-radius"></iconify-icon>{{ user.location }}</x-hbox></li> {% endif %} {% 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 %} </ul> </x-hbox> <x-vbox> {% if user.bio %} <article class="card" style="flex: 0 1 auto;"> <section class="card-main"> <p> {{ user.bio }} </p> </section> </article> {% endif %} </x-vbox> </x-vbox> </x-frame> {% endblock %}
templates/user-profile-repositories.html
@@ -0,0 +1,21 @@
{% extends "user-profile.html" %} {% block content %} <x-frame style="--width: 768px;"> <article class="card" style="flex: 0 1 auto;"> <section class="card-main"> <ul style="list-style: none;" class="noindent"> {% for repo in repos %} <li> <article> <a href="{{ repo.route }}"><h3>{{ repo.name }}</h3></a> {% if repo.info %} <p>{{ repo.info }}</p> {% endif %} </article> </li> {% endfor %} </ul> </section> </article> </x-frame> {% endblock %}
templates/user-profile.html
@@ -5,77 +5,22 @@
{% block breadcrumbs %} <li><a href="/{{ user.username }}">{{ user.username }}</a></li> {% endblock %} {% block content %}<x-frame style="--width: 768px;"><x-vbox><x-hbox style="align-items: center;"><img src="/info/{{ user.username }}/avatar" class="avatar" style="width: 128px; height: 128px;"><x-vbox class="nopad">{% if user.displayName and user.displayName != user.username %}<hgroup id="username"><h1>{{ user.displayName }}</h1><p>{{ user.username }}</p></hgroup>{% else %}<h1 class="headline">{{ user.username }}</h1>{% endif %}</x-vbox><div class="flexible-space"></div><ul class="noindent" style="list-style: none; text-align: end;">{% if user.URL %}<li><a href="{{ user.URL }}"><x-hbox><iconify-icon icon="ic:outline-web"></iconify-icon>{{ user.URL }}</x-hbox></a></li>{% endif %}{% if user.companyURL %}<li><a href="{{ user.companyURL }}"><x-hbox><iconify-icon icon="ic:baseline-business-center"></iconify-icon>{{ user.company }}</x-hbox></a></li>{% elif user.company %}<li><x-hbox><iconify-icon icon="ic:baseline-business-center"></iconify-icon>{{ user.company }}</x-hbox></li>{% endif %}{% if user.location %}<li><x-hbox><iconify-icon icon="mdi:map-marker-radius"></iconify-icon>{{ user.location }}</x-hbox></li>{% endif %}{% 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 and loggedInUser %}<li><form action="?action=follow" method="POST"><button type="submit">{% if relationship %}Unfollow{% else %}Follow{% endif %}</button></form></li>{% endif %}</ul></x-hbox><x-vbox>{% if user.bio %}<article class="card" style="flex: 0 1 auto;"><section class="card-main"><p>{{ user.bio }}</p></section></article>{% endif %}<h2>Repositories</h2><article class="card" style="flex: 0 1 auto;"><section class="card-main"><ul style="list-style: none;" class="noindent">{% for repo in repos %}<li><article><a href="{{ repo.route }}"><h3>{{ repo.name }}</h3></a>{% if repo.info %}<p>{{ repo.info }}</p>{% endif %}</article></li>{% endfor %}</ul></section></article></x-vbox></x-vbox></x-frame>{% block nav %} <nav id="repo-nav" class="navbar"> <ul id="repo-tabs"> <li><a href="?">Overview</a></li> <li><a href="?action=repositories">Repositories</a></li> </ul> <x-buttonbox> {% if loggedInUser != user.username and loggedInUser %} <form action="?action=follow" method="POST"> <button type="submit"> <iconify-icon icon="mdi:eye"></iconify-icon> {% if relationship %}Unfollow{% else %}Follow{% endif %} </button> </form> {% endif %} </x-buttonbox> </nav>{% endblock %}