Skip to content

Commit

Permalink
Fix other thing
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasdeluna authored and Arashfa0301 committed Oct 23, 2023
1 parent 10278d8 commit 69ee849
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lego/apps/lending/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def create(self, *args, **kwargs):
user = User.objects.get(pk=user_id)
notification = LendingInstanceNotification(
lending_instance=lending_instance,
user_email=user,
user=user,
)
notification.notify()

Expand Down
4 changes: 4 additions & 0 deletions lego/apps/lending/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class LendableObject(BasisModel):
responsible_role = models.CharField(
max_length=30, choices=constants.ROLES, default=constants.MEMBER
)
# TODO: options should be changed
image = models.ImageField(
source="cover", required=False, options={"height": 50, "filters": ["blur(20)"]}
)
location = models.CharField(max_length=128, null=False, blank=True)

@property
Expand Down
8 changes: 4 additions & 4 deletions lego/apps/lending/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
class LendingInstanceNotification(Notification):
def __init__(self, lending_instance: LendingInstance, user: User):
self.lending_instance = lending_instance
self.user = user
self.lender = lending_instance.user

# TODO: Might not work
super().__init__(user=lending_instance.user)
super().__init__(user=user)

name = "lending_instance_creation"

def generate_mail(self):
return self._delay_mail(
to_email=self.user.email_address,
context={
"user": self.user.full_name,
"lender": self.lender,
"lendable_object": self.lending_instance.lendable_object.title,
"start_date": self.lending_instance.start_date,
"end_date": self.lending_instance.end_date,
Expand All @@ -31,7 +31,7 @@ def generate_push(self):
return self._delay_push(
template="users/push/lending_instance.txt",
context={
"user": self.user.full_name,
"lender": self.lender,
"lendable_object": self.lending_instance.lendable_object.title,
"start_date": self.lending_instance.start_date,
"end_date": self.lending_instance.end_date,
Expand Down
6 changes: 1 addition & 5 deletions lego/apps/lending/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ class Meta:
def validate(self, data):
lendable_object_id = data["lendable_object"].id
lendable_object = LendableObject.objects.get(id=lendable_object_id)
user = self.request.user

user = self.context['request'].user
if not user.abakus_groups.filter(
id__in=lendable_object.responsible_groups.all().values_list("id", flat=True)
).exists():
Expand All @@ -31,7 +30,4 @@ def validate(self, data):
"Lending period exceeds maximum allowed duration"
)

# Add additional validation logic as per your use case
# ...

return data
3 changes: 1 addition & 2 deletions lego/apps/lending/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ class LendingInstanceViewSet(
]

def create(self, request):
serializer = LendingInstanceSerializer(request, data=request.data)

serializer = LendingInstanceSerializer(data=request.data, context={'request': request})
if serializer.is_valid(raise_exception=True):
serializer.save()
return Response(data=serializer.data, status=status.HTTP_201_CREATED)
Expand Down
3 changes: 2 additions & 1 deletion lego/apps/notifications/notification.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from structlog import get_logger
from lego.apps.users.models import User

from lego.utils.content_types import instance_to_string
from lego.utils.tasks import send_email, send_push
Expand All @@ -15,7 +16,7 @@ class Notification:

name = None

def __init__(self, user, *args, **kwargs):
def __init__(self, user: User, *args, **kwargs):
self.user = user
self.args = (args,)
self.kwargs = kwargs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<tr>
<td class="content-block">
Bruker: {{ user }}!
Bruker: {{ lender }}!
</td>
</tr>

Expand Down
2 changes: 1 addition & 1 deletion lego/apps/users/templates/users/email/lending_instance.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Det er en ny forespørsel om å låne {{ lendable_object }}!

Bruker: {{ user }}!
Bruker: {{ lender }}!

Fra: {{ start_date }}, Til: {{ end_date }}

Expand Down
2 changes: 1 addition & 1 deletion lego/apps/users/templates/users/push/lending_instance.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Det er en ny forespørsel om å låne {{ lendable_object }}!

Bruker: {{ user }}!
Bruker: {{ lender }}!

Fra: {{ start_date }}, Til: {{ end_date }}

0 comments on commit 69ee849

Please sign in to comment.