Skip to content

Commit

Permalink
fix(buddy-system): my-buddies added to menu, fixed matched requests w…
Browse files Browse the repository at this point in the history
…indow
  • Loading branch information
thejoeejoee committed Sep 29, 2023
1 parent c8b6be8 commit 45b50a4
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 86 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ loadlegacydata: DA_CMD = loadlegacydata ## Loads all data from legacydb run fro
loadlegacydata: DCFLAGS = --profile migration
loadlegacydata: da

dumpdata: DA_CMD = dumpdata --exclude auth --exclude contenttypes --exclude sessions --exclude sites --exclude admin
dumpdata: DA_CMD = dumpdata --exclude auth --exclude contenttypes --exclude sessions --exclude sites --exclude admin --natural-foreign
dumpdata: da

fixture ?=
Expand Down
15 changes: 12 additions & 3 deletions fiesta/apps/buddy_system/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,22 @@ class BuddySystemConfig(BasePluginAppConfig):
membership_not_required_urls = ("new-request",)

def as_navigation_item(self, request: HttpRequest, bound_plugin: Plugin) -> NavigationItemSpec | None:
base = super().as_navigation_item(request, bound_plugin)
base = (
super()
.as_navigation_item(request, bound_plugin)
._replace(
children=[
NavigationItemSpec(title=_("My Buddies"), url=reverse("buddy_system:my-buddies")),
],
)
)

if not request.membership.is_privileged:
return base

