def save(self, *args, **kwargs): if self.cleaned_data.get('copy_from'): self.instance.description = self.cleaned_data['copy_from'].description self.instance.active = self.cleaned_data['copy_from'].active self.instance.available_from = self.cleaned_data['copy_from'].available_from self.instance.available_until = self.cleaned_data['copy_from'].available_until self.instance.require_voucher = self.cleaned_data['copy_from'].require_voucher self.instance.hide_without_voucher = self.cleaned_data['copy_from'].hide_without_voucher self.instance.allow_cancel = self.cleaned_data['copy_from'].allow_cancel self.instance.min_per_order = self.cleaned_data['copy_from'].min_per_order self.instance.max_per_order = self.cleaned_data['copy_from'].max_per_order self.instance.checkin_attention = self.cleaned_data['copy_from'].checkin_attention self.instance.free_price = self.cleaned_data['copy_from'].free_price self.instance.original_price = self.cleaned_data['copy_from'].original_price self.instance.sales_channels = self.cleaned_data['copy_from'].sales_channels else: # Add to all sales channels by default self.instance.sales_channels = [k for k in get_all_sales_channels().keys()] self.instance.position = (self.event.items.aggregate(p=Max('position'))['p'] or 0) + 1 instance = super().save(*args, **kwargs) if not self.event.has_subevents and not self.cleaned_data.get('has_variations'): if self.cleaned_data.get('quota_option') == self.EXISTING and self.cleaned_data.get('quota_add_existing') is not None: quota = self.cleaned_data.get('quota_add_existing') quota.items.add(self.instance) quota.log_action('pretix.event.quota.changed', user=self.user, data={ 'item_added': self.instance.pk }) elif self.cleaned_data.get('quota_option') == self.NEW: quota_name = self.cleaned_data.get('quota_add_new_name') quota_size = self.cleaned_data.get('quota_add_new_size') quota = Quota.objects.create( event=self.event, name=quota_name, size=quota_size ) quota.items.add(self.instance) quota.log_action('pretix.event.quota.added', user=self.user, data={ 'name': quota_name, 'size': quota_size, 'items': [self.instance.pk] }) if self.cleaned_data.get('has_variations'): if self.cleaned_data.get('copy_from') and self.cleaned_data.get('copy_from').has_variations: for variation in self.cleaned_data['copy_from'].variations.all(): ItemVariation.objects.create(item=instance, value=variation.value, active=variation.active, position=variation.position, default_price=variation.default_price) else: ItemVariation.objects.create( item=instance, value=__('Standard') ) if self.cleaned_data.get('copy_from'): for question in self.cleaned_data['copy_from'].questions.all(): question.items.add(instance) item_copy_data.send(sender=self.event, source=self.cleaned_data['copy_from'], target=instance) return instance
def save(self, *args, **kwargs): if self.cleaned_data.get('copy_from'): self.instance.description = self.cleaned_data['copy_from'].description self.instance.active = self.cleaned_data['copy_from'].active self.instance.available_from = self.cleaned_data['copy_from'].available_from self.instance.available_until = self.cleaned_data['copy_from'].available_until self.instance.require_voucher = self.cleaned_data['copy_from'].require_voucher self.instance.hide_without_voucher = self.cleaned_data['copy_from'].hide_without_voucher self.instance.allow_cancel = self.cleaned_data['copy_from'].allow_cancel self.instance.min_per_order = self.cleaned_data['copy_from'].min_per_order self.instance.max_per_order = self.cleaned_data['copy_from'].max_per_order self.instance.checkin_attention = self.cleaned_data['copy_from'].checkin_attention self.instance.free_price = self.cleaned_data['copy_from'].free_price self.instance.original_price = self.cleaned_data['copy_from'].original_price self.instance.sales_channels = self.cleaned_data['copy_from'].sales_channels else: # Add to all sales channels by default self.instance.sales_channels = [k for k in get_all_sales_channels().keys()] self.instance.position = (self.event.items.aggregate(p=Max('position'))['p'] or 0) + 1 instance = super().save(*args, **kwargs) if not self.event.has_subevents and not self.cleaned_data.get('has_variations'): if self.cleaned_data.get('quota_option') == self.EXISTING and self.cleaned_data.get('quota_add_existing') is not None: quota = self.cleaned_data.get('quota_add_existing') quota.items.add(self.instance) quota.log_action('pretix.event.quota.changed', user=self.user, data={ 'item_added': self.instance.pk }) elif self.cleaned_data.get('quota_option') == self.NEW: quota_name = self.cleaned_data.get('quota_add_new_name') quota_size = self.cleaned_data.get('quota_add_new_size') quota = Quota.objects.create( event=self.event, name=quota_name, size=quota_size ) quota.items.add(self.instance) quota.log_action('pretix.event.quota.added', user=self.user, data={ 'name': quota_name, 'size': quota_size, 'items': [self.instance.pk] }) if self.cleaned_data.get('has_variations'): if self.cleaned_data.get('copy_from') and self.cleaned_data.get('copy_from').has_variations: for variation in self.cleaned_data['copy_from'].variations.all(): ItemVariation.objects.create(item=instance, value=variation.value, active=variation.active, position=variation.position, default_price=variation.default_price) else: ItemVariation.objects.create( item=instance, value=__('Standard') ) if self.cleaned_data.get('copy_from'): for question in self.cleaned_data['copy_from'].questions.all(): question.items.add(instance) for a in self.cleaned_data['copy_from'].addons.all(): instance.addons.create(addon_category=a.addon_category, min_count=a.min_count, max_count=a.max_count, price_included=a.price_included, position=a.position) for b in self.cleaned_data['copy_from'].bundles.all(): instance.bundles.create(bundled_item=b.bundled_item, bundled_variation=b.bundled_variation, count=b.count, designated_price=b.designated_price) item_copy_data.send(sender=self.event, source=self.cleaned_data['copy_from'], target=instance) return instance
def save(self, *args, **kwargs): if self.cleaned_data.get('copy_from'): src = self.cleaned_data['copy_from'] fields = ( 'description', 'active', 'available_from', 'available_until', 'require_voucher', 'hide_without_voucher', 'allow_cancel', 'min_per_order', 'max_per_order', 'generate_tickets', 'checkin_attention', 'free_price', 'original_price', 'sales_channels', 'issue_giftcard', 'require_approval', 'allow_waitinglist', 'show_quota_left', 'hidden_if_available', 'require_bundling', 'checkin_attention', 'require_membership', 'grant_membership_type', 'grant_membership_duration_like_event', 'grant_membership_duration_days', 'grant_membership_duration_months', ) for f in fields: setattr(self.instance, f, getattr(src, f)) if src.picture: self.instance.picture.save(os.path.basename(src.picture.name), src.picture) else: # Add to all sales channels by default self.instance.sales_channels = list(get_all_sales_channels().keys()) self.instance.position = (self.event.items.aggregate(p=Max('position'))['p'] or 0) + 1 instance = super().save(*args, **kwargs) if not self.event.has_subevents and not self.cleaned_data.get('has_variations'): if self.cleaned_data.get('quota_option') == self.EXISTING and self.cleaned_data.get('quota_add_existing') is not None: quota = self.cleaned_data.get('quota_add_existing') quota.items.add(self.instance) quota.log_action('pretix.event.quota.changed', user=self.user, data={ 'item_added': self.instance.pk }) elif self.cleaned_data.get('quota_option') == self.NEW: quota_name = self.cleaned_data.get('quota_add_new_name') quota_size = self.cleaned_data.get('quota_add_new_size') quota = Quota.objects.create( event=self.event, name=quota_name, size=quota_size ) quota.items.add(self.instance) quota.log_action('pretix.event.quota.added', user=self.user, data={ 'name': quota_name, 'size': quota_size, 'items': [self.instance.pk] }) if self.cleaned_data.get('copy_from'): self.instance.require_membership_types.set( self.cleaned_data['copy_from'].require_membership_types.all() ) if self.cleaned_data.get('has_variations'): if self.cleaned_data.get('copy_from') and self.cleaned_data.get('copy_from').has_variations: for variation in self.cleaned_data['copy_from'].variations.all(): ItemVariation.objects.create(item=instance, value=variation.value, active=variation.active, position=variation.position, default_price=variation.default_price, description=variation.description, original_price=variation.original_price) else: ItemVariation.objects.create( item=instance, value=__('Standard') ) if self.cleaned_data.get('copy_from'): for question in self.cleaned_data['copy_from'].questions.all(): question.items.add(instance) for a in self.cleaned_data['copy_from'].addons.all(): instance.addons.create(addon_category=a.addon_category, min_count=a.min_count, max_count=a.max_count, price_included=a.price_included, position=a.position, multi_allowed=a.multi_allowed) for b in self.cleaned_data['copy_from'].bundles.all(): instance.bundles.create(bundled_item=b.bundled_item, bundled_variation=b.bundled_variation, count=b.count, designated_price=b.designated_price) item_copy_data.send(sender=self.event, source=self.cleaned_data['copy_from'], target=instance) return instance