You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.9 KiB

from sqlalchemy import or_
from sqlalchemy.sql import operators
from flask import Blueprint, render_template, request, abort
from hubsrht.types import User, Project, Visibility, Event, EventType
from hubsrht.types import SourceRepo, MailingList, Tracker
from srht.flask import paginate_query
from srht.oauth import current_user
from import search_by
users = Blueprint("users", __name__)
def summary_GET(username):
user = User.query.filter(User.username == username).first()
if not user:
projects = (Project.query
.filter(Project.owner_id ==
events = (Event.query
.filter(Event.user_id ==
if not current_user or !=
projects = projects.filter(Project.visibility == Visibility.PUBLIC)
events = (events
.join(Project, Event.project_id ==
.filter(Project.visibility == Visibility.PUBLIC))
events = (events
.outerjoin(SourceRepo, Event.source_repo_id ==
.outerjoin(MailingList, Event.source_repo_id ==
.outerjoin(Tracker, Event.source_repo_id ==
.filter(or_(Event.source_repo == None, SourceRepo.visibility == Visibility.PUBLIC),
or_(Event.mailing_list == None, MailingList.visibility == Visibility.PUBLIC),
or_(Event.tracker == None, Tracker.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,
def projects_GET(owner):
if owner.startswith("~"):
owner = owner[1:]
owner = User.query.filter(User.username == owner).first()
if not owner:
projects = (Project.query
.filter(Project.owner_id ==
if not current_user or !=
projects = projects.filter(Project.visibility == Visibility.PUBLIC)
search = request.args.get("search")
search_error = None
if search:
projects = search_by(projects, search,
[, Project.description],
key_fns={"tag": lambda t:
Project.tags.any(t, operator=operators.ilike_op)},
term_map=lambda t: f"tag:{t[1:]}" if t.startswith("#") else t)
except ValueError as e:
search_error = str(e)
projects, pagination = paginate_query(projects)
return render_template("projects.html", user=owner, projects=projects,
search=search, search_error=search_error, **pagination)