Пример #1
0
class UploadFilter(audio_filters.IncludeChannelsFilterSet):
    library = filters.CharFilter("library__uuid")
    channel = filters.CharFilter("library__channel__uuid")
    track = filters.UUIDFilter("track__uuid")
    track_artist = filters.UUIDFilter("track__artist__uuid")
    album_artist = filters.UUIDFilter("track__album__artist__uuid")
    library = filters.UUIDFilter("library__uuid")
    playable = filters.BooleanFilter(field_name="_", method="filter_playable")
    scope = common_filters.ActorScopeFilter(
        actor_field="library__actor",
        distinct=True,
        library_field="library",
    )
    import_status = common_filters.MultipleQueryFilter(coerce=str)
    q = fields.SmartSearchFilter(config=search.SearchConfig(
        search_fields={
            "track_artist": {
                "to": "track__artist__name"
            },
            "album_artist": {
                "to": "track__album__artist__name"
            },
            "album": {
                "to": "track__album__title"
            },
            "title": {
                "to": "track__title"
            },
        },
        filter_fields={
            "artist": {
                "to": "track__artist__name__iexact"
            },
            "mimetype": {
                "to": "mimetype"
            },
            "album": {
                "to": "track__album__title__iexact"
            },
            "title": {
                "to": "track__title__iexact"
            },
            "status": {
                "to": "import_status"
            },
        },
    ))

    class Meta:
        model = models.Upload
        fields = [
            "import_status",
            "mimetype",
            "import_reference",
        ]
        include_channels_field = "track__artist__channel"

    def filter_playable(self, queryset, name, value):
        actor = utils.get_actor_from_request(self.request)
        return queryset.playable_by(actor, value)
Пример #2
0
class TrackFilter(
        RelatedFilterSet,
        ChannelFilterSet,
        LibraryFilterSet,
        audio_filters.IncludeChannelsFilterSet,
        moderation_filters.HiddenContentFilterSet,
):
    q = fields.SearchFilter(
        search_fields=["title", "album__title", "artist__name"],
        fts_search_fields=[
            "body_text", "artist__body_text", "album__body_text"
        ],
    )
    playable = filters.BooleanFilter(field_name="_", method="filter_playable")
    tag = TAG_FILTER
    id = common_filters.MultipleQueryFilter(coerce=int)
    scope = common_filters.ActorScopeFilter(
        actor_field="uploads__library__actor",
        library_field="uploads__library",
        distinct=True,
    )
    artist = filters.ModelChoiceFilter(field_name="_",
                                       method="filter_artist",
                                       queryset=models.Artist.objects.all())

    ordering = django_filters.OrderingFilter(fields=(
        ("creation_date", "creation_date"),
        ("title", "title"),
        ("album__title", "album__title"),
        ("album__release_date", "album__release_date"),
        ("size", "size"),
        ("position", "position"),
        ("disc_number", "disc_number"),
        ("artist__name", "artist__name"),
        ("artist__modification_date", "artist__modification_date"),
        ("?", "random"),
        ("tag_matches", "related"),
    ))

    class Meta:
        model = models.Track
        fields = {
            "title": ["exact", "iexact", "startswith", "icontains"],
            "id": ["exact"],
            "album": ["exact"],
            "license": ["exact"],
            "mbid": ["exact"],
        }
        hidden_content_fields_mapping = moderation_filters.USER_FILTER_CONFIG[
            "TRACK"]
        include_channels_field = "artist__channel"
        channel_filter_field = "track"
        library_filter_field = "track"

    def filter_playable(self, queryset, name, value):
        actor = utils.get_actor_from_request(self.request)
        return queryset.playable_by(actor, value).distinct()

    def filter_artist(self, queryset, name, value):
        return queryset.filter(Q(artist=value) | Q(album__artist=value))
Пример #3
0
class TrackFilter(
    ChannelFilterSet,
    LibraryFilterSet,
    audio_filters.IncludeChannelsFilterSet,
    moderation_filters.HiddenContentFilterSet,
):
    q = fields.SearchFilter(
        search_fields=["title", "album__title", "artist__name"],
        fts_search_fields=["body_text", "artist__body_text", "album__body_text"],
    )
    playable = filters.BooleanFilter(field_name="_", method="filter_playable")
    tag = TAG_FILTER
    id = common_filters.MultipleQueryFilter(coerce=int)
    scope = common_filters.ActorScopeFilter(
        actor_field="uploads__library__actor", distinct=True
    )

    class Meta:
        model = models.Track
        fields = {
            "title": ["exact", "iexact", "startswith", "icontains"],
            "playable": ["exact"],
            "id": ["exact"],
            "artist": ["exact"],
            "album": ["exact"],
            "license": ["exact"],
            "scope": ["exact"],
            "mbid": ["exact"],
        }
        hidden_content_fields_mapping = moderation_filters.USER_FILTER_CONFIG["TRACK"]
        include_channels_field = "artist__channel"
        channel_filter_field = "track"
        library_filter_field = "track"

    def filter_playable(self, queryset, name, value):
        actor = utils.get_actor_from_request(self.request)
        return queryset.playable_by(actor, value).distinct()
Пример #4
0
from funkwhale_api.common import filters as common_filters
from funkwhale_api.common import search
from funkwhale_api.moderation import filters as moderation_filters

from . import models
from . import utils


def filter_tags(queryset, name, value):
    non_empty_tags = [v.lower() for v in value if v]
    for tag in non_empty_tags:
        queryset = queryset.filter(tagged_items__tag__name=tag).distinct()
    return queryset


TAG_FILTER = common_filters.MultipleQueryFilter(method=filter_tags)


class ChannelFilterSet(filters.FilterSet):

    channel = filters.CharFilter(field_name="_", method="filter_channel")

    def filter_channel(self, queryset, name, value):
        if not value:
            return queryset

        channel = (
            audio_models.Channel.objects.filter(uuid=value)
            .select_related("library")
            .first()
        )