Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(buddy-system): matched requests #195

Merged
merged 14 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.4 on 2023-09-02 12:04

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('accounts', '0016_userprofile_facebook_userprofile_instagram_and_more'),
]

operations = [
migrations.AlterField(
model_name='userprofile',
name='instagram',
field=models.CharField(blank=True, validators=[django.core.validators.RegexValidator('^[\\w\\-_.]+$')], verbose_name='instagram username'),
),
]
2 changes: 1 addition & 1 deletion fiesta/apps/accounts/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
4 changes: 1 addition & 3 deletions fiesta/apps/accounts/templates/accounts/dashboard_block.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
{% compute_profile_fullness user as fullness %}
{% interpolate_to_list fullness "text-red-400" "text-orange-400" "text-blue-400" "text-lime-400" as color %}
<div class="flex justify-center items-center my-4">
{# TODO: compute completness #}
{# TODO: interpolate to color #}
<div class="radial-progress {{ color }}"
style="--value:{{ fullness|multiply:100 }};
--size:20rem;
--size: 18rem;
--thickness: 2rem">
<div class="text-white flex flex-col items-center">
<span class="text-4xl lg:text-7xl font-bold">{{ fullness|multiply:100|int }}%</span>
Expand Down
9 changes: 7 additions & 2 deletions fiesta/apps/buddy_system/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -15,3 +15,8 @@ class BuddySystemConfigurationAdmin(BaseChildConfigurationAdmin):
@admin.register(BuddyRequest)
class BuddyRequestAdmin(BaseRequestAdmin):
pass


@admin.register(BuddyRequestMatch)
class BuddyRequestMatchAdmin(BaseRequestMatchAdmin):
pass
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
42 changes: 17 additions & 25 deletions fiesta/apps/buddy_system/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -29,7 +28,7 @@ class NewBuddyRequestForm(BaseModelForm):
class Meta:
model = BuddyRequest
fields = (
"description",
"note",
"interests",
"responsible_section",
"issuer",
Expand All @@ -42,12 +41,12 @@ class Meta:
"issuer": HiddenInput,
}
labels = {
"description": _("Tell us about yourself"),
"note": _("Tell us about yourself"),
"interests": _("What are you into?"),
}
help_texts = {
"description": lazy(
lambda: render_to_string("buddy_system/parts/buddy_request_description_help.html"),
"note": lazy(
lambda: render_to_string("buddy_system/parts/buddy_request_note_help.html"),
str,
)
}
Expand All @@ -65,28 +64,28 @@ 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["description"].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:
model = BuddyRequest
fields = (
"issuer",
"state",
"description",
"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,
}


Expand All @@ -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,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.4 on 2023-09-02 12:04

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('buddy_system', '0019_alter_buddyrequest_options'),
]

operations = [
migrations.RenameField(
model_name='buddyrequest',
old_name='description',
new_name='issuer_note',
),
]
Original file line number Diff line number Diff line change
@@ -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,
},
),
]
3 changes: 2 additions & 1 deletion fiesta/apps/buddy_system/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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",
]
14 changes: 13 additions & 1 deletion fiesta/apps/buddy_system/models/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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}"
Loading
Loading