Skip to content

Commit

Permalink
feat(buddy-system): final touches
Browse files Browse the repository at this point in the history
  • Loading branch information
thejoeejoee committed Oct 1, 2023
1 parent 363f25e commit 8d3ed58
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% load i18n %}
{% load static %}
{% load utils %}
{% load user_profile %}
Expand Down Expand Up @@ -70,7 +71,13 @@ <h2 class="card-title flex flex-row justify-between">
{% endif %}
</div>
</div>
<div class="chat-bubble">{{ br.match.note }}</div>
<div class="chat-bubble">
{% if br.match.note %}
{{ br.match.note }}
{% else %}
{% translate "We have been successfully matched!" %}
{% endif %}
</div>
</div>

<div class="flex flex-row items-center space-x-4 md:space-x-8 my-4">
Expand Down Expand Up @@ -159,7 +166,7 @@ <h3 class="text-2xl">Connect with {{ connect_with.first_name }}</h3>
<div class="chat-bubble bg-info-content">
{% get_waiting_buddy_requests_placed_before br as waiting_total %}

<div class="text-xl">⌛ Waiting for match</div>
<div class="text-xl">{% translate "Waiting for match" %}</div>

{% if waiting_total %}
There is {{ waiting_total }} waiting request{{ waiting_total|pluralize:"s" }} before yours.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{% load i18n %}
{% if not record.match %}
<a class="btn btn-sm btn-outline btn-primary"
x-data="modal($el.href)"
x-bind="bind"
href="{% url "buddy_system:quick-match" record.pk %}">{% trans "Match" %}</a>
{% endif %}
<a class="btn btn-sm btn-outline btn-primary"
x-data="modal($el.href)"
x-bind="bind"
href="{% url "buddy_system:quick-match" record.pk %}">
{% if record.match %}
{% trans "Change buddy" %}
{% else %}
{% trans "Match" %}
{% endif %}
</a>
14 changes: 14 additions & 0 deletions fiesta/apps/buddy_system/views/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.contrib.messages.views import SuccessMessageMixin
from django.contrib.postgres.search import SearchVector
from django.db import transaction
from django.forms import TextInput
from django.urls import reverse_lazy
from django.utils.translation import gettext_lazy as _
Expand Down Expand Up @@ -171,9 +172,22 @@ class QuickBuddyMatchView(
success_url = reverse_lazy("buddy_system:requests")
success_message = _("Buddy request has been matched.")

def get_initial(self):
try:
return {
"matcher": self.get_object().match.matcher,
}
except BuddyRequestMatch.DoesNotExist:
return {}

@transaction.atomic
def form_valid(self, form):
br: BuddyRequest = self.get_object()

if br.match:
# could be already matched by someone else
br.match.delete()

match = BuddyRequestMatch(
request=br,
matcher=form.cleaned_data.get("matcher"),
Expand Down

0 comments on commit 8d3ed58

Please sign in to comment.