Render distance in offer detail
This commit is contained in:
parent
821ad78dd6
commit
9724b7f32e
|
@ -27,9 +27,9 @@
|
|||
<p class="mr-3">
|
||||
<i class="fas fa-map-marker-alt"></i> {{ offer.zipcode }}
|
||||
</p>
|
||||
{% if distance > 0 %}
|
||||
{% if dist %}
|
||||
<p class="pr-3">
|
||||
<i class="fas fa-map-signs mr-1"></i>ca. {{ distance }} km
|
||||
<i class="fas fa-map-signs mr-1"></i> ca. {{ dist }} km
|
||||
</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
|
|
@ -8,6 +8,9 @@ df = read_pickle(os.path.join(path, 'plz.pkl'))
|
|||
|
||||
|
||||
def calculate_distance(zip_1, zip_2):
|
||||
if zip_1 == zip_2:
|
||||
return None
|
||||
|
||||
zip_1_coords = tuple(df[df.index == zip_1].values)
|
||||
zip_2_coords = tuple(df[df.index == zip_2].values)
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ from .forms import CreateOfferForm, RegistrationForm
|
|||
from .models import PflaenzliUser, Offer, Wish
|
||||
from .mail import send_offer_email
|
||||
from .upload import generate_unique_filename
|
||||
from .utils.distance import calculate_distance
|
||||
|
||||
|
||||
def list_offers(request, filters=None):
|
||||
|
@ -39,8 +40,12 @@ def create_offer(request):
|
|||
def offer_detail(request, offer_id):
|
||||
offer = get_object_or_404(Offer, id=offer_id)
|
||||
wishes = Wish.objects.filter(user=offer.user)
|
||||
if offer.zipcode and request.user.zipcode:
|
||||
dist = calculate_distance(offer.zipcode, request.user.zipcode)
|
||||
else:
|
||||
dist = None
|
||||
|
||||
return render(request, "offer/detail.html", {"offer": offer, "wishes": wishes})
|
||||
return render(request, "offer/detail.html", {"offer": offer, "wishes": wishes, "dist": dist})
|
||||
|
||||
|
||||
@login_required
|
||||
|
|
Loading…
Reference in a new issue