コード例 #1
0
ファイル: test_utils.py プロジェクト: XTech2K/osf.io
 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')
コード例 #2
0
ファイル: test_utils.py プロジェクト: jeffreyliu3230/osf.io
 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')
コード例 #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}
コード例 #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
    }
コード例 #5
0
ファイル: register.py プロジェクト: cldershem/osf.io
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}