create all stories + story parts on round create

master
Gesche 3 years ago
parent cd427ad974
commit be0be5a38f

@ -27,23 +27,27 @@ class DetailView(generic.DetailView):
class StoryRoundCreate(CreateView):
model = StoryRound
fields = ['name', 'participants', 'number_of_rounds']
success_url = reverse_lazy('writing:index')
def form_valid(self, form):
self.object = form.save()
sorted_participants = sorted(form.cleaned_data['participants'])
number_of_participants = len(sorted_participants)
for user in form.cleaned_data['participants']:
participant = Participant.objects.create(
user=user,
order_by=1, # TODO: get order by from form
story_round=self.object
)
Story.objects.create(
for user in sorted_participants:
story = Story.objects.create(
part_of_round=self.object,
started_by=participant
started_by=user
)
return HttpResponseRedirect(self.get_success_url())
previous_part=None
for i in range(form.cleaned_data['number_of_rounds']):
current_part = StoryPart.objects.create(
user=sorted_participants[i % number_of_participants],
previous_part=previous_part,
part_of=story
)
previous_part = current_part
class StoryUpdate(UpdateView):

Loading…
Cancel
Save