Source code for oioioi.contests.attachment_registration

import sys

from oioioi.base.menu import OrderedRegistry


[docs]class AttachmentRegistry(object): """Maintains a collection of functions that return attachments for 'Downloads' view. """ def __init__(self): self._registry = OrderedRegistry()
[docs] def register(self, attachment_generator=None, order=sys.maxsize): """Register function generating attachments. :Parameters: Function that takes elements from `**kwargs` as arguments and returns dictionary containing following keys: `category`, `name`, `description`, `link`, `pub_date`. """ if attachment_generator is not None: self._registry.register(attachment_generator, order)
[docs] def to_list(self, **kwargs): attachments = [] for idx, gen in enumerate(self._registry): attachments.extend(gen(**kwargs)) return attachments
# The default attachment registry
[docs]attachment_registry = AttachmentRegistry()
[docs]attachment_registry_problemset = AttachmentRegistry()