Skip to content

Commit

Permalink
Fix minor bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasdeluna committed May 24, 2024
1 parent 3cf0058 commit 2fa3ee6
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 209 deletions.
17 changes: 2 additions & 15 deletions lego/apps/lending/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class LendingInstanceManager(BasisModelManager):
def create(self, *args, **kwargs):
from lego.apps.lending.notifications import LendingInstanceNotification
from lego.apps.lending.notifications import LendingInstanceCreateNotification
from lego.apps.users.models import Membership, User

Check warning on line 7 in lego/apps/lending/managers.py

View check run for this annotation

Codecov / codecov/patch

lego/apps/lending/managers.py#L6-L7

Added lines #L6 - L7 were not covered by tests

lending_instance = super().create(*args, **kwargs)
Expand All @@ -19,26 +19,13 @@ def create(self, *args, **kwargs):
).values_list("user", flat=True)
for user_id in users_to_be_notified:
user = User.objects.get(pk=user_id)
notification = LendingInstanceNotification(
notification = LendingInstanceCreateNotification(

Check warning on line 22 in lego/apps/lending/managers.py

View check run for this annotation

Codecov / codecov/patch

lego/apps/lending/managers.py#L20-L22

Added lines #L20 - L22 were not covered by tests
lending_instance=lending_instance,
user=user,
)
notification.notify()

Check warning on line 26 in lego/apps/lending/managers.py

View check run for this annotation

Codecov / codecov/patch

lego/apps/lending/managers.py#L26

Added line #L26 was not covered by tests

return lending_instance

Check warning on line 28 in lego/apps/lending/managers.py

View check run for this annotation

Codecov / codecov/patch

lego/apps/lending/managers.py#L28

Added line #L28 was not covered by tests

# TODO: We probably need another template for accepting instances
def update(self, *args, **kwargs):
from lego.apps.lending.notifications import LendingInstanceNotification

lending_instance = super().update(*args, **kwargs)
notification = LendingInstanceNotification(
lending_instance=lending_instance,
user=lending_instance.created_by,
)
notification.notify()

return lending_instance

def get_queryset(self):
return super().get_queryset().select_related("created_by")
17 changes: 14 additions & 3 deletions lego/apps/lending/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.0.10 on 2024-04-16 18:32
# Generated by Django 4.0.10 on 2024-05-24 11:03

import datetime

Expand All @@ -16,7 +16,7 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
("users", "0041_user_linkedin_id_alter_user_github_username"),
("users", "0043_alter_abakusgroup_type"),
("files", "0005_file_save_for_use"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
Expand Down Expand Up @@ -186,7 +186,18 @@ class Migration(migrations.Migration):
("require_auth", models.BooleanField(default=True)),
("start_date", models.DateTimeField(null=True)),
("end_date", models.DateTimeField(null=True)),
("pending", models.BooleanField(default=True)),
(
"status",
models.CharField(
choices=[
("PENDING", "Pending"),
("ACCEPTED", "Accepted"),
("REJECTED", "Rejected"),
],
default="PENDING",
max_length=8,
),
),
("message", models.TextField(blank=True)),
(
"can_edit_groups",
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion lego/apps/lending/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from lego.apps.users.models import User

Check warning on line 4 in lego/apps/lending/notifications.py

View check run for this annotation

Codecov / codecov/patch

lego/apps/lending/notifications.py#L1-L4

Added lines #L1 - L4 were not covered by tests


class LendingInstanceNotification(Notification):
class LendingInstanceCreateNotification(Notification):
def __init__(self, lending_instance: LendingInstance, user: User):
self.lending_instance = lending_instance
self.lender = lending_instance.user

Check warning on line 10 in lego/apps/lending/notifications.py

View check run for this annotation

Codecov / codecov/patch

lego/apps/lending/notifications.py#L7-L10

Added lines #L7 - L10 were not covered by tests
Expand Down

0 comments on commit 2fa3ee6

Please sign in to comment.