Added a basic framework for data exporters

This commit is contained in:
Raphael Michel
2015-08-14 22:44:07 +02:00
parent e49a159ff4
commit c928864477
10 changed files with 221 additions and 1 deletions

View File

@@ -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'

View 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

View File

@@ -10,6 +10,7 @@ class PluginType(Enum):
RESTRICTION = 1
PAYMENT = 2
ADMINFEATURE = 3
EXPORT = 4
def get_all_plugins() -> "List[class]":

View File

@@ -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=[]
)