-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!-- 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
Showing
71 changed files
with
2,266 additions
and
749 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
23 changes: 23 additions & 0 deletions
23
...s/buddy_system/migrations/0027_alter_buddysystemconfiguration_matching_policy_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
fiesta/apps/buddy_system/templates/buddy_system/editor/detail.html
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
fiesta/apps/buddy_system/templates/buddy_system/editor/detail_form.html
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
fiesta/apps/buddy_system/templates/buddy_system/editor/quick_match.html
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
fiesta/apps/buddy_system/templates/buddy_system/editor/quick_match_form.html
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
fiesta/apps/buddy_system/templates/buddy_system/new_buddy_request.html
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
fiesta/apps/buddy_system/templates/buddy_system/parts/new_buddy_request_form.html
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.