Browse Source

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

pull/178/head
Pēteris Caune 7 years ago
parent
commit
e4150e8514
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
3 changed files with 46 additions and 46 deletions
  1. +24
    -17
      hc/accounts/views.py
  2. +5
    -5
      static/css/settings.css
  3. +17
    -24
      templates/accounts/badges.html

+ 24
- 17
hc/accounts/views.py View File

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


+ 5
- 5
static/css/settings.css View File

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


+ 17
- 24
templates/accounts/badges.html View File

@ -28,8 +28,10 @@
<h2 class="settings-title">Status Badges</h2>
<p id="badges-description">
{% site_name %} provides status badges for each of the tags
you have used. The badges have public, but hard-to-guess
URLs. If you wish, you can add them to your READMEs,
you have used. Additionally, the "{% site_name %}"
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.
</p>
@ -43,7 +45,11 @@
</div>
<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>
<td>
<img src="{{ urldict.svg }}" alt="" />
@ -53,20 +59,15 @@
</td>
</tr>
{% endfor %}
<tr>
<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>
{% endfor %}
</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>
<td class="json-response" data-url="{{ urldict.json }}">
</td>
@ -75,15 +76,7 @@
</td>
</tr>
{% endfor %}
<tr>
<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>
{% endfor %}
</table>
</div>
</div>


Loading…
Cancel
Save