create all stories + story parts on round create
This commit is contained in:
parent
cd427ad974
commit
be0be5a38f
|
@ -27,23 +27,27 @@ class DetailView(generic.DetailView):
|
||||||
class StoryRoundCreate(CreateView):
|
class StoryRoundCreate(CreateView):
|
||||||
model = StoryRound
|
model = StoryRound
|
||||||
fields = ['name', 'participants', 'number_of_rounds']
|
fields = ['name', 'participants', 'number_of_rounds']
|
||||||
|
success_url = reverse_lazy('writing:index')
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
self.object = form.save()
|
self.object = form.save()
|
||||||
|
sorted_participants = sorted(form.cleaned_data['participants'])
|
||||||
|
number_of_participants = len(sorted_participants)
|
||||||
|
|
||||||
for user in form.cleaned_data['participants']:
|
for user in sorted_participants:
|
||||||
participant = Participant.objects.create(
|
story = Story.objects.create(
|
||||||
user=user,
|
|
||||||
order_by=1, # TODO: get order by from form
|
|
||||||
story_round=self.object
|
|
||||||
)
|
|
||||||
|
|
||||||
Story.objects.create(
|
|
||||||
part_of_round=self.object,
|
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):
|
class StoryUpdate(UpdateView):
|
||||||
|
|
Loading…
Reference in New Issue