mirror of
https://github.com/pretix/pretix.git
synced 2026-05-07 15:34:02 +00:00
move logentrytypes to own module
This commit is contained in:
139
src/pretix/base/logentrytypes.py
Normal file
139
src/pretix/base/logentrytypes.py
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
|
from django.urls import reverse
|
||||||
|
from django.utils.html import escape
|
||||||
|
from django.utils.translation import gettext_lazy as _, pgettext_lazy
|
||||||
|
|
||||||
|
from pretix.base.models.log import make_link
|
||||||
|
from pretix.base.signals import EventPluginRegistry
|
||||||
|
|
||||||
|
|
||||||
|
class LogEntryTypeRegistry(EventPluginRegistry):
|
||||||
|
def new_from_dict(self, data):
|
||||||
|
def reg(clz):
|
||||||
|
for action_type, plain in data.items():
|
||||||
|
self.register(clz(action_type=action_type, plain=plain))
|
||||||
|
return reg
|
||||||
|
|
||||||
|
|
||||||
|
log_entry_types = LogEntryTypeRegistry({'action_type': lambda o: getattr(o, 'action_type')})
|
||||||
|
|
||||||
|
|
||||||
|
class LogEntryType:
|
||||||
|
def __init__(self, action_type=None, plain=None):
|
||||||
|
assert self.__module__ != LogEntryType.__module__ # must not instantiate base classes, only derived ones
|
||||||
|
if action_type: self.action_type = action_type
|
||||||
|
if plain: self.plain = plain
|
||||||
|
|
||||||
|
def display(self, logentry):
|
||||||
|
if hasattr(self, 'plain'):
|
||||||
|
plain = str(self.plain)
|
||||||
|
if '{' in plain:
|
||||||
|
data = defaultdict(lambda: '?', logentry.parsed_data)
|
||||||
|
return plain.format_map(data)
|
||||||
|
else:
|
||||||
|
return plain
|
||||||
|
|
||||||
|
def get_object_link_info(self, logentry) -> dict:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def get_object_link(self, logentry):
|
||||||
|
a_map = self.get_object_link_info(logentry)
|
||||||
|
return make_link(a_map, self.object_link_wrapper)
|
||||||
|
|
||||||
|
object_link_wrapper = '{val}'
|
||||||
|
|
||||||
|
def shred_pii(self, logentry):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
|
class EventLogEntryType(LogEntryType):
|
||||||
|
def get_object_link_info(self, logentry) -> dict:
|
||||||
|
if hasattr(self, 'object_link_viewname') and hasattr(self, 'object_link_argname') and logentry.content_object:
|
||||||
|
return {
|
||||||
|
'href': reverse(self.object_link_viewname, kwargs={
|
||||||
|
'event': logentry.event.slug,
|
||||||
|
'organizer': logentry.event.organizer.slug,
|
||||||
|
self.object_link_argname: self.object_link_argvalue(logentry.content_object),
|
||||||
|
}),
|
||||||
|
'val': escape(self.object_link_display_name(logentry.content_object)),
|
||||||
|
}
|
||||||
|
|
||||||
|
def object_link_argvalue(self, content_object):
|
||||||
|
return content_object.id
|
||||||
|
|
||||||
|
def object_link_display_name(self, content_object):
|
||||||
|
return str(content_object)
|
||||||
|
|
||||||
|
|
||||||
|
class OrderLogEntryType(EventLogEntryType):
|
||||||
|
object_link_wrapper = _('Order {val}')
|
||||||
|
object_link_viewname = 'control:event.order'
|
||||||
|
object_link_argname = 'code'
|
||||||
|
|
||||||
|
def object_link_argvalue(self, order):
|
||||||
|
return order.code
|
||||||
|
|
||||||
|
def object_link_display_name(self, order):
|
||||||
|
return order.code
|
||||||
|
|
||||||
|
|
||||||
|
class VoucherLogEntryType(EventLogEntryType):
|
||||||
|
object_link_wrapper = _('Voucher {val}…')
|
||||||
|
object_link_viewname = 'control:event.voucher'
|
||||||
|
object_link_argname = 'voucher'
|
||||||
|
|
||||||
|
def object_link_display_name(self, order):
|
||||||
|
return order.code[:6]
|
||||||
|
|
||||||
|
|
||||||
|
class ItemLogEntryType(EventLogEntryType):
|
||||||
|
object_link_wrapper = _('Product {val}')
|
||||||
|
object_link_viewname = 'control:event.item'
|
||||||
|
object_link_argname = 'item'
|
||||||
|
|
||||||
|
|
||||||
|
class SubEventLogEntryType(EventLogEntryType):
|
||||||
|
object_link_wrapper = pgettext_lazy('subevent', 'Date {val}')
|
||||||
|
object_link_viewname = 'control:event.subevent'
|
||||||
|
object_link_argname = 'subevent'
|
||||||
|
|
||||||
|
|
||||||
|
class QuotaLogEntryType(EventLogEntryType):
|
||||||
|
object_link_wrapper = _('Quota {val}')
|
||||||
|
object_link_viewname = 'control:event.items.quotas.show'
|
||||||
|
object_link_argname = 'quota'
|
||||||
|
|
||||||
|
|
||||||
|
class DiscountLogEntryType(EventLogEntryType):
|
||||||
|
object_link_wrapper = _('Discount {val}')
|
||||||
|
object_link_viewname = 'control:event.items.discounts.edit'
|
||||||
|
object_link_argname = 'discount'
|
||||||
|
|
||||||
|
|
||||||
|
class ItemCategoryLogEntryType(EventLogEntryType):
|
||||||
|
object_link_wrapper = _('Category {val}')
|
||||||
|
object_link_viewname = 'control:event.items.categories.edit'
|
||||||
|
object_link_argname = 'category'
|
||||||
|
|
||||||
|
|
||||||
|
class QuestionLogEntryType(EventLogEntryType):
|
||||||
|
object_link_wrapper = _('Question {val}')
|
||||||
|
object_link_viewname = 'control:event.items.questions.show'
|
||||||
|
object_link_argname = 'question'
|
||||||
|
|
||||||
|
|
||||||
|
class TaxRuleLogEntryType(EventLogEntryType):
|
||||||
|
object_link_wrapper = _('Tax rule {val}')
|
||||||
|
object_link_viewname = 'control:event.settings.tax.edit'
|
||||||
|
object_link_argname = 'rule'
|
||||||
|
|
||||||
|
|
||||||
|
class NoOpShredderMixin:
|
||||||
|
def shred_pii(self, logentry):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ClearDataShredderMixin:
|
||||||
|
def shred_pii(self, logentry):
|
||||||
|
logentry.data = None
|
||||||
@@ -34,17 +34,16 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from collections import defaultdict
|
|
||||||
|
|
||||||
from django.contrib.contenttypes.fields import GenericForeignKey
|
from django.contrib.contenttypes.fields import GenericForeignKey
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
from django.utils.html import escape
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.utils.translation import gettext_lazy as _, pgettext_lazy
|
|
||||||
|
|
||||||
from pretix.base.signals import logentry_object_link, EventPluginRegistry, is_app_active
|
from pretix.base.logentrytypes import log_entry_types
|
||||||
|
from pretix.base.signals import logentry_object_link, is_app_active
|
||||||
|
|
||||||
|
|
||||||
class VisibleOnlyManager(models.Manager):
|
class VisibleOnlyManager(models.Manager):
|
||||||
@@ -202,134 +201,3 @@ class LogEntry(models.Model):
|
|||||||
to_wh = [o.id for o in objects if o.webhook_type]
|
to_wh = [o.id for o in objects if o.webhook_type]
|
||||||
if to_wh:
|
if to_wh:
|
||||||
notify_webhooks.apply_async(args=(to_wh,))
|
notify_webhooks.apply_async(args=(to_wh,))
|
||||||
|
|
||||||
|
|
||||||
class LogEntryTypeRegistry(EventPluginRegistry):
|
|
||||||
def new_from_dict(self, data):
|
|
||||||
def reg(clz):
|
|
||||||
for action_type, plain in data.items():
|
|
||||||
self.register(clz(action_type=action_type, plain=plain))
|
|
||||||
return reg
|
|
||||||
|
|
||||||
|
|
||||||
log_entry_types = LogEntryTypeRegistry({'action_type': lambda o: getattr(o, 'action_type')})
|
|
||||||
|
|
||||||
|
|
||||||
class LogEntryType:
|
|
||||||
def __init__(self, action_type=None, plain=None):
|
|
||||||
assert self.__module__ != LogEntryType.__module__ # must not instantiate base classes, only derived ones
|
|
||||||
if action_type: self.action_type = action_type
|
|
||||||
if plain: self.plain = plain
|
|
||||||
|
|
||||||
def display(self, logentry):
|
|
||||||
if hasattr(self, 'plain'):
|
|
||||||
plain = str(self.plain)
|
|
||||||
if '{' in plain:
|
|
||||||
data = defaultdict(lambda: '?', logentry.parsed_data)
|
|
||||||
return plain.format_map(data)
|
|
||||||
else:
|
|
||||||
return plain
|
|
||||||
|
|
||||||
def get_object_link_info(self, logentry) -> dict:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def get_object_link(self, logentry):
|
|
||||||
a_map = self.get_object_link_info(logentry)
|
|
||||||
return make_link(a_map, self.object_link_wrapper)
|
|
||||||
|
|
||||||
object_link_wrapper = '{val}'
|
|
||||||
|
|
||||||
def shred_pii(self, logentry):
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
|
|
||||||
class EventLogEntryType(LogEntryType):
|
|
||||||
def get_object_link_info(self, logentry) -> dict:
|
|
||||||
if hasattr(self, 'object_link_viewname') and hasattr(self, 'object_link_argname') and logentry.content_object:
|
|
||||||
return {
|
|
||||||
'href': reverse(self.object_link_viewname, kwargs={
|
|
||||||
'event': logentry.event.slug,
|
|
||||||
'organizer': logentry.event.organizer.slug,
|
|
||||||
self.object_link_argname: self.object_link_argvalue(logentry.content_object),
|
|
||||||
}),
|
|
||||||
'val': escape(self.object_link_display_name(logentry.content_object)),
|
|
||||||
}
|
|
||||||
|
|
||||||
def object_link_argvalue(self, content_object):
|
|
||||||
return content_object.id
|
|
||||||
|
|
||||||
def object_link_display_name(self, content_object):
|
|
||||||
return str(content_object)
|
|
||||||
|
|
||||||
|
|
||||||
class OrderLogEntryType(EventLogEntryType):
|
|
||||||
object_link_wrapper = _('Order {val}')
|
|
||||||
object_link_viewname = 'control:event.order'
|
|
||||||
object_link_argname = 'code'
|
|
||||||
|
|
||||||
def object_link_argvalue(self, order):
|
|
||||||
return order.code
|
|
||||||
|
|
||||||
def object_link_display_name(self, order):
|
|
||||||
return order.code
|
|
||||||
|
|
||||||
|
|
||||||
class VoucherLogEntryType(EventLogEntryType):
|
|
||||||
object_link_wrapper = _('Voucher {val}…')
|
|
||||||
object_link_viewname = 'control:event.voucher'
|
|
||||||
object_link_argname = 'voucher'
|
|
||||||
|
|
||||||
def object_link_display_name(self, order):
|
|
||||||
return order.code[:6]
|
|
||||||
|
|
||||||
|
|
||||||
class ItemLogEntryType(EventLogEntryType):
|
|
||||||
object_link_wrapper = _('Product {val}')
|
|
||||||
object_link_viewname = 'control:event.item'
|
|
||||||
object_link_argname = 'item'
|
|
||||||
|
|
||||||
|
|
||||||
class SubEventLogEntryType(EventLogEntryType):
|
|
||||||
object_link_wrapper = pgettext_lazy('subevent', 'Date {val}')
|
|
||||||
object_link_viewname = 'control:event.subevent'
|
|
||||||
object_link_argname = 'subevent'
|
|
||||||
|
|
||||||
|
|
||||||
class QuotaLogEntryType(EventLogEntryType):
|
|
||||||
object_link_wrapper = _('Quota {val}')
|
|
||||||
object_link_viewname = 'control:event.items.quotas.show'
|
|
||||||
object_link_argname = 'quota'
|
|
||||||
|
|
||||||
|
|
||||||
class DiscountLogEntryType(EventLogEntryType):
|
|
||||||
object_link_wrapper = _('Discount {val}')
|
|
||||||
object_link_viewname = 'control:event.items.discounts.edit'
|
|
||||||
object_link_argname = 'discount'
|
|
||||||
|
|
||||||
|
|
||||||
class ItemCategoryLogEntryType(EventLogEntryType):
|
|
||||||
object_link_wrapper = _('Category {val}')
|
|
||||||
object_link_viewname = 'control:event.items.categories.edit'
|
|
||||||
object_link_argname = 'category'
|
|
||||||
|
|
||||||
|
|
||||||
class QuestionLogEntryType(EventLogEntryType):
|
|
||||||
object_link_wrapper = _('Question {val}')
|
|
||||||
object_link_viewname = 'control:event.items.questions.show'
|
|
||||||
object_link_argname = 'question'
|
|
||||||
|
|
||||||
|
|
||||||
class TaxRuleLogEntryType(EventLogEntryType):
|
|
||||||
object_link_wrapper = _('Tax rule {val}')
|
|
||||||
object_link_viewname = 'control:event.settings.tax.edit'
|
|
||||||
object_link_argname = 'rule'
|
|
||||||
|
|
||||||
|
|
||||||
class NoOpShredderMixin:
|
|
||||||
def shred_pii(self, logentry):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class ClearDataShredderMixin:
|
|
||||||
def shred_pii(self, logentry):
|
|
||||||
logentry.data = None
|
|
||||||
|
|||||||
@@ -51,12 +51,9 @@ from pretix.base.models import (
|
|||||||
Checkin, CheckinList, Event, ItemVariation, LogEntry, OrderPosition,
|
Checkin, CheckinList, Event, ItemVariation, LogEntry, OrderPosition,
|
||||||
TaxRule,
|
TaxRule,
|
||||||
)
|
)
|
||||||
from pretix.base.models.log import (
|
from pretix.base.logentrytypes import log_entry_types, LogEntryType, EventLogEntryType, OrderLogEntryType, \
|
||||||
DiscountLogEntryType, EventLogEntryType, ItemCategoryLogEntryType,
|
VoucherLogEntryType, ItemLogEntryType, QuotaLogEntryType, DiscountLogEntryType, ItemCategoryLogEntryType, \
|
||||||
ItemLogEntryType, LogEntryType, OrderLogEntryType, QuestionLogEntryType,
|
QuestionLogEntryType, TaxRuleLogEntryType
|
||||||
QuotaLogEntryType, TaxRuleLogEntryType, VoucherLogEntryType,
|
|
||||||
log_entry_types,
|
|
||||||
)
|
|
||||||
from pretix.base.signals import logentry_display, orderposition_blocked_display, app_cache
|
from pretix.base.signals import logentry_display, orderposition_blocked_display, app_cache
|
||||||
from pretix.base.templatetags.money import money_filter
|
from pretix.base.templatetags.money import money_filter
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ from django.urls import resolve, reverse
|
|||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from pretix.base.models import Event, Order
|
from pretix.base.models import Event, Order
|
||||||
from pretix.base.models.log import EventLogEntryType, log_entry_types
|
from pretix.base.logentrytypes import log_entry_types, EventLogEntryType
|
||||||
from pretix.base.signals import (
|
from pretix.base.signals import (
|
||||||
event_copy_data, item_copy_data, register_data_exporters,
|
event_copy_data, item_copy_data, register_data_exporters,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -25,11 +25,10 @@ from django.urls import resolve, reverse
|
|||||||
from django.utils.translation import gettext_lazy as _, gettext_noop
|
from django.utils.translation import gettext_lazy as _, gettext_noop
|
||||||
from i18nfield.strings import LazyI18nString
|
from i18nfield.strings import LazyI18nString
|
||||||
|
|
||||||
from pretix.base.models.log import OrderLogEntryType, log_entry_types
|
from ...base.logentrytypes import log_entry_types, OrderLogEntryType, ClearDataShredderMixin
|
||||||
from pretix.base.signals import register_payment_providers
|
from pretix.base.signals import register_payment_providers
|
||||||
from pretix.control.signals import html_head, nav_event, nav_organizer
|
from pretix.control.signals import html_head, nav_event, nav_organizer
|
||||||
|
|
||||||
from ...base.models.log import ClearDataShredderMixin
|
|
||||||
from ...base.settings import settings_hierarkey
|
from ...base.settings import settings_hierarkey
|
||||||
from .payment import BankTransfer
|
from .payment import BankTransfer
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ from django.utils.translation import gettext_lazy as _, pgettext_lazy
|
|||||||
|
|
||||||
from pretix.base.forms import SecretKeySettingsField
|
from pretix.base.forms import SecretKeySettingsField
|
||||||
from pretix.base.middleware import _merge_csp, _parse_csp, _render_csp
|
from pretix.base.middleware import _merge_csp, _parse_csp, _render_csp
|
||||||
from pretix.base.models.log import EventLogEntryType, log_entry_types
|
from pretix.base.logentrytypes import log_entry_types, EventLogEntryType
|
||||||
from pretix.base.settings import settings_hierarkey
|
from pretix.base.settings import settings_hierarkey
|
||||||
from pretix.base.signals import (
|
from pretix.base.signals import (
|
||||||
register_global_settings, register_payment_providers,
|
register_global_settings, register_payment_providers,
|
||||||
|
|||||||
@@ -47,9 +47,7 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
from django_scopes import scope, scopes_disabled
|
from django_scopes import scope, scopes_disabled
|
||||||
|
|
||||||
from pretix.base.models import SubEvent
|
from pretix.base.models import SubEvent
|
||||||
from pretix.base.models.log import (
|
from pretix.base.logentrytypes import log_entry_types, EventLogEntryType, OrderLogEntryType
|
||||||
EventLogEntryType, OrderLogEntryType, log_entry_types,
|
|
||||||
)
|
|
||||||
from pretix.base.signals import (
|
from pretix.base.signals import (
|
||||||
EventPluginSignal, event_copy_data, periodic_task,
|
EventPluginSignal, event_copy_data, periodic_task,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user