return base._replace(
url="",
children=[
children=base.children
+ [
NavigationItemSpec(title=_("Requests"), url=reverse("buddy_system:requests")),
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
<div class="Dashboard__tile bg-gray-200">
<div class="Dashboard__tile__title">My Buddies</div>

{% get_matched_buddy_requests as matched_requests %}
{% if not matched_requests.exists %}
{% get_matched_buddy_requests as request_matches %}
{% if not request_matches.exists %}
<div class="Dashboard__tile__value">So empty here :(</div>
<div class="Dashboard__tile__actions text-right">
<a href="{% url "buddy_system:matching-requests" %}"
Expand All @@ -70,33 +70,35 @@
{% else %}
<div class="Dashboard__tile__value">
<div class="avatar-group -space-x-12 justify-center p-2">
{% for br in matched_requests|slice:":3" %}
{% get_user_picture br.issuer as buddy_picture %}
{% for rm in request_matches|slice:":3" %}
{% get_user_picture rm.request.issuer as buddy_picture %}

{% if buddy_picture %}
<div class="avatar hover:scale-105 transition-transform">
<a class="avatar hover:scale-105 transition-transform"
href="{% url "buddy_system:my-buddies" %}">
<div class="w-24">
<img src="{% url "buddy_system:serve-issuer-profile-picture" buddy_picture %}"
width="{{ buddy_picture.width }}"
height="{{ buddy_picture.height }}"
alt="{{ br.issuer }}"
title="{{ br.issuer }}" />
alt="{{ rm.request.issuer }}"
title="{{ rm.request.issuer }}" />
</div>
</div>
</a>
{% else %}
<div class="w-24 avatar hover:scale-105 transition-transform aspect-square text-white text-3xl flex flex-row justify-center items-center group"
style="background-color: {{ br.issuer.username|get_color_by_text }}">
<a class="w-24 avatar hover:scale-105 transition-transform aspect-square text-white text-3xl flex flex-row justify-center items-center group"
style="background-color: {{ rm.request.issuer.username|get_color_by_text }}"
href="{% url "buddy_system:my-buddies" %}">
<span class="-translate-x-3 group-last:translate-x-0 uppercase">
{{ br.issuer.first_name|first }}{{ br.issuer.last_name|first }}
{{ rm.request.issuer.first_name|first }}{{ rm.request.issuer.last_name|first }}
</span>
</div>
</a>
{% endif %}
{% endfor %}
{% if matched_requests|length > 3 %}
{% if request_matches|length > 3 %}
<div class="avatar placeholder">
<a class="w-24 bg-neutral-focus text-neutral-content text-3xl flex justify-center items-center"
href="{% url "buddy_system:my-buddies" %}">
<span>+{{ matched_requests|length|add:"-3" }}</span>
<span>+{{ request_matches|length|add:"-3" }}</span>
</a>
</div>
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ <h2 class="card-title flex flex-row justify-between">
</div>
<div class="chat chat-end">
<div class="chat-header">
{{ br.matched_by.get_full_name }}
{% if br.matched_at %}
{% if br.match.created %}
<time class="text-xs opacity-50"
title="{{ br.matched_at|date:"SHORT_DATETIME_FORMAT" }}">
{{ br.matched_at|date:"SHORT_DATETIME_FORMAT" }}
{{ br.match.created|date:"SHORT_DATETIME_FORMAT" }}
</time>
{% endif %}
{{ br.match.matcher.get_full_name }}
</div>
<div class="chat-image avatar">
<div class="w-10 rounded-full">
{% get_user_picture br.matched_by as matcher_picture %}
{% get_user_picture br.match.matcher as matcher_picture %}

{% if matcher_picture %}
<img src="{% url "buddy_system:serve-matcher-profile-picture" matcher_picture %}"
Expand All @@ -67,20 +67,20 @@ <h2 class="card-title flex flex-row justify-between">
{% endif %}
</div>
</div>
<div class="chat-bubble">response from {{ br.matched_by.first_name }}</div>
<div class="chat-bubble">{{ br.match.note }}</div>
</div>

<div class="flex flex-row items-center space-x-4 md:space-x-8 my-4">
<hr class="flex-grow bg-base-300 h-1 mt-0.5">
<h3 class="text-2xl">Connect with {{ br.matched_by.first_name }}</h3>
<h3 class="text-2xl">Connect with {{ br.match.matcher.first_name }}</h3>
<hr class="flex-grow bg-base-300 h-1 mt-0.5">
</div>
<div class="btn-group justify-center">
{% if br.matched_by.profile.facebook %}
<a href="{{ br.matched_by.profile.facebook }}"
<div class="flex flex-row gap-x-4 items-center justify-center">
{% if br.match.matcher.profile.facebook %}
<a href="{{ br.match.matcher.profile.facebook }}"
rel="nofollow,noreferer,noopener"
target="_blank"
class="uppercase text-white bg-[#3b5998] hover:bg-[#3b5998]/90 focus:ring-4 focus:ring-[#3b5998]/50 font-medium rounded-lg text-sm px-4 py-2.5 text-center inline-flex items-center gap-x-2 dark:focus:ring-[#3b5998]/55">
class="btn uppercase text-white bg-[#3b5998] hover:bg-[#3b5998]/90 focus:ring-4 focus:ring-[#3b5998]/50 inline-flex items-center gap-x-2 dark:focus:ring-[#3b5998]/55">
<svg xmlns="http://www.w3.org/2000/svg"
x="0px"
y="0px"
Expand All @@ -90,7 +90,17 @@ <h3 class="text-2xl">Connect with {{ br.matched_by.first_name }}</h3>
<path d="M24,4H6C4.895,4,4,4.895,4,6v18c0,1.105,0.895,2,2,2h10v-9h-3v-3h3v-1.611C16,9.339,17.486,8,20.021,8 c1.214,0,1.856,0.09,2.16,0.131V11h-1.729C19.376,11,19,11.568,19,12.718V14h3.154l-0.428,3H19v9h5c1.105,0,2-0.895,2-2V6 C26,4.895,25.104,4,24,4z">
</path>
</svg>
{{ br.matched_by }}
{{ br.match.matcher }}
</a>
{% endif %}
{% if br.match.matcher.email %}
<a href="mailto:{{ br.match.matcher.email }}"
rel="nofollow,noreferer,noopener"
target="_blank"
class="btn btn-primary inline-flex items-center gap-x-2">
<span class="text-xl">✉️</span>

{{ br.match.matcher.email }}
</a>
{% endif %}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,13 @@
x-ref="dialog">
<form action="{% url "buddy_system:take-buddy-request" br.pk %}"
method="POST"
hx-boost="true">
hx-boost="true"
class="flex flex-col space-y-4"
x-data="{ note: '', noteEnabled: $el.dataset.enableNoteFromMatcher === 'true' }"
data-enable-note-from-matcher="{{ configuration.enable_note_from_matcher|lower }}">
{% csrf_token %}
<div class="flex flex-row justify-between">
<h3 class="text-2xl">{% blocktrans %}Buddy Request Confirmation{% endblocktrans %}</h3>
<h3 class="text-3xl">{% blocktrans %}Buddy Request Confirmation{% endblocktrans %}</h3>
<button @click="$refs.dialog.close()"
class="transition-transform hover:scale-95"
type="button">
Expand All @@ -97,15 +100,36 @@ <h3 class="text-2xl">{% blocktrans %}Buddy Request Confirmation{% endblocktrans
</button>
</div>

<p class="my-8">
<p class="text-md">
{% blocktrans %}Are you sure you want to confirm the buddy request,
acknowledging that you will be responsible for being buddy?{% endblocktrans %}
</p>

{% if configuration.enable_note_from_matcher %}
<label for="id_for_note">
<span class="text-xl">{% translate 'Message for your buddy' %}</span>
<textarea name="note"
id="id_for_note"
cols="15"
rows="10"
class="Forms__textarea"
x-model="note"
placeholder="{% translate "Hi! I am John and I will be your buddy! The best for communication for me is Telegram, but I am basically on all the social platforms. Looking forward to see your and grab a drink together!" %}"></textarea>
</label>

<h4 class="text-lg">{% translate 'What to include in message?' %}</h4>
<ul class="list-disc text-sm">
<li>{% translate 'Through which platform you will contact him/her' %}</li>
<li>{% translate "That you're looking forward to see her/him" %}</li>
<li>{% translate "Kind words to support in their international mobility" %}</li>
</ul>
{% endif %}

<div class="modal-actions flex flex-row justify-end">
<button class="btn btn-lg btn-success" type="submit">{% trans "Take Buddy" %}</button>
<button class="btn btn-lg btn-success"
type="submit"
:disabled="noteEnabled && !note">{% trans "Take Buddy" %}</button>
</div>

</form>
</dialog>

Expand Down
30 changes: 15 additions & 15 deletions fiesta/apps/buddy_system/templates/buddy_system/my_buddies.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,42 @@

{% block main %}
<div class="md:columns-2 space-y-4">
{% for br in object_list.all %}
<div class="card card-side bg-gray-100 group">
{% for match in object_list.all %}
<div class="card card-side bg-gray-100 group break-inside-avoid-column">
<div class="card-body w-3/4 grow-1">
<div class="card-title flex flex-row justify-between">
{{ br.issuer.full_name_official }}
{{ match.request.issuer.full_name_official }}

<span class="text-gray-600 text-xs">{{ br.matched_at|date }}</span>
<span class="text-gray-600 text-xs">{{ match.created|date }}</span>
</div>


<div class="prose prose-sm">
{# <p /> are added by filter #}
{{ br.note|censor_description|linebreaks }}
{{ match.request.note|censor_description|linebreaks }}
</div>

<div>
{% for interest in br.get_interests_display %}
{% for interest in match.request.get_interests_display %}
<span class="badge badge-outline badge-sm mr-1 mb-1">{{ interest }}</span>
{% endfor %}
</div>

</div>
{% if br.issuer.profile.picture %}
{% if match.request.issuer.profile.picture %}
<figure class="flex flex-col !items-start space-y-4 pb-4 max-w-[33%]">
<img src="{% url "buddy_system:serve-issuer-profile-picture" br.issuer.profile.picture %}"
width="{{ br.issuer.profile.picture.width }}"
height="{{ br.issuer.profile.picture.height }}"
<img src="{% url "buddy_system:serve-issuer-profile-picture" match.request.issuer.profile.picture %}"
width="{{ match.request.issuer.profile.picture.width }}"
height="{{ match.request.issuer.profile.picture.height }}"
alt=""
class="rounded-bl-xl">

<div class="flex flex-col justify-start items-center space-y-2">
{% if br.issuer.profile_or_none.facebook %}
{% if match.request.issuer.profile_or_none.facebook %}
<a type="button"
class="inline-block rounded px-6 py-2.5 text-xs font-medium leading-normal text-white transition duration-150 ease-in-out hover:shadow focus:shadow-lg focus:outline-none focus:ring-0 active:shadow-lg"
style="background-color: #1877f2"
href="{{ br.issuer.profile_or_none.facebook }}"
href="{{ match.request.issuer.profile_or_none.facebook }}"
rel="nofollow,noreferer">
<svg xmlns="http://www.w3.org/2000/svg"
class="h-4 w-4"
Expand All @@ -58,11 +58,11 @@
</svg>
</a>
{% endif %}
{% if br.issuer.profile_or_none.instagram %}
{% if match.request.issuer.profile_or_none.instagram %}
<a type="button"
class="inline-block rounded px-6 py-2.5 text-xs font-medium leading-normal text-white transition duration-150 ease-in-out hover:shadow focus:shadow-lg focus:outline-none focus:ring-0 active:shadow-lg"
style="background-color: #c13584"
href="{{ br.issuer.profile_or_none.instagram }}">
href="{{ match.request.issuer.profile_or_none.instagram }}">
<svg xmlns="http://www.w3.org/2000/svg"
class="h-4 w-4"
fill="currentColor"
Expand All @@ -75,7 +75,7 @@

<a type="button"
class="bg-gray-500 inline-block rounded px-6 py-1.5 font-medium leading-normal text-white transition duration-150 ease-in-out hover:shadow focus:shadow-lg focus:outline-none focus:ring-0 active:shadow-lg"
href="mailto:{{ br.issuer.email }}">@</a>
href="mailto:{{ match.request.issuer.email }}">@</a>
{% endif %}
</div>
</figure>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% load i18n %}
{% if not record.matched_by %}
{% if not record.match %}
<a class="btn btn-sm btn-outline btn-primary"
x-data="modal($el.href)"
x-bind="bind"
Expand Down
9 changes: 3 additions & 6 deletions fiesta/apps/buddy_system/templatetags/buddy_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from apps.plugins.middleware.plugin import HttpRequest
from apps.plugins.models import Plugin
from apps.plugins.utils import all_plugins_mapped_to_class
from apps.utils.models.query import get_single_object_or_none

register = template.Library()

Expand Down Expand Up @@ -38,11 +37,9 @@ def censor_description(description: str) -> str:
def get_current_buddy_request_of_user(context):
request: HttpRequest = context["request"]

return get_single_object_or_none(
request.membership.user.buddy_system_issued_requests.filter(
responsible_section=request.membership.section,
)
) # TODO: could be more then one?
return request.membership.user.buddy_system_issued_requests.filter(
responsible_section=request.membership.section,
).latest("created")


@register.simple_tag(takes_context=True)
Expand Down
Loading

0 comments on commit 45b50a4

Please sign in to comment.