コード例 #1
0
ファイル: tests.py プロジェクト: piql/archivematica
    def test_get_revision_descendants(self):
        cmd1 = IDCommand.objects.create(
            uuid='37f3bd7c-bb24-4899-b7c4-785ff1c764ac')
        cmd2 = IDCommand(description='Foobar')
        cmd2.save(replacing=cmd1)

        descendants = get_revision_descendants(IDCommand, cmd1.uuid, [123])
        self.assertEqual(descendants, [123, cmd2])

        with self.assertRaises(IDCommand.DoesNotExist):
            descendants = get_revision_descendants(IDCommand, '12345', [])
コード例 #2
0
ファイル: views.py プロジェクト: piql/archivematica
def revision_list(request, entity_name, uuid):
    # get model using entity name
    available_models = apps.get_models()
    model = None
    for model in available_models:
        if model._meta.db_table == 'fpr_' + entity_name:
            break
    if model is None:
        raise Http404

    # human-readable names
    revision_type = entity_name
    human_readable_names = {
        'formatversion': _('Format version'),
        'idtoolconfig': _('Identification tool configuration'),
        'idrule': _('Identification rule'),
        'idcommand': _('Identification command'),
        'fpcommand': _('Format policy command'),
        'fprule': _('Format policy rule')
    }
    if entity_name in human_readable_names:
        revision_type = human_readable_names[entity_name]

    # restrict to models that are intended to have revisions
    try:
        getattr(model, 'replaces')

        # get specific revision's data and augment with detail URL
        revision = model.objects.get(uuid=uuid)
        _augment_revisions_with_detail_url(request, entity_name, model,
                                           [revision])

        # get revision ancestor data and augment with detail URLs
        ancestors = utils.get_revision_ancestors(model, uuid, [])
        _augment_revisions_with_detail_url(request, entity_name, model,
                                           ancestors)

        # get revision descendant data and augment with detail URLs
        descendants = utils.get_revision_descendants(model, uuid, [])
        _augment_revisions_with_detail_url(request, entity_name, model,
                                           descendants)
        descendants.reverse()

        return render(request, 'fpr/revisions/list.html', context(locals()))
    except AttributeError:
        raise Http404
コード例 #3
0
def revision_list(request, entity_name, uuid):
    # get model using entity name
    try:
        model = utils.get_fpr_models()[entity_name]
    except KeyError:
        raise Http404

    # human-readable names
    revision_type = entity_name
    human_readable_names = {
        "formatversion": _("Format version"),
        "idtoolconfig": _("Identification tool configuration"),
        "idrule": _("Identification rule"),
        "idcommand": _("Identification command"),
        "fpcommand": _("Format policy command"),
        "fprule": _("Format policy rule"),
    }
    if entity_name in human_readable_names:
        revision_type = human_readable_names[entity_name]

    # restrict to models that are intended to have revisions
    try:
        getattr(model, "replaces")

        # get specific revision's data and augment with detail URL
        revision = model.objects.get(uuid=uuid)
        _augment_revisions_with_detail_url(request, entity_name, model, [revision])

        # get revision ancestor data and augment with detail URLs
        ancestors = utils.get_revision_ancestors(model, uuid, [])
        _augment_revisions_with_detail_url(request, entity_name, model, ancestors)

        # get revision descendant data and augment with detail URLs
        descendants = utils.get_revision_descendants(model, uuid, [])
        _augment_revisions_with_detail_url(request, entity_name, model, descendants)
        descendants.reverse()

        return render(request, "fpr/revisions/list.html", context(locals()))
    except AttributeError:
        raise Http404