Skip to content

Commit

Permalink
store user.api_keys.all in a template variable
Browse files Browse the repository at this point in the history
without this the sql query is repeated twice
  • Loading branch information
catgirlinspace committed Sep 30, 2024
1 parent 6853984 commit cb835d3
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions users/templates/users/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -181,33 +181,35 @@ <h1 class="text-xl font-splatoon1 pt-2">API Keys</h1>
<input type="submit" value="Create API Key">
</form>

{% if user.api_keys.all %}
<table class="w-max table-auto border-collapse">
<thead>
<tr>
<th class="border border-slate-200 p-1">Key</th>
<th class="border border-slate-200 p-1">Note</th>
<th class="border border-slate-200 p-1">Created</th>
<th class="border border-slate-200 p-1">Delete</th>
</tr>
</thead>
<tbody>
{% for api_key in user.api_keys.all %}
{% with api_keys=user.api_keys.all %}
{% if api_keys %}
<table class="w-max table-auto border-collapse">
<thead>
<tr>
<td class="border border-slate-200 p-1 font-mono">{{ api_key.key }}</td>
<td class="border border-slate-200 p-1">{{ api_key.note }}</td>
<td class="border border-slate-200 p-1">{{ api_key.created }}</td>
<td class="border border-slate-200 p-1">
<form action="{% url 'users:delete_api_key' api_key.key %}" method="post">
{% csrf_token %}
<input type="submit" value="">
</form>
</td>
<th class="border border-slate-200 p-1">Key</th>
<th class="border border-slate-200 p-1">Note</th>
<th class="border border-slate-200 p-1">Created</th>
<th class="border border-slate-200 p-1">Delete</th>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
</thead>
<tbody>
{% for api_key in api_keys %}
<tr>
<td class="border border-slate-200 p-1 font-mono">{{ api_key.key }}</td>
<td class="border border-slate-200 p-1">{{ api_key.note }}</td>
<td class="border border-slate-200 p-1">{{ api_key.created }}</td>
<td class="border border-slate-200 p-1">
<form action="{% url 'users:delete_api_key' api_key.key %}" method="post">
{% csrf_token %}
<input type="submit" value="">
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
{% endwith %}
</div>

<div>
Expand Down

0 comments on commit cb835d3

Please sign in to comment.