Merge pull request 'Fix layout and mail language' (#14) from dev into main
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/promote/production Build is passing

Reviewed-on: #14
This commit is contained in:
Jannis Portmann 2023-09-10 11:59:34 +02:00
commit 2f8feb5e0f
2 changed files with 12 additions and 7 deletions

View file

@ -1,14 +1,15 @@
from django.core.mail import EmailMessage, EmailMultiAlternatives
from django.urls import reverse
from django.template.loader import render_to_string
from django.utils.translation import gettext_lazy as _
from django.utils.translation import activate, get_language, gettext_lazy as _
def send_offer_email(request, offer, sender_user, recipient_user):
activate(recipient_user.language_code)
html_content = render_to_string('user/trade/offer_email.html',
{'request': request, 'offer': offer, 'sender_user': sender_user, 'recipient_user': recipient_user})
plain_text = get_offer_text(request, offer, sender_user, recipient_user)
message = EmailMultiAlternatives(
f'{sender_user.username} {_("wants to trade")}',
plain_text,
@ -21,6 +22,8 @@ def send_offer_email(request, offer, sender_user, recipient_user):
message.send()
activate(sender_user.language_code)
def get_offer_text(request, offer, sender_user, recipient_user):
return f"{_('Hello')} {recipient_user.username},\n\n{sender_user.username} {_('is interested in')} {offer.title}!\n\n{_('Checkout their offers')}: {request.scheme}://{request.get_host()}{reverse('user_detail', args=[sender_user.id])}\n\n{_('Contact')} {sender_user.username}, {_('by replying to this mail')}."

View file

@ -20,22 +20,24 @@
<h2 class="h3">{% trans "Offers" %}</h2>
</div>
{% if offers %}
<div class="card-deck d-flex justify-content-around justify-content-sm-around justify-content-md-between flex-wrap">
<div class="row row-cols-1 row-cols-md-2 row-cols-xl-3 mt-3 mb-3 row-gap-5">
{% for offer in offers %}
<div class="col">
<div class="card h-100 p-0 flex-column justify-content-between">
<div class="card h-100 p-0">
<a href="{% url 'offer_detail' offer.id %}">
{% if offer.image %}
<img class="card-img-top offer-img" src="{{ offer.image.url }}"/>
<img class="card-img-top offer-img" src="{{ offer.image.url }}" />
{% else %}
<img class="card-img-top offer-img" src="{% static 'placeholder.jpg' %}" />
{% endif %}
<div class="card-body">
<h5 class="h5">{{ offer.title }}</h5>
<h5 class="h5">
{{ offer.title }}<span class="ms-2 badge pfl-{{ offer.category|lower }}">{{ offer.get_category_display }}</span>
</h5>
</div>
</a>
<div class="card-footer d-flex justify-content-between">
<a href="#">
<a href="{% url 'user_detail' offer.user.id %}">
<i class="fas fa-user mt-3"></i> {{ offer.user.username }}
</a>
<p class="zip">