diff --git a/fiesta/apps/accounts/models/user.py b/fiesta/apps/accounts/models/user.py index b2c61d04..d617b21c 100644 --- a/fiesta/apps/accounts/models/user.py +++ b/fiesta/apps/accounts/models/user.py @@ -50,7 +50,7 @@ class Meta(AbstractUser.Meta): verbose_name_plural = _("users") # a few dynamic related models - buddy_system_matched_requests: models.QuerySet + buddy_system_request_matches: models.QuerySet profile: UserProfile diff --git a/fiesta/apps/buddy_system/admin.py b/fiesta/apps/buddy_system/admin.py index aee4903e..20f16846 100644 --- a/fiesta/apps/buddy_system/admin.py +++ b/fiesta/apps/buddy_system/admin.py @@ -2,9 +2,9 @@ from django.contrib import admin -from ..fiestarequests.admin import BaseRequestAdmin +from ..fiestarequests.admin import BaseRequestAdmin, BaseRequestMatchAdmin from ..plugins.admin import BaseChildConfigurationAdmin -from .models import BuddyRequest, BuddySystemConfiguration +from .models import BuddyRequest, BuddyRequestMatch, BuddySystemConfiguration @admin.register(BuddySystemConfiguration) @@ -15,3 +15,8 @@ class BuddySystemConfigurationAdmin(BaseChildConfigurationAdmin): @admin.register(BuddyRequest) class BuddyRequestAdmin(BaseRequestAdmin): pass + + +@admin.register(BuddyRequestMatch) +class BuddyRequestMatchAdmin(BaseRequestMatchAdmin): + pass diff --git a/fiesta/apps/buddy_system/forms.py b/fiesta/apps/buddy_system/forms.py index c0080dd1..445c407c 100644 --- a/fiesta/apps/buddy_system/forms.py +++ b/fiesta/apps/buddy_system/forms.py @@ -6,9 +6,8 @@ from django.utils.translation import gettext_lazy as _ from apps.accounts.models import UserProfile -from apps.buddy_system.models import BuddyRequest +from apps.buddy_system.models import BuddyRequest, BuddyRequestMatch from apps.fiestaforms.fields.array import ChoicedArrayField -from apps.fiestaforms.fields.datetime import DateTimeLocalField from apps.fiestaforms.forms import BaseModelForm from apps.fiestaforms.widgets.models import ActiveLocalMembersFromSectionWidget, UserWidget @@ -29,7 +28,7 @@ class NewBuddyRequestForm(BaseModelForm): class Meta: model = BuddyRequest fields = ( - "issuer_note", + "note", "interests", "responsible_section", "issuer", @@ -42,12 +41,12 @@ class Meta: "issuer": HiddenInput, } labels = { - "issuer_note": _("Tell us about yourself"), + "note": _("Tell us about yourself"), "interests": _("What are you into?"), } help_texts = { - "issuer_note": lazy( - lambda: render_to_string("buddy_system/parts/buddy_request_issuer_note_help.html"), + "note": lazy( + lambda: render_to_string("buddy_system/parts/buddy_request_note_help.html"), str, ) } @@ -65,9 +64,9 @@ def __init__(self, *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["issuer_note"].disabled = True + # self.fields["matched_by"].disabled = True + # self.fields["matched_at"].disabled = True + self.fields["note"].disabled = True self.fields["interests"].disabled = True class Meta: @@ -75,18 +74,18 @@ class Meta: fields = ( "issuer", "state", - "issuer_note", + "note", "interests", - "matched_by", - "matched_at", + # "matched_by", + # "matched_at", ) field_classes = { "interests": ChoicedArrayField, - "matched_at": DateTimeLocalField, + # "matched_at": DateTimeLocalField, } widgets = { "issuer": UserWidget, - "matched_by": ActiveLocalMembersFromSectionWidget, + # "matched_by": ActiveLocalMembersFromSectionWidget, } @@ -96,18 +95,11 @@ class QuickBuddyMatchForm(BaseModelForm): 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["issuer"].disabled = True class Meta: - model = BuddyRequest - fields = ( - "issuer", - "matched_by", - ) + model = BuddyRequestMatch + fields = ("matcher",) widgets = { - "issuer": UserWidget, - "matched_by": ActiveLocalMembersFromSectionWidget, + "matcher": ActiveLocalMembersFromSectionWidget, } diff --git a/fiesta/apps/buddy_system/migrations/0021_remove_buddyrequest_issuer_note_and_more.py b/fiesta/apps/buddy_system/migrations/0021_remove_buddyrequest_issuer_note_and_more.py new file mode 100644 index 00000000..e7ec4a4e --- /dev/null +++ b/fiesta/apps/buddy_system/migrations/0021_remove_buddyrequest_issuer_note_and_more.py @@ -0,0 +1,59 @@ +# Generated by Django 4.2.4 on 2023-09-24 19:17 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import django_extensions.db.fields +import uuid + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('buddy_system', '0020_rename_description_buddyrequest_issuer_note'), + ] + + operations = [ + migrations.RemoveField( + model_name='buddyrequest', + name='issuer_note', + ), + migrations.RemoveField( + model_name='buddyrequest', + name='matched_at', + ), + migrations.RemoveField( + model_name='buddyrequest', + name='matched_by', + ), + migrations.AddField( + model_name='buddyrequest', + name='note', + field=models.TextField(default='', verbose_name='text from issuer'), + preserve_default=False, + ), + migrations.AddField( + model_name='buddysystemconfiguration', + name='enable_note_from_matcher', + field=models.BooleanField(default=True, help_text='Allows matcher to reply with custom notes to the request issuer'), + ), + migrations.CreateModel( + name='BuddyRequestMatch', + fields=[ + ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('created', django_extensions.db.fields.CreationDateTimeField(auto_now_add=True, verbose_name='created')), + ('modified', django_extensions.db.fields.ModificationDateTimeField(auto_now=True, verbose_name='modified')), + ('note', models.TextField(blank=True, verbose_name='text from matcher')), + ('matcher', models.ForeignKey(on_delete=django.db.models.deletion.RESTRICT, related_name='buddy_system_request_matches', to=settings.AUTH_USER_MODEL, verbose_name='matched by')), + ('request', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='match', to='buddy_system.buddyrequest', verbose_name='request')), + ], + options={ + 'verbose_name': 'buddy request match', + 'verbose_name_plural': 'buddy request matches', + 'ordering': ('-created',), + 'get_latest_by': 'modified', + 'abstract': False, + }, + ), + ] diff --git a/fiesta/apps/buddy_system/models/__init__.py b/fiesta/apps/buddy_system/models/__init__.py index 6f575a1c..e05998e1 100644 --- a/fiesta/apps/buddy_system/models/__init__.py +++ b/fiesta/apps/buddy_system/models/__init__.py @@ -1,9 +1,10 @@ from __future__ import annotations from .configuration import BuddySystemConfiguration -from .request import BuddyRequest +from .request import BuddyRequest, BuddyRequestMatch __all__ = [ "BuddySystemConfiguration", "BuddyRequest", + "BuddyRequestMatch", ] diff --git a/fiesta/apps/buddy_system/models/request.py b/fiesta/apps/buddy_system/models/request.py index c76e97b0..014a9f4c 100644 --- a/fiesta/apps/buddy_system/models/request.py +++ b/fiesta/apps/buddy_system/models/request.py @@ -7,7 +7,10 @@ from apps.fiestarequests.models import base_request_model_factory from apps.utils.models.fields import ArrayFieldWithDisplayableChoices -BaseRequestForBuddySystem = base_request_model_factory(related_base="buddy_system") +BaseRequestForBuddySystem, BaseRequestMatchForBuddySystem = base_request_model_factory( + final_request_model_name="buddy_system.BuddyRequest", + related_base="buddy_system", +) class BuddyRequest(BaseRequestForBuddySystem): @@ -29,3 +32,12 @@ class Meta(BaseRequestForBuddySystem.Meta): def __str__(self): return f"Buddy Request {self.issuer}: {self.get_state_display()}" + + +class BuddyRequestMatch(BaseRequestMatchForBuddySystem): + class Meta(BaseRequestForBuddySystem.Meta): + verbose_name = _("buddy request match") + verbose_name_plural = _("buddy request matches") + + def __str__(self): + return f"Buddy Request Match {self.matcher}: {self.request}" diff --git a/fiesta/apps/buddy_system/templates/buddy_system/dashboard_block.html b/fiesta/apps/buddy_system/templates/buddy_system/dashboard_block.html index f6e53044..0bf19511 100644 --- a/fiesta/apps/buddy_system/templates/buddy_system/dashboard_block.html +++ b/fiesta/apps/buddy_system/templates/buddy_system/dashboard_block.html @@ -39,15 +39,15 @@