Skip to content

Commit

Permalink
feat(buddy-system): international index tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
thejoeejoee committed Aug 27, 2023
1 parent 2853191 commit cf35f0d
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 37 deletions.
2 changes: 1 addition & 1 deletion fiesta/apps/accounts/models/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class Gender(TextChoices):
)
instagram = models.CharField(
verbose_name=_("instagram username"),
validators=[RegexValidator(r"^[\w_-.]+$")],
validators=[RegexValidator(r"^[\w\-_.]+$")],
blank=True,
)
telegram = models.CharField(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,35 @@
</div>
{% elif br.state == br.State.MATCHED %}
{% get_user_picture br.matched_by as buddy_picture %}
<div class="stat-figure text-secondary flex flex-col md:flex-row justify-center items-center md:space-x-8 space-y-4 md:space-y-0">
<a href="{% url "buddy_system:index" %}" class="btn btn-lg btn-white">{% trans "find out about your buddy" %}</a>

{% if buddy_picture %}
<div class="stat-figure text-secondary">
{% if buddy_picture %}
<div class="avatar">
<div class="w-16 rounded-full">
<img src="{% url "buddy_system:serve-issuer-profile-picture" buddy_picture %}"
<div class="w-24 rounded-full">
<img src="{% url "buddy_system:serve-matcher-profile-picture" buddy_picture %}"
width="{{ buddy_picture.width }}"
height="{{ buddy_picture.height }}"
alt="Matched buddy picture" />
</div>
</div>
</div>
{% endif %}
{% endif %}
</div>

<div class="Dashboard__tile__value">✅ Matched</div>
<div class="Dashboard__tile__desc">It's a match!</div>
<div class="Dashboard__tile__desc">
It's a match!
<br>
You have been matched with {{ br.matched_by }}.
</div>
{% endif %}
{% else %}
{% get_waiting_requests_to_match as waiting_brs %}
<div class="Dashboard__tile__value">
{% with waiting_brs.count as count %}<span>{{ count }}</span> waiting request{{ count|pluralize:"s" }}{% endwith %}
{% with waiting_brs.count as count %}
<span>{{ count }}</span> waiting request
{{ count|pluralize:"s" }}
{% endwith %}
</div>
<div class="Dashboard__tile__actions text-right">
<a href="{% url "buddy_system:matching-requests" %}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% extends "fiesta/base.html" %}
{% load user_profile %}

{% load i18n %}
{% load breadcrumbs %}
Expand All @@ -9,24 +10,98 @@
{% endblock upper_head %}

{% block main %}
<div class="prose prose-lg">
<h1>My requests</h1>
{# TODO: ugly #}
<table>
{% for request in requests %}
<tr>
<td>{{ request }}</td>
<td>{{ request.responsible_section }}</td>
<td>{{ request.created }}</td>
<td>{{ request.state }}</td>
</tr>
{% empty %}
<tr>
<td>
<a href="{% url "buddy_system:new-request" %}">new buddy request</a>
</td>
</tr>
{% endfor %}
</table>
</div>

{% for br in requests %}
<div class="card bg-base-200 shadow mb-4 mt-2">
<div class="card-body">
<h2 class="card-title flex flex-row justify-between">
Your Request from {{ br.created|date }}

<span class="badge badge-lg">{{ br.get_state_display }}</span>
</h2>

{% if br.state == RequestState.MATCHED %}
<div class="chat chat-start">
<div class="chat-header">
{{ br.issuer.get_full_name }}
<time class="text-xs opacity-50"
title="{{ br.created|date:"SHORT_DATETIME_FORMAT" }}">
{{ br.created|date:"SHORT_DATETIME_FORMAT" }}
</time>
</div>
<div class="chat-image avatar">
<div class="w-10 rounded-full">
{% get_user_picture br.issuer as issuer_picture %}

{% if issuer_picture %}
<img src="{% url "buddy_system:serve-issuer-profile-picture" issuer_picture %}"
width="{{ issuer_picture.width }}"
height="{{ issuer_picture.height }}"
alt="Issuer picture" />
{# TODO: avatar for empty #}
{% endif %}
</div>
</div>
<div class="chat-bubble">{{ br.description }}</div>
</div>
<div class="chat chat-end">
<div class="chat-header">
{{ br.matched_by.get_full_name }}
{% if br.matched_at %}
<time class="text-xs opacity-50"
title="{{ br.matched_at|date:"SHORT_DATETIME_FORMAT" }}">
{{ br.matched_at|date:"SHORT_DATETIME_FORMAT" }}
</time>
{% endif %}
</div>
<div class="chat-image avatar">
<div class="w-10 rounded-full">
{% get_user_picture br.matched_by as matcher_picture %}

{% if matcher_picture %}
<img src="{% url "buddy_system:serve-matcher-profile-picture" matcher_picture %}"
width="{{ matcher_picture.width }}"
height="{{ matcher_picture.height }}"
alt="Matcher picture" />
{# TODO: avatar for empty #}
{% endif %}
</div>
</div>
<div class="chat-bubble">response from {{ br.matched_by.first_name }}</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>
<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 }}"
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">
<svg xmlns="http://www.w3.org/2000/svg"
x="0px"
y="0px"
viewBox="0 0 30 30"
class="text-white w-6 h-6"
fill="currentColor">
<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 }}
</a>
{% endif %}
</div>
{% endif %}
</div>
</div>
{% empty %}
<tr>
<td>
<a href="{% url "buddy_system:new-request" %}">new buddy request</a>
</td>
</tr>
{% endfor %}
{% endblock %}
5 changes: 3 additions & 2 deletions fiesta/apps/buddy_system/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .views import BuddySystemIndexView
from .views.editor import BuddyRequestEditorDetailView, BuddyRequestsEditorView, QuickBuddyMatchView
from .views.matches import MyBuddies
from .views.matching import MatchingRequestsView, ProfilePictureServeView, TakeBuddyRequestView
from .views.matching import IssuerPictureServeView, MatcherPictureServeView, MatchingRequestsView, TakeBuddyRequestView
from .views.request import BuddySystemEntrance, NewRequestView, SignUpBeforeEntranceView, WannaBuddyView

