diff --git a/hubsrht/blueprints/users.py b/hubsrht/blueprints/users.py index 38e42a6..1c28c39 100644 --- a/hubsrht/blueprints/users.py +++ b/hubsrht/blueprints/users.py @@ -1,11 +1,48 @@ -from flask import Blueprint +from flask import Blueprint, render_template +from hubsrht.types import User, Project, Visibility, Event, EventType +from srht.flask import paginate_query +from srht.oauth import current_user users = Blueprint("users", __name__) @users.route("/~") def summary_GET(username): - pass # TODO + user = User.query.filter(User.username == username).first() + if not user: + abort(404) + projects = (Project.query + .filter(Project.owner_id == current_user.id) + .order_by(Project.updated.desc())) + events = (Event.query + .filter(Event.user_id == current_user.id) + .order_by(Event.created.desc())) + + if not current_user or current_user.id != user.id: + # TODO: ACLs + projects = projects.filter(Project.visibility == Visibility.public) + events = (events + .join(Project) + .filter(Project.visibility == Visibility.public)) + + projects = projects.limit(5).all() + events, pagination = paginate_query(events) + + return render_template("profile.html", + user=user, projects=projects, EventType=EventType, events=events, + **pagination) @users.route("/projects/") def projects_GET(owner): - pass # TODO + if owner.startswith("~"): + owner = owner[1:] + owner = User.query.filter(User.username == owner).first() + if not owner: + abort(404) + projects = (Project.query + .filter(Project.owner_id == owner.id)) + if not current_user or current_user.id != owner.id: + # TODO: ACLs + projects = projects.filter(Project.visibility == Visibility.public) + projects, pagination = paginate_query(projects) + return render_template("projects.html", user=owner, projects=projects, + **pagination) diff --git a/hubsrht/templates/dashboard.html b/hubsrht/templates/dashboard.html index 48bc98d..ede4a03 100644 --- a/hubsrht/templates/dashboard.html +++ b/hubsrht/templates/dashboard.html @@ -7,7 +7,7 @@

- Welcome back, {{current_user.canonical_name}}! + Welcome back, {{current_user.username}}! This is the {{cfg("sr.ht", "site-name")}} hub service, which organizes and indexes projects and users on the platform.

@@ -59,7 +59,8 @@
@@ -75,9 +76,9 @@
More events {{icon("caret-right")}} + >More on your profile {{icon("caret-right")}}
diff --git a/hubsrht/templates/profile.html b/hubsrht/templates/profile.html new file mode 100644 index 0000000..de1fd43 --- /dev/null +++ b/hubsrht/templates/profile.html @@ -0,0 +1,83 @@ +{% extends "layout.html" %} +{% import "event.html" as eventutil with context %} +{% block title %} +{{user.canonical_name}} on {{cfg("sr.ht", "site-name")}} +{% endblock %} +{% block content %} +
+
+

+ {{user.canonical_name}} +

+ {% if user.location %} +

{{user.location}}

+ {% endif %} + {% if user.url %} +

+ {{user.url}} +

+ {% endif %} + {% if user.bio %} +

{{user.bio | md}}

+ {% endif %} +
+
+
+
+
+
+ + {% if search_error %} +
{{ search_error }}
+ {% endif %} +
+
+ {% for project in projects %} +
+

+ {% if project.visibility.value != 'public' %} + {{project.visibility.value}} + {% endif %} + {{project.name}} +

+

{{project.description}}

+
+ {% endfor %} +
+ +
+
+
+
+
+

Activity

+ {% for event in events %} + {{ eventutil.event(event, project=True) }} + {% endfor %} + {{pagination()}} +
+
+
+
+{% endblock %} + diff --git a/hubsrht/templates/projects.html b/hubsrht/templates/projects.html new file mode 100644 index 0000000..6690e6b --- /dev/null +++ b/hubsrht/templates/projects.html @@ -0,0 +1,63 @@ +{% extends "layout.html" %} +{% import "event.html" as eventutil with context %} +{% block title %} +{{user.canonical_name}}'s projects - {{cfg("sr.ht", "site-name")}} +{% endblock %} +{% block content %} +
+
+

+ {{user.canonical_name}} +

+ {% if user.location %} +

{{user.location}}

+ {% endif %} + {% if user.url %} +

+ {{user.url}} +

+ {% endif %} + {% if user.bio %} +

{{user.bio | md}}

+ {% endif %} +
+
+
+ + {% if search_error %} +
{{ search_error }}
+ {% endif %} +
+
+ {% for project in projects %} +
+

+ {% if project.visibility.value != 'public' %} + {{project.visibility.value}} + {% endif %} + {{project.name}} +

+

{{project.description}}

+
+ {% endfor %} +
+ {{pagination()}} +
+
+{% endblock %} +