Skip to content

Commit

Permalink
beautification, truncate repos/commits to :5, add datetime.
Browse files Browse the repository at this point in the history
  • Loading branch information
stnbu committed Sep 10, 2018
1 parent 0c6aaf9 commit a28a19b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
21 changes: 20 additions & 1 deletion gitbored/static/gitbored/style.css
Expand Up @@ -24,12 +24,31 @@ a.commit-link {
list-style: none;
}

.repo-title {
padding-top: 20px;
}

.repo-more-link {
padding-top: 30px;
padding-left: 20px;
}

.commit-list {
list-style: none;
padding-bottom: 10px;
}

.commit-hash {
.commit-header {
width: 75%;
padding-top: 30px;
padding-bottom: 10px;
margin-bottom: 20px;
}

.commit-hash {
float: left;
}

.commit-dt {
float: right;
}
9 changes: 6 additions & 3 deletions gitbored/templates/gitbored/index.html
Expand Up @@ -15,7 +15,7 @@
{% for repo, blurb, commits in repos_list %}
<li class="repo">

<h2 class="repo-title">Repository Name: <a href="{{ repo.html_url }}">{{ repo.name }}</a></h2>
<h1 class="repo-title"><a href="{{ repo.html_url }}">{{ repo.name }}</a></h1>
{% if repo.description %}
<p class="repo-description shadow-box">{{ repo.description }}</p>
{% endif %} {# repo.description #}
Expand All @@ -24,18 +24,21 @@ <h2 class="repo-title">Repository Name: <a href="{{ repo.html_url }}">{{ repo.na
<p class="blurb shadow-box">{{ blurb.blurb }}</p>
{% endif %} {# blurb #}

<h3>Commits...</h3>
<ul class="commit-list">
{% for commit in commits %}
<li class="commit">
<a class="commit-link" href="{{ commit.html_url }}">
<div class="commit-hash">{{ commit.sha }}</div>
<div class="commit-header">
<div class="commit-hash">{{ commit.sha }}</div>
<div class="commit-dt">{{ commit.dt }}</div>
</div>
<div class="rst">
<div class="commit-message shadow-box">{{ commit.message_html|safe }}</div>
</div>
</a>
</li>
{% endfor %} {# commits #}
<li class="repo-more-link"><a href="{{ repo.html_url }}">more from {{ repo.name }}...</a></li>
</ul>
</li>
{% endfor %} {# repos_list #}
Expand Down
20 changes: 19 additions & 1 deletion gitbored/views.py
@@ -1,14 +1,19 @@
from dateutil.parser import parse as parse_dt

from django.shortcuts import get_object_or_404, render
from django.http import HttpResponseRedirect
from .models import Repos, Commits, Blurbs

def get_grouped_commits():
"""Return a list of the format
`[(repo, blurb, [commit, commit, ...], ...]`
`[(repo, blurb, [commit, commit, ...]), ...]`
Each list of commits belongs to the corresponding `repo` (and `blurb`). The tuples are then sorted by
the date of the first commit in the list of commits.
Note that this code assumes a reasonably small amount of data (~ 5 repos x 5 commits). The below is not
especially efficient...
"""
# a temporary dict used to group commits by repo
by_repo = {}
Expand All @@ -29,6 +34,15 @@ def get_grouped_commits():
commits = sorted(commits,
key=lambda c: c.author_date,
reverse=True)

def add_friendly_dt(commit):
commit.dt = parse_dt(commit.author_date).strftime('%Y-%m-%d, %H:%M UTC')
return commit

# truncate to 5 commits
commits = commits[:5]
# add a dt field formatted more nicely
commits = list(map(add_friendly_dt, commits))
grouped_commits.append((repo, blurb, commits))

# sort the tuples by the date of the first commit
Expand All @@ -37,6 +51,10 @@ def get_grouped_commits():
reverse=True)
print(len(grouped_commits))

# truncate to 5 repos
grouped_commits = grouped_commits[:5]
#grouped_commits = map(lambda r: (r[0], r[1], r[2][:5]), grouped_commits)

return grouped_commits


Expand Down

0 comments on commit a28a19b

Please sign in to comment.