feat: Automatically subscribe user that created AN to AN
This commit is contained in:
parent
44f05cbb7d
commit
9b824bc326
@ -163,6 +163,9 @@ class User(AbstractUser):
|
|||||||
def get_notifications_url(self):
|
def get_notifications_url(self):
|
||||||
return self.get_absolute_url()
|
return self.get_absolute_url()
|
||||||
|
|
||||||
|
def get_unread_notifications(self):
|
||||||
|
return BaseNotification.objects.filter(user=self, read=False)
|
||||||
|
|
||||||
def get_num_unread_notifications(self):
|
def get_num_unread_notifications(self):
|
||||||
return BaseNotification.objects.filter(user=self, read=False).count()
|
return BaseNotification.objects.filter(user=self, read=False).count()
|
||||||
|
|
||||||
|
@ -210,18 +210,18 @@ def add_adoption_notice(request):
|
|||||||
in_adoption_notice_creation_flow=True)
|
in_adoption_notice_creation_flow=True)
|
||||||
|
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
instance = form.save(commit=False)
|
an_instance = form.save(commit=False)
|
||||||
instance.owner = request.user
|
an_instance.owner = request.user
|
||||||
instance.save()
|
an_instance.save()
|
||||||
|
|
||||||
"""Spin up a task that adds the location"""
|
"""Spin up a task that adds the location"""
|
||||||
add_adoption_notice_location.delay_on_commit(instance.pk)
|
add_adoption_notice_location.delay_on_commit(an_instance.pk)
|
||||||
|
|
||||||
# Set correct status
|
# Set correct status
|
||||||
if request.user.trust_level >= TrustLevel.MODERATOR:
|
if request.user.trust_level >= TrustLevel.MODERATOR:
|
||||||
instance.set_active()
|
an_instance.set_active()
|
||||||
else:
|
else:
|
||||||
instance.set_unchecked()
|
an_instance.set_unchecked()
|
||||||
|
|
||||||
# Get the species and number of animals from the form
|
# Get the species and number of animals from the form
|
||||||
species = form.cleaned_data["species"]
|
species = form.cleaned_data["species"]
|
||||||
@ -230,13 +230,18 @@ def add_adoption_notice(request):
|
|||||||
date_of_birth = form.cleaned_data["date_of_birth"]
|
date_of_birth = form.cleaned_data["date_of_birth"]
|
||||||
for i in range(0, num_animals):
|
for i in range(0, num_animals):
|
||||||
Animal.objects.create(owner=request.user,
|
Animal.objects.create(owner=request.user,
|
||||||
name=f"{species} {i + 1}", adoption_notice=instance, species=species, sex=sex,
|
name=f"{species} {i + 1}", adoption_notice=an_instance, species=species, sex=sex,
|
||||||
date_of_birth=date_of_birth)
|
date_of_birth=date_of_birth)
|
||||||
|
|
||||||
"""Log"""
|
"""Log"""
|
||||||
Log.objects.create(user=request.user, action="add_adoption_notice",
|
Log.objects.create(user=request.user, action="add_adoption_notice",
|
||||||
text=f"{request.user} hat Vermittlung {instance.pk} hinzugefügt")
|
text=f"{request.user} hat Vermittlung {an_instance.pk} hinzugefügt")
|
||||||
return redirect(reverse("adoption-notice-detail", args=[instance.pk]))
|
|
||||||
|
"""Subscriptions"""
|
||||||
|
# Automatically subscribe user that created AN to AN
|
||||||
|
Subscriptions.objects.create(owner=request.user, adoption_notice=an_instance)
|
||||||
|
|
||||||
|
return redirect(reverse("adoption-notice-detail", args=[an_instance.pk]))
|
||||||
else:
|
else:
|
||||||
form = AdoptionNoticeFormWithDateWidgetAutoAnimal(in_adoption_notice_creation_flow=True)
|
form = AdoptionNoticeFormWithDateWidgetAutoAnimal(in_adoption_notice_creation_flow=True)
|
||||||
return render(request, 'fellchensammlung/forms/form_add_adoption.html', {'form': form})
|
return render(request, 'fellchensammlung/forms/form_add_adoption.html', {'form': form})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user