def build_notification(self, logentry: LogEntry) -> Notification: """ This is the main function that you should override. It is supposed to turn a log entry object into a notification object that can then be rendered e.g. into an email. """ return Notification( logentry.event, logentry.display() )
def form_valid(self, form): tz = self.request.event.timezone subevents = [] for rdate in self.get_rrule_set(): for t in self.get_times(): se = copy.copy(form.instance) se.date_from = make_aware( datetime.combine(rdate, t['time_from']), tz) if t.get('time_to'): se.date_to = ( make_aware(datetime.combine(rdate, t['time_to']), tz) if t.get('time_to') > t.get('time_from') else make_aware( datetime.combine(rdate + timedelta(days=1), t['time_to']), tz)) else: se.date_to = None se.date_admission = (make_aware( datetime.combine(rdate, t['time_admission']), tz) if t.get('time_admission') else None) se.presale_start = ( form.cleaned_data['rel_presale_start'].datetime(se) if form.cleaned_data.get('rel_presale_start') else None) se.presale_end = ( form.cleaned_data['rel_presale_end'].datetime(se) if form.cleaned_data.get('rel_presale_end') else None) se.save(clear_cache=False) subevents.append(se) data = dict(form.cleaned_data) for f in self.plugin_forms: data.update({ k: (f.cleaned_data.get(k).name if isinstance( f.cleaned_data.get(k), File) else f.cleaned_data.get(k)) for k in f.cleaned_data }) log_entries = [] for se in subevents: log_entries.append( se.log_action('pretix.subevent.added', data=data, user=self.request.user, save=False)) to_save = [] for f in self.meta_forms: if f.cleaned_data.get('value'): for se in subevents: i = copy.copy(f.instance) i.pk = None i.subevent = se to_save.append(i) SubEventMetaValue.objects.bulk_create(to_save) to_save_items = [] to_save_variations = [] for f in self.itemvar_forms: for se in subevents: i = copy.copy(f.instance) i.pk = None i.subevent = se if isinstance(i, SubEventItem): to_save_items.append(i) else: to_save_variations.append(i) SubEventItem.objects.bulk_create(to_save_items) SubEventItemVariation.objects.bulk_create(to_save_variations) to_save_items = [] to_save_variations = [] for f in self.formset.forms: if self.formset._should_delete_form(f) or not f.has_changed(): continue change_data = {k: f.cleaned_data.get(k) for k in f.changed_data} for se in subevents: i = copy.copy(f.instance) i.pk = None i.subevent = se i.event = se.event i.save(clear_cache=False) selected_items = set( list( self.request.event.items.filter(id__in=[ i.split('-')[0] for i in f.cleaned_data.get('itemvars', []) ]))) selected_variations = list( ItemVariation.objects.filter( item__event=self.request.event, id__in=[ i.split('-')[1] for i in f.cleaned_data.get('itemvars', []) if '-' in i ])) for _i in selected_items: to_save_items.append( Quota.items.through(quota_id=i.pk, item_id=_i.pk)) for _i in selected_variations: to_save_variations.append( Quota.variations.through(quota_id=i.pk, itemvariation_id=_i.pk)) change_data['id'] = i.pk log_entries.append( i.log_action(action='pretix.event.quota.added', user=self.request.user, data=change_data, save=False)) log_entries.append( se.log_action('pretix.subevent.quota.added', user=self.request.user, data=change_data, save=False)) Quota.items.through.objects.bulk_create(to_save_items) Quota.variations.through.objects.bulk_create(to_save_variations) to_save_products = [] for f in self.cl_formset.forms: if self.cl_formset._should_delete_form(f) or not f.has_changed(): continue change_data = {k: f.cleaned_data.get(k) for k in f.changed_data} for se in subevents: i = copy.copy(f.instance) i.subevent = se i.event = se.event i.save() for _i in f.cleaned_data.get('limit_products', []): to_save_products.append( CheckinList.limit_products.through(checkinlist_id=i.pk, item_id=_i.pk)) change_data['id'] = i.pk log_entries.append( i.log_action(action='pretix.event.checkinlist.added', user=self.request.user, data=change_data, save=False)) CheckinList.limit_products.through.objects.bulk_create( to_save_products) for f in self.plugin_forms: f.is_valid() for se in subevents: f.subevent = se f.save() if connections['default'].features.can_return_rows_from_bulk_insert: LogEntry.objects.bulk_create(log_entries) LogEntry.bulk_postprocess(log_entries) else: for le in log_entries: le.save() LogEntry.bulk_postprocess(log_entries) self.request.event.cache.clear() messages.success( self.request, pgettext_lazy('subevent', '{} new dates have been created.').format( len(subevents))) return redirect( reverse('control:event.subevents', kwargs={ 'organizer': self.request.event.organizer.slug, 'event': self.request.event.slug, }))