Ejemplo n.º 1
0
 def test_conjunct(self):
     words = []
     assert_equal(conjunct(words), '')
     words = ['a']
     assert_equal(conjunct(words), 'a')
     words = ['a', 'b']
     assert_equal(conjunct(words), 'a and b')
     words = ['a', 'b', 'c']
     assert_equal(conjunct(words), 'a, b, and c')
     assert_equal(conjunct(words, conj='or'), 'a, b, or c')
Ejemplo n.º 2
0
 def test_conjunct(self):
     words = []
     assert_equal(conjunct(words), '')
     words = ['a']
     assert_equal(conjunct(words), 'a')
     words = ['a', 'b']
     assert_equal(conjunct(words), 'a and b')
     words = ['a', 'b', 'c']
     assert_equal(conjunct(words), 'a, b, and c')
     assert_equal(conjunct(words, conj='or'), 'a, b, or c')
Ejemplo n.º 3
0
def project_before_register(auth, node, **kwargs):
    """Returns prompt informing user that addons, if any, won't be registered."""
    # TODO: Avoid generating HTML code in Python; all HTML should be in display layer
    messages = {
        'full': {
            'addons':
            set(),
            'message':
            'The content and version history of <strong>{0}</strong> will be copied to the registration.',
        },
        'partial': {
            'addons':
            set(),
            'message':
            'The current version of the content in <strong>{0}</strong> will be copied to the registration, but version history will be lost.'
        },
        'none': {
            'addons':
            set(),
            'message':
            'The contents of <strong>{0}</strong> cannot be registered at this time,  and will not be included as part of this registration.',
        },
    }
    errors = {}

    addon_set = [
        n.get_addons() for n in itertools.chain(
            [node], node.get_descendants_recursive(primary_only=True))
    ]
    for addon in itertools.chain(*addon_set):
        if not addon.complete:
            continue
        archive_errors = getattr(addon, 'archive_errors', None)
        error = None
        if archive_errors:
            error = archive_errors()
            if error:
                errors[addon.config.short_name] = error
                continue
        name = addon.config.short_name
        if name in settings.ADDONS_ARCHIVABLE:
            messages[settings.ADDONS_ARCHIVABLE[name]]['addons'].add(
                addon.config.full_name)
        else:
            messages['none']['addons'].add(addon.config.full_name)
    error_messages = list(errors.values())

    prompts = [
        m['message'].format(util.conjunct(m['addons']))
        for m in messages.values() if m['addons']
    ]

    if node.has_pointers_recursive:
        prompts.append(
            language.BEFORE_REGISTER_HAS_POINTERS.format(
                category=node.project_or_component))

    return {'prompts': prompts, 'errors': error_messages}
Ejemplo n.º 4
0
def project_before_register(auth, node, **kwargs):
    """Returns prompt informing user that addons, if any, won't be registered."""
    # TODO: Avoid generating HTML code in Python; all HTML should be in display layer
    messages = {
        'full': {
            'addons': set(),
            'message': 'The content and version history of <strong>{0}</strong> will be copied to the registration.',
        },
        'partial': {
            'addons': set(),
            'message': 'The current version of the content in <strong>{0}</strong> will be copied to the registration, but version history will be lost.'
        },
        'none': {
            'addons': set(),
            'message': 'The contents of <strong>{0}</strong> cannot be registered at this time,  and will not be included as part of this registration.',
        },
    }
    errors = {}

    addon_set = [n.get_addons() for n in itertools.chain([node], node.get_descendants_recursive(primary_only=True))]
    for addon in itertools.chain(*addon_set):
        if not addon.complete:
            continue
        archive_errors = getattr(addon, 'archive_errors', None)
        error = None
        if archive_errors:
            error = archive_errors()
            if error:
                errors[addon.config.short_name] = error
                continue
        name = addon.config.short_name
        if name in settings.ADDONS_ARCHIVABLE:
            messages[settings.ADDONS_ARCHIVABLE[name]]['addons'].add(addon.config.full_name)
        else:
            messages['none']['addons'].add(addon.config.full_name)
    error_messages = errors.values()

    prompts = [
        m['message'].format(util.conjunct(m['addons']))
        for m in messages.values() if m['addons']
    ]

    if node.has_pointers_recursive:
        prompts.append(
            language.BEFORE_REGISTER_HAS_POINTERS.format(
                category=node.project_or_component
            )
        )

    return {
        'prompts': prompts,
        'errors': error_messages
    }
Ejemplo n.º 5
0
def project_before_register(auth, node, **kwargs):
    """Returns prompt informing user that addons, if any, won't be registered."""

    messages = {
        "full": {
            "addons": set(),
            "message": "The content and version history of <strong>{0}</strong> will be copied to the registration.",
        },
        "partial": {
            "addons": set(),
            "message": "The current version of the content in <strong>{0}</strong> will be copied to the registration, but version history will be lost.",
        },
        "none": {
            "addons": set(),
            "message": "The contents of <strong>{0}</strong> cannot be registered at this time,  and will not be included as part of this registration.",
        },
    }
    errors = []

    addon_set = [n.get_addons() for n in itertools.chain([node], node.get_descendants_recursive(lambda n: n.primary))]
    for addon in itertools.chain(*addon_set):
        if not addon.complete:
            continue
        archive_errors = getattr(addon, "archive_errors", None)
        error = None
        if archive_errors:
            error = archive_errors()
            if error:
                errors.append(error)
                continue
        name = addon.config.short_name
        if name in settings.ADDONS_ARCHIVABLE:
            messages[settings.ADDONS_ARCHIVABLE[name]]["addons"].add(addon.config.full_name)
        else:
            messages["none"]["addons"].add(addon.config.full_name)
    errors = [e for e in errors if e]

    prompts = [m["message"].format(util.conjunct(m["addons"])) for m in messages.values() if m["addons"]]

    if node.has_pointers_recursive:
        prompts.append(language.BEFORE_REGISTER_HAS_POINTERS.format(category=node.project_or_component))

    return {"prompts": prompts, "errors": errors}