Skip to content

Commit

Permalink
feat: new pickup system (#246)
Browse files Browse the repository at this point in the history
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced a new "Pickup System" feature, allowing users to create,
manage, and match pickup requests.
- Added a new dashboard layout to accommodate the "Pickup System"
feature.
- **Bug Fixes**
- Fixed import statements and class names to reflect recent changes in
the codebase.
- **Refactor**
- Refactored several classes and methods to improve code organization
and readability.
- **Chores**
- Performed Django migrations to update the database schema in line with
the new "Pickup System" feature.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
thejoeejoee committed Nov 16, 2023
2 parents c56433b + 04c55c3 commit 230359a
Show file tree
Hide file tree
Showing 71 changed files with 2,266 additions and 749 deletions.
1 change: 1 addition & 0 deletions fiesta/apps/accounts/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Meta(AbstractUser.Meta):

# a few dynamic related models
buddy_system_request_matches: models.QuerySet
pickup_system_request_matches: models.QuerySet
profile: UserProfile

@property
Expand Down
97 changes: 19 additions & 78 deletions fiesta/apps/buddy_system/forms.py
Original file line number Diff line number Diff line change
@@ -1,122 +1,63 @@
from __future__ import annotations

from django.core.exceptions import ValidationError
from django.forms import BooleanField, HiddenInput, fields_for_model
from django.forms import fields_for_model
from django.template.loader import render_to_string
from django.utils.functional import lazy
from django.utils.translation import gettext_lazy as _

from apps.accounts.models import User, UserProfile
from apps.accounts.models import UserProfile
from apps.buddy_system.models import BuddyRequest, BuddyRequestMatch
from apps.fiestaforms.fields.array import ChoicedArrayField
from apps.fiestaforms.forms import BaseModelForm
from apps.fiestaforms.widgets.models import ActiveLocalMembersFromSectionWidget, FacultyWidget, UserWidget
from apps.fiestarequests.forms.editor import BaseQuickMatchForm, BaseRequestEditorForm
from apps.fiestarequests.forms.request import BaseNewRequestForm

USER_PROFILE_CONTACT_FIELDS = fields_for_model(
UserProfile,
fields=("facebook", "instagram", "telegram", "whatsapp"),
)


class NewBuddyRequestForm(BaseModelForm):
class NewBuddyRequestForm(BaseNewRequestForm):
submit_text = _("Send request for buddy")

# TODO: group field somehow and add group headings
facebook, instagram, telegram, whatsapp = USER_PROFILE_CONTACT_FIELDS.values()

approving_request = BooleanField(required=True, label=_("I really want a buddy"))

class Meta:
class Meta(BaseNewRequestForm.Meta):
model = BuddyRequest
fields = (
"note",
"interests",
"responsible_section",
"issuer",
"issuer_faculty",
)
field_classes = {

fields = BaseNewRequestForm.Meta.fields + ("interests",)
field_classes = BaseNewRequestForm.Meta.field_classes | {
"interests": ChoicedArrayField,
}
widgets = {
"responsible_section": HiddenInput,
"issuer": HiddenInput,
"issuer_faculty": FacultyWidget,
}
labels = {
labels = BaseNewRequestForm.Meta.labels | {
"note": _("Tell us about yourself"),
"interests": _("What are you into?"),
"issuer_faculty": _("Your faculty"),
"approving_requests": _("I really want a buddy"),
}
help_texts = {
help_texts = BaseNewRequestForm.Meta.help_texts | {
"note": lazy(
lambda: render_to_string("buddy_system/parts/buddy_request_note_help.html"),
str,
)
}

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

if self.initial.get("issuer_faculty"):
self.fields["issuer_faculty"].disabled = True


# TODO: add save/load of contacts to/from user_profile


class BuddyRequestEditorForm(BaseModelForm):
submit_text = _("Save")

class BuddyRequestEditorForm(BaseRequestEditorForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.fields["issuer"].disabled = True

if self.instance.state != BuddyRequest.State.CREATED:
# self.fields["matched_by"].disabled = True
# self.fields["matched_at"].disabled = True
self.fields["note"].disabled = True
self.fields["interests"].disabled = True

class Meta:
class Meta(BaseRequestEditorForm.Meta):
model = BuddyRequest
fields = (
"issuer",
"state",
"note",
"interests",
# "matched_by",
# "matched_at",
)
field_classes = {
fields = BaseRequestEditorForm.Meta.fields + ("interests",)
field_classes = BaseRequestEditorForm.Meta.field_classes | {
"interests": ChoicedArrayField,
# "matched_at": DateTimeLocalField,
}
widgets = {
"issuer": UserWidget,
# "matched_by": ActiveLocalMembersFromSectionWidget,
}
widgets = BaseRequestEditorForm.Meta.widgets | {}


class QuickBuddyMatchForm(BaseModelForm):
submit_text = _("Match")
class QuickBuddyMatchForm(BaseQuickMatchForm):
instance: BuddyRequestMatch

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

class Meta:
class Meta(BaseQuickMatchForm.Meta):
model = BuddyRequestMatch
fields = ("matcher",)
widgets = {
"matcher": ActiveLocalMembersFromSectionWidget,
}

def clean_matcher(self):
matcher: User = self.cleaned_data["matcher"]

if not matcher.profile_or_none.faculty:
raise ValidationError(_("This user has not set their faculty. Please ask them to do so or do it yourself."))

return matcher
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.7 on 2023-11-16 15:45

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('buddy_system', '0026_alter_buddyrequest_created_and_more'),
]

operations = [
migrations.AlterField(
model_name='buddysystemconfiguration',
name='matching_policy',
field=models.CharField(choices=[('manual-by-editor', 'Manual by editors'), ('manual-by-member', 'Manual by members'), ('same-faculty', 'Manual by members with restriction to same faculty')], default='manual-by-editor', help_text='Manual by editors: Matching is done manually only by editors. <br />Manual by members: Matching is done manually directly by members. <br />Manual by members with restriction to same faculty: Matching is done manually by members themselves, but limited to the same faculty.', max_length=32),
),
migrations.AlterField(
model_name='buddysystemconfiguration',
name='rolling_limit',
field=models.PositiveSmallIntegerField(default=0, editable=False),
),
]
14 changes: 13 additions & 1 deletion fiesta/apps/buddy_system/models/configuration.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
from __future__ import annotations

from django.db import models
from django.utils.translation import gettext_lazy as _

from apps.fiestarequests.matching_policy import MatchingPoliciesRegister
from apps.fiestarequests.models import BaseRequestSystemConfiguration


class BuddySystemConfiguration(BaseRequestSystemConfiguration):
...
matching_policy = models.CharField(
default=MatchingPoliciesRegister.DEFAULT_POLICY.id,
choices=MatchingPoliciesRegister.CHOICES,
max_length=32,
help_text=MatchingPoliciesRegister.DESCRIPTION,
)

@property
def matching_policy_instance(self):
# TODO: pass configuration?
return MatchingPoliciesRegister.get_policy_by_id(self.matching_policy)

class Meta:
verbose_name = _("buddy system configuration")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</div>

<div class="Dashboard__tile__value">✅ Matched</div>
<div class="Dashboard__tile__desc">
<div class="Dashboard__tile__desc text-base-200">
It's a match!
<br>
You have been matched with {{ br.match.matcher.full_name }}.
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions fiesta/apps/buddy_system/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .views.editor import BuddyRequestEditorDetailView, BuddyRequestsEditorView, QuickBuddyMatchView
from .views.matches import MyBuddies
from .views.matching import IssuerPictureServeView, MatcherPictureServeView, MatchingRequestsView, TakeBuddyRequestView
from .views.request import BuddySystemEntrance, NewRequestView, SignUpBeforeEntranceView, WannaBuddyView
from .views.request import BuddySystemEntrance, NewBuddyRequestView, SignUpBeforeEntranceView, WannaBuddyView

urlpatterns = [
path("", BuddySystemIndexView.as_view(), name="index"),
Expand All @@ -18,7 +18,7 @@
SignUpBeforeEntranceView.as_view(),
name="sign-up-before-request",
),
path("new-request", NewRequestView.as_view(), name="new-request"),
path("new-request", NewBuddyRequestView.as_view(), name="new-request"),
path("requests", BuddyRequestsEditorView.as_view(), name="requests"),
path("my-buddies", MyBuddies.as_view(), name="my-buddies"),
path("matching-requests", MatchingRequestsView.as_view(), name="matching-requests"),
Expand Down
Loading

0 comments on commit 230359a

Please sign in to comment.