Compare commits

...

3 commits

Author SHA1 Message Date
Jannis Portmann
2707916d2f Add reminder for plzindex
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is failing
2023-10-15 17:29:26 +02:00
Jannis Portmann
ac2403bfb8 Display information in rows instead of columns 2023-10-15 17:29:10 +02:00
Jannis Portmann
5040d139b5 Handle multiple locations with same PLZ 2023-10-15 17:28:16 +02:00
4 changed files with 26 additions and 10 deletions

View file

@ -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)

View file

@ -21,21 +21,21 @@
<h1 class="mb-3">
{{ offer.title }}<span class="ms-2 badge text-bg-secondary">{{ offer.get_category_display }}</span>
</h1>
<div class="mb-3 d-flex column-gap-2">
<p class="mr-3">
<i class="fas fa-user"></i>
<div class="mb-3 d-flex flex-column">
<p class="mb-1">
<i class="fas fa-user me-1"></i>
{% if offer.user == user %}
{% trans "You" %}
{% else %}
{{ offer.user.username }}
{% endif %}
</p>
<p class="mr-3">
{% with plz=offer|get_plz %}<i class="fas fa-map-marker-alt"></i> {{ offer.zipcode }} {{ plz.name }}{% endwith %}
<p class="mb-1">
{% with plz=offer|get_plz %}<i class="fas fa-map-marker-alt me-1"></i> {{ offer.zipcode }} {{ plz.name }}{% endwith %}
</p>
{% if dist %}
<p class="pr-3">
<i class="fas fa-map-signs mr-1"></i> ca. {{ dist }} km
<p class="mb-1">
<i class="fas fa-map-signs me-1"></i> ca. {{ dist }} km
</p>
{% endif %}
</div>

View file

@ -7,7 +7,10 @@ def calculate_distance(plz_1: Plz, plz_2: Plz):
if plz_1 == plz_2:
return 0
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

View file

@ -59,8 +59,10 @@ def offer_detail(request, offer_id):
if offer.zipcode == request.user.zipcode:
dist = 0
else:
dist = calculate_distance(Plz.objects.filter(plz=offer.zipcode)[
0], Plz.objects.filter(plz=request.user.zipcode)[0])
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:
@ -194,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 <a href="/imprint">privacy policy</a>'))})
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)