Compare commits
3 commits
929d61e12c
...
9724b7f32e
Author | SHA1 | Date | |
---|---|---|---|
|
9724b7f32e | ||
|
821ad78dd6 | ||
|
114a83e304 |
6 changed files with 40 additions and 7 deletions
|
@ -14,6 +14,6 @@ class CreateOfferForm(forms.ModelForm):
|
||||||
class RegistrationForm(UserCreationForm):
|
class RegistrationForm(UserCreationForm):
|
||||||
class Meta(UserCreationForm.Meta):
|
class Meta(UserCreationForm.Meta):
|
||||||
model = PflaenzliUser
|
model = PflaenzliUser
|
||||||
fields = UserCreationForm.Meta.fields + ('zipcode',)
|
fields = UserCreationForm.Meta.fields + ('email', 'zipcode',)
|
||||||
|
|
||||||
captcha = FrcCaptchaField()
|
captcha = FrcCaptchaField()
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
# Generated by Django 4.1.7 on 2023-04-09 10:31
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("pflaenzli", "0001_initial"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="pflaenzliuser",
|
||||||
|
name="email",
|
||||||
|
field=models.EmailField(max_length=254),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="pflaenzliuser",
|
||||||
|
name="zipcode",
|
||||||
|
field=models.PositiveIntegerField(blank=True, null=True),
|
||||||
|
),
|
||||||
|
]
|
|
@ -6,7 +6,8 @@ from django.core.files.storage import default_storage
|
||||||
|
|
||||||
|
|
||||||
class PflaenzliUser(AbstractUser):
|
class PflaenzliUser(AbstractUser):
|
||||||
zipcode = models.PositiveIntegerField(blank=True)
|
email = models.EmailField(max_length=254)
|
||||||
|
zipcode = models.PositiveIntegerField(blank=True, null=True)
|
||||||
|
|
||||||
|
|
||||||
class Offer(models.Model):
|
class Offer(models.Model):
|
||||||
|
|
|
@ -27,9 +27,9 @@
|
||||||
<p class="mr-3">
|
<p class="mr-3">
|
||||||
<i class="fas fa-map-marker-alt"></i> {{ offer.zipcode }}
|
<i class="fas fa-map-marker-alt"></i> {{ offer.zipcode }}
|
||||||
</p>
|
</p>
|
||||||
{% if distance > 0 %}
|
{% if dist %}
|
||||||
<p class="pr-3">
|
<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>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
@ -76,11 +76,11 @@
|
||||||
<p>{{ offer.user.username }} would like some of the following in return:</p>
|
<p>{{ offer.user.username }} would like some of the following in return:</p>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
{% if wishes %}
|
{% if wishes %}
|
||||||
<div class="alert alert-warning" role="alert">There are currently no wishes!</div>
|
|
||||||
{% else %}
|
|
||||||
<ul class="list-group">
|
<ul class="list-group">
|
||||||
{% for wish in wishes %}<li class="list-group-item">{{ wish.title }}</li>{% endfor %}
|
{% for wish in wishes %}<li class="list-group-item">{{ wish.title }}</li>{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
{% else %}
|
||||||
|
<div class="alert alert-warning" role="alert">There are currently no wishes!</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<a class="btn btn-pfl mb-3" href="{% url 'offer_trade' offer.id %}">Offer trade</a>
|
<a class="btn btn-pfl mb-3" href="{% url 'offer_trade' offer.id %}">Offer trade</a>
|
||||||
|
|
|
@ -8,6 +8,9 @@ df = read_pickle(os.path.join(path, 'plz.pkl'))
|
||||||
|
|
||||||
|
|
||||||
def calculate_distance(zip_1, zip_2):
|
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_1_coords = tuple(df[df.index == zip_1].values)
|
||||||
zip_2_coords = tuple(df[df.index == zip_2].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 .models import PflaenzliUser, Offer, Wish
|
||||||
from .mail import send_offer_email
|
from .mail import send_offer_email
|
||||||
from .upload import generate_unique_filename
|
from .upload import generate_unique_filename
|
||||||
|
from .utils.distance import calculate_distance
|
||||||
|
|
||||||
|
|
||||||
def list_offers(request, filters=None):
|
def list_offers(request, filters=None):
|
||||||
|
@ -38,8 +39,13 @@ def create_offer(request):
|
||||||
@ login_required
|
@ login_required
|
||||||
def offer_detail(request, offer_id):
|
def offer_detail(request, offer_id):
|
||||||
offer = get_object_or_404(Offer, id=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": ["Monstera", "Tradescantia"]})
|
return render(request, "offer/detail.html", {"offer": offer, "wishes": wishes, "dist": dist})
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
|
Loading…
Reference in a new issue