Пример #1
0
def test_local_qs(factory_name, fids, kwargs, expected_indexes, factories, settings):
    settings.FEDERATION_HOSTNAME = "local.domain"
    objs = [factories[factory_name](fid=fid) for fid in fids]

    qs = objs[0].__class__.objects.all().order_by("id")
    result = utils.local_qs(qs, **kwargs)

    expected_objs = [obj for i, obj in enumerate(objs) if i in expected_indexes]
    assert list(result) == expected_objs
Пример #2
0
def artists_set_tags_from_tracks(ids=None, dry_run=False):
    qs = models.Artist.objects.filter(tagged_items__isnull=True).order_by("id")
    qs = federation_utils.local_qs(qs)
    qs = qs.values_list("id", flat=True)
    if ids is not None:
        qs = qs.filter(pk__in=ids)
    data = tags_tasks.get_tags_from_foreign_key(
        ids=qs,
        foreign_key_model=models.Track,
        foreign_key_attr="artist",
    )
    logger.info("Found automatic tags for %s artists…", len(data))
    if dry_run:
        logger.info("Running in dry-run mode, not commiting")
        return

    tags_tasks.add_tags_batch(
        data,
        model=models.Artist,
    )
    return data