forked from CGM_Public/pretix_original
Apply suggestions from code review
Co-authored-by: Raphael Michel <michel@rami.io>
This commit is contained in:
@@ -55,7 +55,7 @@ def make_link(a_map, wrapper, is_active=True, event=None, plugin_name=None):
|
||||
class LogEntryTypeRegistry(EventPluginRegistry):
|
||||
def new_from_dict(self, data):
|
||||
"""
|
||||
Register multiple instance of a LogEntryType class with different action_type
|
||||
Register multiple instance of a `LogEntryType` class with different `action_type`
|
||||
and plain text strings, as given by the items of the specified data dictionary.
|
||||
|
||||
This method is designed to be used as a decorator as follows:
|
||||
@@ -142,7 +142,7 @@ class LogEntryType:
|
||||
|
||||
class EventLogEntryType(LogEntryType):
|
||||
"""
|
||||
Base class for any LogEntry type whose content_object is either an `Event` itself or belongs to a specific `Event`.
|
||||
Base class for any `LogEntry` type whose `content_object` is either an `Event` itself or belongs to a specific `Event`.
|
||||
"""
|
||||
|
||||
def get_object_link_info(self, logentry) -> dict:
|
||||
@@ -183,7 +183,9 @@ class VoucherLogEntryType(EventLogEntryType):
|
||||
object_link_argname = 'voucher'
|
||||
|
||||
def object_link_display_name(self, voucher):
|
||||
return voucher.code[:6]
|
||||
if len(voucher.code) > 6:
|
||||
return voucher.code[:6] + "…"
|
||||
return voucher.code
|
||||
|
||||
|
||||
class ItemLogEntryType(EventLogEntryType):
|
||||
|
||||
@@ -254,7 +254,7 @@ class Registry:
|
||||
|
||||
def __init__(self, keys):
|
||||
"""
|
||||
:param keys: dictionary {key: accessor_function}
|
||||
:param keys: Dictionary with `{key: accessor_function}`
|
||||
When a new entry is registered, all accessor functions are called with the new entry as parameter.
|
||||
Their return value is stored as the metadata value for that key.
|
||||
"""
|
||||
@@ -281,10 +281,12 @@ class Registry:
|
||||
for key, value in meta.items():
|
||||
self.by_key[key][value] = tup
|
||||
self.registered_entries.append(tup)
|
||||
if len(objs) == 1:
|
||||
return objs[0]
|
||||
|
||||
def new(self, *args, **kwargs):
|
||||
"""
|
||||
Instantiate the decorated class with the given *args and **kwargs, and register the instance in this registry.
|
||||
Instantiate the decorated class with the given `*args` and `**kwargs`, and register the instance in this registry.
|
||||
May be used multiple times.
|
||||
|
||||
.. code-block:: python
|
||||
@@ -306,10 +308,11 @@ class Registry:
|
||||
return self.by_key.get(key).get(value, (None, None))
|
||||
|
||||
def filter(self, **kwargs):
|
||||
return ((entry, meta)
|
||||
for entry, meta in self.registered_entries
|
||||
if all(value == meta[key] for key, value in kwargs.items())
|
||||
)
|
||||
return (
|
||||
(entry, meta)
|
||||
for entry, meta in self.registered_entries
|
||||
if all(value == meta[key] for key, value in kwargs.items())
|
||||
)
|
||||
|
||||
|
||||
class EventPluginRegistry(Registry):
|
||||
|
||||
Reference in New Issue
Block a user