Skip to content

Commit 7cbda87

Browse files
committed
Generate sidebar via template tag
1 parent bebef8e commit 7cbda87

File tree

5 files changed

+52
-35
lines changed

5 files changed

+52
-35
lines changed

src/sentry/api/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from datetime import datetime, timedelta
2+
from enum import Enum
23
from pytz import utc
34
from rest_framework.authentication import SessionAuthentication
45
from rest_framework.parsers import JSONParser
@@ -20,7 +21,7 @@
2021
LINK_HEADER = '<{uri}&cursor={cursor}>; rel="{name}"'
2122

2223

23-
class DocSection(object):
24+
class DocSection(Enum):
2425
ACCOUNTS = 'Accounts API'
2526
TEAMS = 'Teams API'
2627
PROJECTS = 'Projects API'

src/sentry/templates/sentry/help/api_index.html

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@
44
{% load sentry_helpers %}
55

66
{% block breadcrumbs %}
7-
{{ block.super }}
8-
<li class="divider">/</li>
9-
<li>API</li>
10-
<li class="divider">/</li>
11-
<li><a href="{% url 'sentry-help-platform-list' %}">Web API</a></li>
12-
7+
{{ block.super }}
8+
<li class="divider">/</li>
9+
<li>API</li>
10+
<li class="divider">/</li>
11+
<li><a href="{% url 'sentry-help-platform-list' %}">Web API</a></li>
1312
{% endblock%}
1413

1514
{% block main %}
16-
1715
<h2>Web API</h2>
1816

1917
<p>API requests are made using project-level API keys. They're passed using HTTP Basic auth where the username is your public key, and the password is your secret key. The API key must also be configured with "Web API access" as a role.</p>
@@ -36,7 +34,6 @@ <h2>Web API</h2>
3634
id: "4"
3735
}]</pre>
3836

39-
4037
{% for section in section_list %}
4138
<br>
4239
<h3>{{ section.name }}</h3>

src/sentry/templates/sentry/help/index.html

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{% extends "sentry/bases/modal.html" %}
22

33
{% load i18n %}
4+
{% load sentry_docs %}
45
{% load sentry_helpers %}
56

67
{% block heading %}{% endblock %}
@@ -13,32 +14,7 @@
1314
<div class="row">
1415
<div class="col-sm-3 sidebar">
1516
{% block sidebar %}
16-
<h4>Guides</h4>
17-
<ul>
18-
{% for page in page_list %}
19-
<li><a href="{% url 'sentry-help-page' page.id page.slug %}">{{ page.title }}</a></li>
20-
{% endfor %}
21-
</ul>
22-
23-
<h4>Clients</h4>
24-
<ul>
25-
<li class="{% block client_overview_class %}{% endblock %}"><a href="{% url 'sentry-help-platform-list' %}">Overview</a></li>
26-
<li class="{% ifequal platform "python" %}active{% endifequal %}"><a href="{% url 'sentry-help-platform' 'python' %}">Python</a></li>
27-
<li class="{% ifequal platform "php" %}active{% endifequal %}"><a href="{% url 'sentry-help-platform' 'php' %}">PHP</a></li>
28-
<li class="{% ifequal platform "ruby" %}active{% endifequal %}"><a href="{% url 'sentry-help-platform' 'ruby' %}">Ruby</a></li>
29-
<li class="{% ifequal platform "javascript" %}active{% endifequal %}"><a href="{% url 'sentry-help-platform' 'javascript' %}">JavaScript</a></li>
30-
<li class="{% ifequal platform "java" %}active{% endifequal %}"><a href="{% url 'sentry-help-platform' 'java' %}">Java</a></li>
31-
<li class="{% ifequal platform "node.js" %}active{% endifequal %}"><a href="{% url 'sentry-help-platform' 'node.js' %}">Node.js</a></li>
32-
<li class="{% ifequal platform "ios" %}active{% endifequal %}"><a href="{% url 'sentry-help-platform' 'ios' %}">iOS</a></li>
33-
<li class="{% ifequal platform "go" %}active{% endifequal %}"><a href="{% url 'sentry-help-platform' 'go' %}">Go</a></li>
34-
</ul>
35-
36-
<h4>API Reference</h4>
37-
<ul>
38-
<li><a href="{% url 'sentry-api-0-help' %}">Web API</a></li>
39-
<li><a href="http://sentry.readthedocs.org/en/latest/developer/client/index.html">Client API</a></li>
40-
</ul>
41-
17+
{% render_doc_sidebar %}
4218
{% endblock %}
4319
</div>
4420
<div class="col-sm-9 main">
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<h4>Guides</h4>
2+
<ul>
3+
{% for page in page_list %}
4+
<li><a href="{% url 'sentry-help-page' page.id page.slug %}">{{ page.title }}</a></li>
5+
{% endfor %}
6+
</ul>
7+
8+
<h4>Clients</h4>
9+
<ul>
10+
<li class="{% block client_overview_class %}{% endblock %}"><a href="{% url 'sentry-help-platform-list' %}">Overview</a></li>
11+
<li class="{% ifequal platform "python" %}active{% endifequal %}"><a href="{% url 'sentry-help-platform' 'python' %}">Python</a></li>
12+
<li class="{% ifequal platform "php" %}active{% endifequal %}"><a href="{% url 'sentry-help-platform' 'php' %}">PHP</a></li>
13+
<li class="{% ifequal platform "ruby" %}active{% endifequal %}"><a href="{% url 'sentry-help-platform' 'ruby' %}">Ruby</a></li>
14+
<li class="{% ifequal platform "javascript" %}active{% endifequal %}"><a href="{% url 'sentry-help-platform' 'javascript' %}">JavaScript</a></li>
15+
<li class="{% ifequal platform "java" %}active{% endifequal %}"><a href="{% url 'sentry-help-platform' 'java' %}">Java</a></li>
16+
<li class="{% ifequal platform "node.js" %}active{% endifequal %}"><a href="{% url 'sentry-help-platform' 'node.js' %}">Node.js</a></li>
17+
<li class="{% ifequal platform "ios" %}active{% endifequal %}"><a href="{% url 'sentry-help-platform' 'ios' %}">iOS</a></li>
18+
<li class="{% ifequal platform "go" %}active{% endifequal %}"><a href="{% url 'sentry-help-platform' 'go' %}">Go</a></li>
19+
</ul>
20+
21+
<h4>API Reference</h4>
22+
<ul>
23+
<li><a href="{% url 'sentry-api-0-help' %}">Overview</a></li>
24+
{% for section_key, section_label in api_sections %}
25+
<li><a href="{% url 'sentry-api-0-help' %}">{{ section_label }}</a></li>
26+
{% endfor %}
27+
<li><a href="http://sentry.readthedocs.org/en/latest/developer/client/index.html">Client Specification</a></li>
28+
</ul>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from django import template
2+
3+
from sentry.api.base import DocSection
4+
5+
register = template.Library()
6+
7+
8+
@register.inclusion_tag('sentry/help/sidebar.html', takes_context=True)
9+
def render_doc_sidebar(context):
10+
api_sections = sorted(((v.name, v.value) for v in DocSection),
11+
key=lambda x: x[1])
12+
13+
return {
14+
'api_sections': api_sections,
15+
}

0 commit comments

Comments
 (0)