def form_valid(self, form):
startDate = form.cleaned_data.get('<STR_LIT>')<EOL>repeatEvery = form.cleaned_data.get('<STR_LIT>')<EOL>periodicity = form.cleaned_data.get('<STR_LIT>')<EOL>quantity = form.cleaned_data.get('<STR_LIT>')<EOL>endDate = form.cleaned_data.get('<STR_LIT>')<EOL>if periodicity == '<STR_LIT:D>':<EOL><INDENT>delta = {'<STR_LIT>': repeatEvery}<EOL><DEDENT>elif periodicity == '<STR_LIT>':<EOL><INDENT>delta = {'<STR_LIT>': repeatEvery}<EOL><DEDENT>elif periodicity == '<STR_LIT:M>':<EOL><INDENT>delta = {'<STR_LIT>': repeatEvery}<EOL><DEDENT>repeat_list = []<EOL>this_date = startDate<EOL>if quantity:<EOL><INDENT>for k in range(<NUM_LIT:0>, quantity):<EOL><INDENT>repeat_list.append(this_date)<EOL>this_date = this_date + relativedelta(**delta)<EOL><DEDENT><DEDENT>elif endDate:<EOL><INDENT>while (this_date <= endDate):<EOL><INDENT>repeat_list.append(this_date)<EOL>this_date = this_date + relativedelta(**delta)<EOL><DEDENT><DEDENT>for event in self.queryset:<EOL><INDENT>old_min_time = event.localStartTime.replace(hour=<NUM_LIT:0>, minute=<NUM_LIT:0>, second=<NUM_LIT:0>, microsecond=<NUM_LIT:0>)<EOL>old_occurrence_data = [<EOL>(x.startTime - old_min_time, x.endTime - old_min_time, x.cancelled)<EOL>for x in event.eventoccurrence_set.all()<EOL>]<EOL>old_role_data = [(x.role, x.capacity) for x in event.eventrole_set.all()]<EOL>for instance_date in repeat_list:<EOL><INDENT>combined_datetime = datetime.combine(instance_date, datetime.min.time())<EOL>new_datetime = ensure_timezone(combined_datetime, old_min_time.tzinfo)<EOL>event.id = None<EOL>event.pk = None<EOL>event.save()<EOL>for occurrence in old_occurrence_data:<EOL><INDENT>EventOccurrence.objects.create(<EOL>event=event,<EOL>startTime=new_datetime + occurrence[<NUM_LIT:0>],<EOL>endTime=new_datetime + occurrence[<NUM_LIT:1>],<EOL>cancelled=occurrence[<NUM_LIT:2>],<EOL>)<EOL><DEDENT>for role in old_role_data:<EOL><INDENT>EventRole.objects.create(<EOL>event=event,<EOL>role=role[<NUM_LIT:0>],<EOL>capacity=role[<NUM_LIT:1>],<EOL>)<EOL><DEDENT>event.save()<EOL><DEDENT>return super(RepeatEventsView, self).form_valid(form)<EOL><DEDENT>
For each object in the queryset, create the duplicated objects