mirror of
https://github.com/pretix/pretix.git
synced 2026-05-05 15:14:04 +00:00
* MKBDIGI-185: Added update/create to events * MKBDIGI-185: Added validation for 'slug, 'live' on event endpoint * MKBDIGI-185: Code formatting * MKBDIGI-185: Added 'plugins' to 'event' endpoint * MKBDIGI-185: Merge migrations * MKBDIGI-185: Cleaned up static methods * EBILL-5: Added delete endpoint for event * EBILL-5: Merge migrations * EBILL-5: Fixed imports * EBILL-5: Changed plugins to only list plugins enabled for the event * EBILL-5: Added clone event endpoint * EBILL-5: Removed permissions check API test for events * EBILL-5: Merged master, updated migrations * EBILL-5: Updated api permissions check for CRUD on events * EBILL-5: Removed 'unique_together' constraint on event model * EBILL-5: Removed call to changed static methods in test * EBILL-5: Changed Event 'has_paid_things' to a property for consistency * EBILL-5: Fixed created response code in documentation * EBILL-6: Documentation fixes * EBILL-6: Fixed typo * EBILL-6: Fixed permissions * EBILL-6: Added note on copying settings to documentation * EBILL-6: Created model method for deleting sub objects on event before delete * EBILL-6: Fixed typo * EBILL-6: Re-added meta_data as read-only * EBILL-6: Fixed permissions test * EBILL-6: Added plugins issues check before live. Moved issues property from form to Event model. * EBILL-6: Upped version number in documentation * Add write support for MetaDataField * EBILL-6: Expanded documentation for the clone endpoint, made behaviour of 'is_public' similar to 'plugins' for consistency * EBILL-6: Re-added EventCRUDPermission * EBILL-16: Updated documentation with permission model for the API * EBILL-16: Added 'has_subevents' validation to ensure it cannot be changed once event is created. * EBILL-16: Fixed event clone not differentiating between "not set" and "deliberately set to False" * EBILL-16: Fixed event live validation * EBILL-16: Added logging of live activated/deactivated * EBILL-16: Fixed create event bug when no 'meta_data' supplied * EBILL-16: Typo fixed * EBILL-16: Added log display for "event created" * EBILL-16: Enabling a plugin now calls 'installed' if applicable and log entries are added * EBILL-16: Updated tests for events * Do not allow enabling restricted plugins via the API * Remove unused code
This commit is contained in:
committed by
Raphael Michel
parent
1a0e2031d2
commit
7bb18f6fad
@@ -525,6 +525,40 @@ class Event(EventMixin, LoggedModel):
|
||||
data.update({v.property.name: v.value for v in self.meta_values.select_related('property').all()})
|
||||
return data
|
||||
|
||||
@property
|
||||
def has_payment_provider(self):
|
||||
result = False
|
||||
for provider in self.get_payment_providers().values():
|
||||
if provider.is_enabled and provider.identifier != 'free':
|
||||
result = True
|
||||
break
|
||||
return result
|
||||
|
||||
@property
|
||||
def has_paid_things(self):
|
||||
from .items import Item, ItemVariation
|
||||
|
||||
return Item.objects.filter(event=self, default_price__gt=0).exists()\
|
||||
or ItemVariation.objects.filter(item__event=self, default_price__gt=0).exists()
|
||||
|
||||
@cached_property
|
||||
def live_issues(self):
|
||||
from pretix.base.signals import event_live_issues
|
||||
issues = []
|
||||
|
||||
if self.has_paid_things and not self.has_payment_provider:
|
||||
issues.append(_('You have configured at least one paid product but have not enabled any payment methods.'))
|
||||
|
||||
if not self.quotas.exists():
|
||||
issues.append(_('You need to configure at least one quota to sell anything.'))
|
||||
|
||||
responses = event_live_issues.send(self)
|
||||
for receiver, response in sorted(responses, key=lambda r: str(r[0])):
|
||||
if response:
|
||||
issues.append(response)
|
||||
|
||||
return issues
|
||||
|
||||
def get_users_with_any_permission(self):
|
||||
"""
|
||||
Returns a queryset of users who have any permission to this event.
|
||||
@@ -556,9 +590,78 @@ class Event(EventMixin, LoggedModel):
|
||||
|
||||
return User.objects.annotate(twp=Exists(team_with_perm)).filter(twp=True)
|
||||
|
||||
def clean_live(self):
|
||||
for issue in self.live_issues:
|
||||
if issue:
|
||||
raise ValidationError(issue)
|
||||
|
||||
def allow_delete(self):
|
||||
return not self.orders.exists() and not self.invoices.exists()
|
||||
|
||||
def delete_sub_objects(self):
|
||||
self.items.all().delete()
|
||||
self.subevents.all().delete()
|
||||
|
||||
def set_active_plugins(self, modules, allow_restricted=False):
|
||||
from pretix.base.plugins import get_all_plugins
|
||||
|
||||
plugins_active = self.get_plugins()
|
||||
plugins_available = {
|
||||
p.module: p for p in get_all_plugins()
|
||||
if not p.name.startswith('.') and getattr(p, 'visible', True)
|
||||
}
|
||||
|
||||
enable = [m for m in modules if m not in plugins_active and m in plugins_available]
|
||||
|
||||
for module in enable:
|
||||
if getattr(plugins_available[module].app, 'restricted', False) and not allow_restricted:
|
||||
modules.remove(module)
|
||||
elif hasattr(plugins_available[module].app, 'installed'):
|
||||
getattr(plugins_available[module].app, 'installed')(self)
|
||||
|
||||
self.plugins = ",".join(modules)
|
||||
|
||||
def enable_plugin(self, module, allow_restricted=False):
|
||||
plugins_active = self.get_plugins()
|
||||
|
||||
if module not in plugins_active:
|
||||
plugins_active.append(module)
|
||||
self.set_active_plugins(plugins_active, allow_restricted=allow_restricted)
|
||||
|
||||
def disable_plugin(self, module):
|
||||
plugins_active = self.get_plugins()
|
||||
|
||||
if module in plugins_active:
|
||||
plugins_active.remove(module)
|
||||
self.set_active_plugins(plugins_active)
|
||||
|
||||
@staticmethod
|
||||
def clean_has_subevents(event, has_subevents):
|
||||
if event is not None and event.has_subevents is not None:
|
||||
if event.has_subevents != has_subevents:
|
||||
raise ValidationError(_('Once created an event cannot change between an series and a single event.'))
|
||||
|
||||
@staticmethod
|
||||
def clean_slug(organizer, event, slug):
|
||||
if event is not None and event.slug is not None:
|
||||
if event.slug != slug:
|
||||
raise ValidationError(_('The event slug cannot be changed.'))
|
||||
else:
|
||||
if Event.objects.filter(slug=slug, organizer=organizer).exists():
|
||||
raise ValidationError(_('This slug has already been used for a different event.'))
|
||||
|
||||
@staticmethod
|
||||
def clean_dates(date_from, date_to):
|
||||
if date_from is not None and date_to is not None:
|
||||
if date_from > date_to:
|
||||
raise ValidationError(_('The event cannot end before it starts.'))
|
||||
|
||||
@staticmethod
|
||||
def clean_presale(presale_start, presale_end):
|
||||
if presale_start is not None and presale_end is not None:
|
||||
if presale_start > presale_end:
|
||||
raise ValidationError(_('The event\'s presale cannot end before it starts.'))
|
||||
|
||||
|
||||
class SubEvent(EventMixin, LoggedModel):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user