Skip to content

Commit 13e8b1d

Browse files
authored
Merge pull request #570 from geoadmin/bug-PB-1615-property-upload-url
PB-1615: Fix change form template variable lookup error
2 parents d4e7bd7 + daf73d5 commit 13e8b1d

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

app/stac_api/templatetags/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from django import template
2+
3+
register = template.Library()
4+
5+
6+
@register.simple_tag(takes_context=True)
7+
def get_context_variable(context, name, default):
8+
"""Retrieve a context variable from the template context, returning a default value if the
9+
variable is not defined.
10+
11+
Accessing undefined variables will still render the template, but using this function prevents
12+
unnecessary stack traces in the logs.
13+
14+
Use this tag in a template like this:
15+
16+
{% get_context_variable '<name>' <default> as <name> %}
17+
{{ name }}
18+
19+
"""
20+
return context.get(name, default)

app/templates/admin/change_form.html

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{% extends "admin/change_form.html" %}
22
{% load i18n admin_urls %}
3+
{% load context_variables %}
34
{% block object-tools-items %}
5+
{% get_context_variable 'property_upload_url' None as property_upload_url %}
46
{% if property_upload_url %}
57
<li>
68
<a href="upload/" class="historylink">Upload file</a>

0 commit comments

Comments
 (0)