def form_valid(self,form):
regSession = self.request.session.get(REG_VALIDATION_STR, {})<EOL>expiry = timezone.now() + timedelta(minutes=getConstant('<STR_LIT>'))<EOL>permitted_keys = getattr(form,'<STR_LIT>',['<STR_LIT>',])<EOL>try:<EOL><INDENT>event_listing = {<EOL>int(key.split("<STR_LIT:_>")[-<NUM_LIT:1>]): {k:v for k,v in json.loads(value[<NUM_LIT:0>]).items() if k in permitted_keys}<EOL>for key,value in form.cleaned_data.items() if '<STR_LIT>' in key and value<EOL>}<EOL>non_event_listing = {key: value for key,value in form.cleaned_data.items() if '<STR_LIT>' not in key}<EOL><DEDENT>except (ValueError, TypeError) as e:<EOL><INDENT>form.add_error(None,ValidationError(_('<STR_LIT>'),code='<STR_LIT>'))<EOL>return super(ClassRegistrationView,self).form_invalid(form)<EOL><DEDENT>associated_events = Event.objects.filter(id__in=[k for k in event_listing.keys()])<EOL>if self.request.user.is_authenticated:<EOL><INDENT>submissionUser = self.request.user<EOL><DEDENT>else:<EOL><INDENT>submissionUser = None<EOL><DEDENT>reg = TemporaryRegistration(<EOL>submissionUser=submissionUser,dateTime=timezone.now(),<EOL>payAtDoor=non_event_listing.pop('<STR_LIT>',False),<EOL>expirationDate=expiry,<EOL>)<EOL>reg.data = non_event_listing or {}<EOL>if regSession.get('<STR_LIT>'):<EOL><INDENT>reg.data.update({'<STR_LIT>': regSession.pop('<STR_LIT>',None)})<EOL><DEDENT>eventRegs = []<EOL>grossPrice = <NUM_LIT:0><EOL>for key,value in event_listing.items():<EOL><INDENT>this_event = associated_events.get(id=key)<EOL>this_role_id = value.get('<STR_LIT>',None) if '<STR_LIT>' in permitted_keys else None<EOL>soldOut = this_event.soldOutForRole(role=this_role_id,includeTemporaryRegs=True)<EOL>if soldOut:<EOL><INDENT>if self.request.user.has_perm('<STR_LIT>'):<EOL><INDENT>messages.warning(self.request,_(<EOL>'<STR_LIT>' % this_event.name +<EOL>'<STR_LIT>' +<EOL>'<STR_LIT>'<EOL>))<EOL><DEDENT>else:<EOL><INDENT>form.add_error(None, ValidationError(_('<STR_LIT>' % this_event.name),code='<STR_LIT>'))<EOL>return super(ClassRegistrationView,self).form_invalid(form)<EOL><DEDENT><DEDENT>dropInList = [int(k.split("<STR_LIT:_>")[-<NUM_LIT:1>]) for k,v in value.items() if k.startswith('<STR_LIT>') and v is True]<EOL>logger.debug('<STR_LIT>' % key)<EOL>if len(dropInList) > <NUM_LIT:0>:<EOL><INDENT>tr = TemporaryEventRegistration(<EOL>event=this_event, dropIn=True, price=this_event.getBasePrice(dropIns=len(dropInList))<EOL>)<EOL><DEDENT>else:<EOL><INDENT>tr = TemporaryEventRegistration(<EOL>event=this_event, price=this_event.getBasePrice(payAtDoor=reg.payAtDoor), role_id=this_role_id<EOL>)<EOL><DEDENT>tr.data = {k: v for k,v in value.items() if k in permitted_keys and k != '<STR_LIT>'}<EOL>eventRegs.append(tr)<EOL>grossPrice += tr.price<EOL><DEDENT>reg.priceWithDiscount = grossPrice<EOL>reg.save()<EOL>for er in eventRegs:<EOL><INDENT>er.registration = reg<EOL>er.save()<EOL><DEDENT>regSession["<STR_LIT>"] = reg.id<EOL>regSession["<STR_LIT>"] = expiry.strftime('<STR_LIT>')<EOL>self.request.session[REG_VALIDATION_STR] = regSession<EOL>if self.returnJson:<EOL><INDENT>return JsonResponse({<EOL>'<STR_LIT:status>': '<STR_LIT:success>', '<STR_LIT>': self.get_success_url()<EOL>})<EOL><DEDENT>return HttpResponseRedirect(self.get_success_url())<EOL>
If the form is valid, pass its contents on to the next view.  In order to permit the registration
form to be overridden flexibly, but without permitting storage of arbitrary data keys that could
lead to potential security issues, a form class for this view can optionally specify a list of
keys that are permitted.  If no such list is specified as instance.permitted_event_keys, then
the default list are used.