Skip to content

Commit

Permalink
Merge pull request #3 from parrotmac/ip/multi-groups-plus-more
Browse files Browse the repository at this point in the history
Major feature bump
  • Loading branch information
parrotmac committed Dec 17, 2023
2 parents 60daa0f + 513c995 commit 0a62ec6
Show file tree
Hide file tree
Showing 30 changed files with 723 additions and 103 deletions.
16 changes: 16 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '3.8'
services:
db:
image: postgres:16.1-alpine3.19
restart: always
environment:
POSTGRES_HOST_AUTH_METHOD: trust
# POSTGRES_USER: postgres
# POSTGRES_PASSWORD: postgres
# POSTGRES_DB: postgres
ports:
- "5900:5432"
redis:
image: redis:alpine3.17
ports:
- "6379:6379"
12 changes: 0 additions & 12 deletions docker-compose.yml

This file was deleted.

1 change: 1 addition & 0 deletions gary/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ def get_envvar_list(envvar_name, default=[], separator=",", normalize=True):

ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_USER_DISPLAY = "gifter.utils.user_display"

AUTHENTICATION_BACKENDS = [
"django.contrib.auth.backends.ModelBackend",
Expand Down
29 changes: 29 additions & 0 deletions gifter/migrations/0006_wishlist_groups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 4.1.2 on 2023-12-17 02:04

from django.db import migrations, models


def forwards_func(apps, schema_editor):
Wishlist = apps.get_model("gifter", "Wishlist")
for wishlist in Wishlist.objects.all():
wishlist.groups.add(wishlist.group)
wishlist.save()


class Migration(migrations.Migration):
dependencies = [
("auth", "0012_alter_user_first_name_max_length"),
("gifter", "0005_alter_claim_options_alter_groupinvitation_options_and_more"),
]

operations = [
migrations.AddField(
model_name="wishlist",
name="groups",
field=models.ManyToManyField(related_name="wishlists", to="auth.group"),
),
migrations.RunPython(
code=forwards_func,
reverse_code=migrations.RunPython.noop,
),
]
16 changes: 16 additions & 0 deletions gifter/migrations/0007_remove_wishlist_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 4.1.2 on 2023-12-17 02:29

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("gifter", "0006_wishlist_groups"),
]

operations = [
migrations.RemoveField(
model_name="wishlist",
name="group",
),
]
4 changes: 2 additions & 2 deletions gifter/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ def __str__(self):
class Wishlist(CommonBaseClass):
title = models.CharField(max_length=120, blank=False, null=False)
owner = models.ForeignKey(User, on_delete=models.CASCADE)
group = models.ForeignKey(Group, on_delete=models.CASCADE)
groups = models.ManyToManyField(Group, related_name="wishlists")

def __str__(self):
return f"Wishlist for {self.owner} on {self.group.name}"
return f"Wishlist for {self.owner} (in {self.groups.count()} groups)"


class Item(CommonBaseClass):
Expand Down
2 changes: 2 additions & 0 deletions gifter/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ a:link, a:visited {
.profile {
display: flex;
align-items: center;
justify-content: center;
}

.profile-photo {
max-height: 40px;
max-width: 40px;
border-radius: 100px;
margin-right: 0.5em;
}

.socialaccount_providers {
Expand Down
12 changes: 6 additions & 6 deletions gifter/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ def setUp(self) -> None:
Group.objects.create(name="The Bears")

def test_wishlist_creation(self):
Wishlist.objects.create(
wl1 = Wishlist.objects.create(
title="Mama's Christmas 2020",
owner=self.users["mama-bear"],
group=Group.objects.get(name="The Bears"),
)
Wishlist.objects.create(
wl1.groups.add(Group.objects.get(name="The Bears"))
wl2 = Wishlist.objects.create(
title="Papa's Christmas 2020",
owner=self.users["papa-bear"],
group=Group.objects.get(name="The Bears"),
)
Wishlist.objects.create(
wl2.groups.add(Group.objects.get(name="The Bears"))
wl3 = Wishlist.objects.create(
title="Baby's Christmas 2020",
owner=self.users["baby-bear"],
group=Group.objects.get(name="The Bears"),
)
wl3.groups.add(Group.objects.get(name="The Bears"))
self.assertEqual(Wishlist.objects.count(), 3)
self.assertEqual(
Wishlist.objects.filter(owner=self.users["mama-bear"]).count(), 1
Expand Down
32 changes: 30 additions & 2 deletions gifter/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
GroupDeleteView,
SendInviteFormView,
MyWishlistsListView,
ItemDeleteView,
ItemDeleteView, UpdateWishlistOptionsView, ClaimListView,
)

urlpatterns = [
Expand All @@ -41,6 +41,11 @@
path(
"groups/<str:group_pk>/wishlists/<str:pk>",
WishlistDetailView.as_view(),
name="wishlist_detail_with_group",
),
path(
"wishlists/<str:pk>",
WishlistDetailView.as_view(),
name="wishlist_detail",
),
path(
Expand All @@ -49,10 +54,15 @@
name="wishlist_update",
),
path(
"groups/<str:group_pk>/wishlists/<str:pk>/delete",
"wishlists/<str:pk>/delete",
WishlistDeleteView.as_view(),
name="wishlist_delete",
),
path(
"groups/<int:group_pk>/wishlists/<str:pk>/delete",
WishlistDeleteView.as_view(),
name="wishlist_delete_with_group",
),
path("wishlists", MyWishlistsListView.as_view(), name="my_wishlists"),
path(
"wishlists/<str:wishlist_pk>/items/create",
Expand All @@ -74,6 +84,16 @@
ClaimCreateView.as_view(),
name="claim_create",
),
path(
"wishlists/<str:wishlist_pk>/items/<str:item_pk>/claims",
ClaimListView.as_view(),
name="claim_list",
),
path(
"groups/<str:group_pk>/wishlists/<str:wishlist_pk>/items/<str:item_pk>/claims",
ClaimListView.as_view(),
name="claim_list_with_group",
),
path(
"wishlists/<str:wishlist_pk>/items/<str:item_pk>/claims/<str:pk>",
ClaimUpdateView.as_view(),
Expand All @@ -84,6 +104,14 @@
ClaimDeleteView.as_view(),
name="claim_delete",
),
path(
"wishlists/<str:pk>/add-to-group",
UpdateWishlistOptionsView.as_view(),
name="add_wishlist_to_group"),
path(
"wishlists/<str:pk>/remove-from-group",
UpdateWishlistOptionsView.as_view(),
name="remove_wishlist_from_group"),
path(
"invitations/incoming/<str:token>",
incoming_invitation,
Expand Down
7 changes: 7 additions & 0 deletions gifter/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@


def user_display(user):
if user.first_name or user.last_name:
return f"{user.first_name} {user.last_name}"
else:
return user.email
Loading

0 comments on commit 0a62ec6

Please sign in to comment.