forked from CGM_Public/pretix_original
Added a basic framework for data exporters
This commit is contained in:
@@ -5,4 +5,8 @@ class PretixBaseConfig(AppConfig):
|
||||
name = 'pretix.base'
|
||||
label = 'pretixbase'
|
||||
|
||||
def ready(self):
|
||||
from . import exporter # NOQA
|
||||
from . import payment # NOQA
|
||||
|
||||
default_app_config = 'pretix.base.PretixBaseConfig'
|
||||
|
||||
70
src/pretix/base/exporter.py
Normal file
70
src/pretix/base/exporter.py
Normal file
@@ -0,0 +1,70 @@
|
||||
from django import forms
|
||||
from django.dispatch import receiver
|
||||
from django.http import HttpRequest, HttpResponse, JsonResponse
|
||||
|
||||
from pretix.base.signals import register_data_exporters
|
||||
|
||||
|
||||
class BaseExporter:
|
||||
"""
|
||||
This is the base class for all data exporters
|
||||
"""
|
||||
|
||||
def __init__(self, event):
|
||||
self.event = event
|
||||
|
||||
def __str__(self):
|
||||
return self.identifier
|
||||
|
||||
@property
|
||||
def verbose_name(self) -> str:
|
||||
"""
|
||||
A human-readable name for this exporter. This should be short but
|
||||
self-explaining. Good examples include 'JSON' or 'Microsoft Excel'.
|
||||
"""
|
||||
raise NotImplementedError() # NOQA
|
||||
|
||||
@property
|
||||
def identifier(self) -> str:
|
||||
"""
|
||||
A short and unique identifier for this exporter.
|
||||
This should only contain lowercase letters and in most
|
||||
cases will be the same as your packagename.
|
||||
"""
|
||||
raise NotImplementedError() # NOQA
|
||||
|
||||
@property
|
||||
def export_form_fields(self) -> dict:
|
||||
"""
|
||||
When the event's administrator administrator visits the export page, this method
|
||||
is called to return the configuration fields available.
|
||||
|
||||
It should therefore return a dictionary where the keys should be field names and
|
||||
the values should be corresponding Django form fields.
|
||||
|
||||
We suggest that you return an ``OrderedDict`` object instead of a dictionary.
|
||||
Your implementation could look like this::
|
||||
|
||||
@property
|
||||
def export_form_fields(self):
|
||||
return OrderedDict(
|
||||
[
|
||||
('tab_width',
|
||||
forms.IntegerField(
|
||||
label=_('Tab width'),
|
||||
default=4
|
||||
))
|
||||
]
|
||||
)
|
||||
"""
|
||||
return {}
|
||||
|
||||
def render(self, request: HttpRequest) -> HttpResponse:
|
||||
"""
|
||||
Render the exported file and return a request that either contains the file
|
||||
or redirects to it.
|
||||
|
||||
:type request: HttpRequest
|
||||
:param request: The HTTP request of the user requesting the export
|
||||
"""
|
||||
raise NotImplementedError() # NOQA
|
||||
@@ -10,6 +10,7 @@ class PluginType(Enum):
|
||||
RESTRICTION = 1
|
||||
PAYMENT = 2
|
||||
ADMINFEATURE = 3
|
||||
EXPORT = 4
|
||||
|
||||
|
||||
def get_all_plugins() -> "List[class]":
|
||||
|
||||
@@ -69,3 +69,11 @@ subclass of pretix.base.ticketoutput.BaseTicketOutput
|
||||
register_ticket_outputs = EventPluginSignal(
|
||||
providing_args=[]
|
||||
)
|
||||
|
||||
"""
|
||||
This signal is sent out to get all known data exporters. Receivers should return a
|
||||
subclass of pretix.base.exporter.BaseExporter
|
||||
"""
|
||||
register_data_exporters = EventPluginSignal(
|
||||
providing_args=[]
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user