diff --git a/HISTORY.rst b/HISTORY.rst index 0031a0e265..f5352e518f 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -52,6 +52,7 @@ Next (2018-XX-XX) - Unify the way to gather the project's metadata. Use mayan.__XX__ and a new common tag named {% project_information '' %} - Return to the same source view after uploading a document. - Add new WizardStep class to decouple the wizard step configuration. +- Add support for deregister upload wizard steps. 2.8 (2018-02-27) ================ diff --git a/mayan/apps/sources/wizards.py b/mayan/apps/sources/wizards.py index 48ef207f79..88eeb4ec7c 100644 --- a/mayan/apps/sources/wizards.py +++ b/mayan/apps/sources/wizards.py @@ -15,6 +15,7 @@ from documents.forms import DocumentTypeSelectForm class WizardStep(object): _registry = {} + _deregistry = {} @classmethod def done(cls, wizard): @@ -32,11 +33,9 @@ class WizardStep(object): @classmethod def get_choices(cls, attribute_name): - return sorted( - [ - (step.name, getattr(step, attribute_name)) for step in cls.get_all() - ] - ) + return [ + (step.name, getattr(step, attribute_name)) for step in cls.get_all() + ] @classmethod def get_form_initial(cls, wizard): @@ -55,8 +54,28 @@ class WizardStep(object): @classmethod def register(cls, step): + if step in cls._deregistry: + # This step has been marked for reregistration before it was + # registered + return + + if step.name in cls._registry: + raise Exception('A step with this name already exists: %s' % step.name) + + if step.number in [reigstered_step.number for reigstered_step in cls.get_all()]: + raise Exception('A step with this number already exists: %s' % step.name) + cls._registry[step.name] = step + @classmethod + def deregister(cls, step): + try: + cls._registry.pop(step.name) + except KeyError: + cls._deregistry[step.name] = step + else: + cls._deregistry[step.name] = step + @classmethod def step_post_upload_process(cls, document, querystring=None): pass