~edwargix/git.sr.ht

5f05a28c92e5c2ea696213d6b5490a7423b26b4c — Drew DeVault 8 years ago 9bddf29
Add search to user page
3 files changed, 33 insertions(+), 9 deletions(-)

M git/blueprints/public.py
M scss/main.scss
M templates/user.html
M git/blueprints/public.py => git/blueprints/public.py +10 -3
@@ 29,10 29,13 @@ def user_index(username):
    user = User.query.filter(User.username == username).first()
    if not user:
        abort(404)
    search = request.args.get("search")
    repos = Repository.query\
            .filter(Repository.owner_id == user.id)\
            .filter(Repository.visibility == RepoVisibility.public)\
            .order_by(Repository.updated.desc()).all()
            .filter(Repository.visibility == RepoVisibility.public)
    if search:
        repos = repos.filter(Repository.name.ilike("%" + search + "%"))
    repos = repos.order_by(Repository.updated.desc()).all()
    r = requests.get(meta_uri + "/api/user/profile", headers={
        "Authorization": "token " + user.oauth_token
    }) # TODO: cache


@@ 40,4 43,8 @@ def user_index(username):
        profile = r.json()
    else:
        profile = None
    return render_template("user.html", user=user, repos=repos, profile=profile)
    return render_template("user.html",
            user=user,
            repos=repos,
            profile=profile,
            search=search)

M scss/main.scss => scss/main.scss +6 -0
@@ 1,6 1,12 @@
@import "base";
@import "cgit";

.filter-repos {
  .btn {
    height: 1.9rem;
  }
}

div#cgit {
  padding: 0;
  font-size: inherit;

M templates/user.html => templates/user.html +17 -6
@@ 3,7 3,9 @@
<div class="container">
  <div class="row">
    <section class="col-md-4">
      <h2>~{{ user.username }}</h2>
      <h2>
        ~{{ user.username }}
      </h2>
      {% if profile.get("location") %}
      <p>{{profile["location"]}}</p>
      {% endif %}


@@ 22,18 24,27 @@
      {% if len(repos) == 0 %}
      <p>This user has no repositories.</p>
      {% else %}
      <form>
        <input
          name="search"
          type="text"
          placeholder="Search"
          class="form-control"
          value="{{ search if search else "" }}"
          />
      </form>
      {% for repo in repos %}
        <h4>
          <a href="/~{{current_user.username}}/{{repo.name}}">
            ~{{current_user.username}}/{{repo.name}}
          </a>
        </h4>
        {% if not repo.description %}
        <em>This repository has no description</em>
        {% else %}
        {{ repo.description }}
        {% if repo.description %}
        <p>{{ repo.description }}</p>
        {% endif %}
        <p><em>Last updated {{ repo.updated | date }}</em></p>
        <p>
          <em class="text-muted">Last updated {{ repo.updated | date }}</em>
        </p>
      {% endfor %}
      {% endif %}
    </section>