diff --git a/README.md b/README.md
index 88cd6e9..48f68d7 100644
--- a/README.md
+++ b/README.md
@@ -32,6 +32,12 @@ Searching with filters such as:
| Name | `string` | textfield |
| Category | `Category` | dropdown |
+## Setup
+When deploying, don't forget to pull the PLZ index and save it to the database using
+```
+python manage.py getplzindex --force
+```
+
## Development
To get started with development, see [DEVELOPMENT.md](DEVELOPMENT.md)
diff --git a/pflaenzli/pflaenzli/templates/offer/detail.html b/pflaenzli/pflaenzli/templates/offer/detail.html
index d4dba70..218d7ef 100644
--- a/pflaenzli/pflaenzli/templates/offer/detail.html
+++ b/pflaenzli/pflaenzli/templates/offer/detail.html
@@ -21,21 +21,21 @@
-
-
+
+
+
{% if offer.user == user %}
{% trans "You" %}
{% else %}
{{ offer.user.username }}
{% endif %}
-
- {% with plz=offer|get_plz %} {{ offer.zipcode }} {{ plz.name }}{% endwith %}
+
+ {% with plz=offer|get_plz %} {{ offer.zipcode }} {{ plz.name }}{% endwith %}
{% if dist %}
-
- ca. {{ dist }} km
+
+ ca. {{ dist }} km
{% endif %}
diff --git a/pflaenzli/pflaenzli/utils/distance.py b/pflaenzli/pflaenzli/utils/distance.py
index df0dea7..9e83b74 100644
--- a/pflaenzli/pflaenzli/utils/distance.py
+++ b/pflaenzli/pflaenzli/utils/distance.py
@@ -7,7 +7,10 @@ def calculate_distance(plz_1: Plz, plz_2: Plz):
if plz_1 == plz_2:
return 0
- dist = round(distance((plz_1.lat, plz_1.lon), (plz_2.lat, plz_2.lon)).kilometers)
+ try:
+ dist = round(distance((plz_1.lat, plz_1.lon), (plz_2.lat, plz_2.lon)).kilometers)
+ except AttributeError:
+ return None
return None if dist > 400 else dist
diff --git a/pflaenzli/pflaenzli/views.py b/pflaenzli/pflaenzli/views.py
index beb492c..766c188 100644
--- a/pflaenzli/pflaenzli/views.py
+++ b/pflaenzli/pflaenzli/views.py
@@ -59,7 +59,10 @@ def offer_detail(request, offer_id):
if offer.zipcode == request.user.zipcode:
dist = 0
else:
- dist = calculate_distance(Plz.objects.get(plz=offer.zipcode), Plz.objects.get(plz=request.user.zipcode))
+ user_plz = get_single_plz(request.user.zipcode)
+ offer_plz = get_single_plz(offer.zipcode)
+
+ dist = calculate_distance(offer_plz, user_plz)
else:
dist = None
else:
@@ -193,6 +196,11 @@ def register_user(request):
return render(request, "basic_form.html", {"form": form, "button_label": _("Register"), "title": _("Registeration"), "umami_event": "User registration", "form_note": mark_safe(_('Please note the
privacy policy'))})
+def get_single_plz(plz):
+ p = Plz.objects.filter(plz=plz)
+ return p[0] if len(p) >= 1 else None
+
+
def save_language(request):
referer_url = request.META.get('HTTP_REFERER')
response = redirect(referer_url)