Skip to content

Commit

Permalink
Merge pull request #1554 from RomainFayolle/feature-export_retreat_pa…
Browse files Browse the repository at this point in the history
…rticipant_room

Modify call to pass id because celery cant handle django objects
  • Loading branch information
RignonNoel authored Sep 9, 2022
2 parents 2e87a2b + cc8dce2 commit b23c6ef
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion retirement/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def export_retreat_sales(self, request, queryset):

def export_retreat_room_distribution(self, request, queryset):
for retreat in queryset:
generate_retreat_room_distribution.delay(request.user.id, retreat)
generate_retreat_room_distribution.delay(request.user.id, retreat.id)


export_retreat_room_distribution.short_description = 'export_retreat_room_distribution'
Expand Down
6 changes: 4 additions & 2 deletions retirement/exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.utils import timezone

from blitz_api.models import ExportMedia
from retirement.models import Retreat


def generate_retreat_sales(
Expand Down Expand Up @@ -52,12 +53,12 @@ def generate_retreat_sales(
@shared_task()
def generate_retreat_room_distribution(
admin_id,
retreat
retreat_id
):
"""
For given retreats, generate a csv file for room distribution
:params admin_id: id of admin doing the request
:params retreat: django retreat object
:params retreat_id: id of django retreat object
"""

output_stream = io.StringIO()
Expand All @@ -69,6 +70,7 @@ def generate_retreat_room_distribution(
]

writer.writerow(header)
retreat = Retreat.objects.get(pk=retreat_id)
participants_distribution_data = retreat.get_retreat_room_distribution()

for p in participants_distribution_data:
Expand Down
3 changes: 1 addition & 2 deletions retirement/tests/test_export_retreat_room_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ def test_export_retreat_room_distribution(self, mock_email, mock_room_distributi
{'first_name': 'Justin', 'last_name': 'Martin', 'email': '[email protected]', 'room_option': 'shared',
'gender_preference': 'woman', 'share_with': '[email protected]', 'room_number': 4, 'placed': True}
]
retreat = Retreat.objects.get(pk=self.retreat.id)
generate_retreat_room_distribution(self.admin.id, retreat)
generate_retreat_room_distribution(self.admin.id, self.retreat.id)
self.assertEqual(
ExportMedia.objects.all().count(),
1)
Expand Down

0 comments on commit b23c6ef

Please sign in to comment.