Settings > Badges page shows badges from all teams user has access to.

This commit is contained in:
Pēteris Caune 2018-06-15 01:07:52 +03:00
parent 9cbd0138da
commit e4150e8514
No known key found for this signature in database
GPG Key ID: E28D7679E9A9EDE2
3 changed files with 46 additions and 46 deletions

View File

@ -252,28 +252,35 @@ def notifications(request):
def badges(request): def badges(request):
_ensure_own_team(request) _ensure_own_team(request)
tags = set() teams = [request.profile]
for check in Check.objects.filter(user=request.team.user): for membership in request.user.memberships.all():
tags.update(check.tags_list()) teams.append(membership.team)
username = request.user.username badge_sets = []
urls = [] for team in teams:
for tag in sorted(tags, key=lambda s: s.lower()): tags = set()
if not re.match("^[\w-]+$", tag): for check in Check.objects.filter(user=team.user):
continue tags.update(check.tags_list())
urls.append({ sorted_tags = sorted(tags, key=lambda s: s.lower())
"svg": get_badge_url(username, tag), sorted_tags.append("*") # For the "overall status" badge
"json": get_badge_url(username, tag, format="json"),
}) urls = []
username = team.user.username
for tag in sorted_tags:
if not re.match("^[\w-]+$", tag) and tag != "*":
continue
urls.append({
"svg": get_badge_url(username, tag),
"json": get_badge_url(username, tag, format="json"),
})
badge_sets.append({"team": team, "urls": urls})
ctx = { ctx = {
"page": "profile", "page": "profile",
"urls": urls, "badges": badge_sets
"master": {
"svg": get_badge_url(username, "*"),
"json": get_badge_url(username, "*", format="json")
}
} }
return render(request, "accounts/badges.html", ctx) return render(request, "accounts/badges.html", ctx)

View File

@ -11,10 +11,6 @@
padding-bottom: 24px; padding-bottom: 24px;
} }
#badges-description, #b-format {
margin-bottom: 24px;
}
.page-profile .icon-ok { .page-profile .icon-ok {
color: #5cb85c; color: #5cb85c;
} }
@ -33,7 +29,11 @@
border-top: 0; border-top: 0;
} }
.table td.have-tags { .table.badges th {
border-top: 0;
color: #777777;
font-weight: normal;
font-size: 12px;
padding-top: 32px; padding-top: 32px;
} }

View File

@ -28,8 +28,10 @@
<h2 class="settings-title">Status Badges</h2> <h2 class="settings-title">Status Badges</h2>
<p id="badges-description"> <p id="badges-description">
{% site_name %} provides status badges for each of the tags {% site_name %} provides status badges for each of the tags
you have used. The badges have public, but hard-to-guess you have used. Additionally, the "{% site_name %}"
URLs. If you wish, you can add them to your READMEs, badge shows the overall status of all checks in your
account. The badges have public, but hard-to-guess
URLs. You can use them to your READMEs,
dashboards or status pages. dashboards or status pages.
</p> </p>
@ -43,7 +45,11 @@
</div> </div>
<table id="badges-svg" class="badges table"> <table id="badges-svg" class="badges table">
{% for urldict in urls %} {% for badge_set in badges %}
<tr>
<th colspan="2">{{ badge_set.team }}</th>
</tr>
{% for urldict in badge_set.urls %}
<tr> <tr>
<td> <td>
<img src="{{ urldict.svg }}" alt="" /> <img src="{{ urldict.svg }}" alt="" />
@ -53,20 +59,15 @@
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}
<tr> {% endfor %}
<td class="overall-status {% if urls %}have-tags{% endif %}" colspan="2">Overall status:</td>
</tr>
<tr>
<td>
<img src="{{ master.svg }}" alt="" />
</td>
<td class="svg-url">
<code>{{ master.svg }}</code>
</td>
</tr>
</table> </table>
<table id="badges-json" class="badges table"> <table id="badges-json" class="badges table">
{% for urldict in urls %} {% for badge_set in badges %}
<tr>
<th colspan="2">{{ badge_set.team }}</th>
</tr>
{% for urldict in badge_set.urls %}
<tr> <tr>
<td class="json-response" data-url="{{ urldict.json }}"> <td class="json-response" data-url="{{ urldict.json }}">
</td> </td>
@ -75,15 +76,7 @@
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}
<tr> {% endfor %}
<td class="overall-status {% if urls %}have-tags{% endif %}"" colspan="2">Overall status:</td>
</tr>
<tr>
<td class="json-response" data-url="{{ master.json }}">
<td class="json-url">
<code>{{ master.json }}</code>
</td>
</tr>
</table> </table>
</div> </div>
</div> </div>