urlpatterns = [
Expand All @@ -30,5 +30,6 @@
path("detail/<uuid:pk>", BuddyRequestEditorDetailView.as_view(), name="editor-detail"),
path("quick-match/<uuid:pk>", QuickBuddyMatchView.as_view(), name="quick-match"),
# serve profile picture with proxy view
ProfilePictureServeView.as_url(user_profile_picture_storage, url_name="serve-issuer-profile-picture"),
IssuerPictureServeView.as_url(user_profile_picture_storage, url_name="serve-issuer-profile-picture"),
MatcherPictureServeView.as_url(user_profile_picture_storage, url_name="serve-matcher-profile-picture"),
]
6 changes: 5 additions & 1 deletion fiesta/apps/buddy_system/views/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.views.generic import TemplateView

from apps.buddy_system.models import BuddySystemConfiguration
from apps.buddy_system.models import BuddyRequest, BuddySystemConfiguration
from apps.plugins.views import PluginConfigurationViewMixin
from apps.sections.middleware.user_membership import HttpRequest
from apps.sections.models import SectionMembership
Expand All @@ -16,6 +16,10 @@ class BuddySystemIndexView(
):
request: HttpRequest

extra_context = {
"RequestState": BuddyRequest.State,
}

def get_context_data(self, **kwargs):
data = super().get_context_data(**kwargs)

Expand Down
34 changes: 30 additions & 4 deletions fiesta/apps/buddy_system/views/matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,45 @@ def post(self, request, pk: uuid.UUID):
return HttpResponseClientRedirect("/")


class ProfilePictureServeView(
class IssuerPictureServeView(
PluginConfigurationViewMixin[BuddySystemConfiguration],
NamespacedFilesServeView,
):
def has_permission(self, request: HttpRequest, name: str) -> bool:
# is the file in requests, for whose is the related section responsible?
related_requests = request.membership.section.buddy_system_requests.filter(
Q(issuer__profile__picture=name) | Q(matched_by__profile__picture=name)
issuer__profile__picture=name,
)

# does have the section enabled picture displaying?
return (related_requests.exists() and self.configuration and self.configuration.display_issuer_picture) or (
related_requests.filter(
Q(matched_by=request.user) | Q(issuer=request.user), state=BuddyRequest.State.MATCHED
).exists()
state=BuddyRequest.State.MATCHED,
)
.filter(
Q(matched_by=request.user) | Q(issuer=request.user),
)
.exists()
)


class MatcherPictureServeView(
PluginConfigurationViewMixin[BuddySystemConfiguration],
NamespacedFilesServeView,
):
def has_permission(self, request: HttpRequest, name: str) -> bool:
# is the file in requests, for whose is the related section responsible?
related_requests = request.membership.section.buddy_system_requests.filter(
matched_by__profile__picture=name,
)

# does have the section enabled picture displaying?
return (
related_requests.filter(
state=BuddyRequest.State.MATCHED,
)
.filter(
Q(matched_by=request.user) | Q(issuer=request.user),
)
.exists()
)
2 changes: 1 addition & 1 deletion fiesta/apps/files/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def has_permission(self, request: HttpRequest, name: str) -> bool:
@classmethod
def as_url(cls, storage: NamespacedFilesStorage, url_name: str = None) -> RoutePattern:
return path(
f"serve/{storage.namespace}/<path:name>",
f"serve/{storage.namespace}/{url_name or 'default'}/<path:name>",
cls.as_view(
storage=storage,
),
Expand Down

0 comments on commit cf35f0d

Please sign in to comment.