filter content and various updates
This commit is contained in:
parent
0b9dbb4e50
commit
baf876b230
|
@ -983,8 +983,8 @@ CELERY_BEAT_SCHEDULE = {
|
|||
"schedule": crontab(day_of_month="2", minute="30", hour="3"),
|
||||
"options": {"expires": 60 * 60 * 24},
|
||||
},
|
||||
"music.wikidata_far_righ_artists": {
|
||||
"task": "music.wikidata_far_righ_artists",
|
||||
"music.wikidata_far_right_artists": {
|
||||
"task": "music.wikidata_far_right_artists",
|
||||
"schedule": crontab(day_of_month="3", minute="30", hour="3"),
|
||||
"options": {"expires": 60 * 60 * 24},
|
||||
},
|
||||
|
|
|
@ -679,9 +679,6 @@ def inbox_delete_favorite(payload, context):
|
|||
favorite.delete()
|
||||
|
||||
|
||||
# to do : test listening routes and broadcast
|
||||
|
||||
|
||||
@outbox.register({"type": "Listen", "object.type": "Track"})
|
||||
def outbox_create_listening(context):
|
||||
track = context["track"]
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
from django.core.cache import cache
|
||||
from django.db.models import Q
|
||||
from django_filters import rest_framework as filters
|
||||
|
||||
from funkwhale_api.music.models import Artist
|
||||
|
||||
USER_FILTER_CONFIG = {
|
||||
"ARTIST": {"target_artist": ["pk"]},
|
||||
"CHANNEL": {"target_artist": ["artist__pk"]},
|
||||
|
@ -28,9 +31,18 @@ USER_FILTER_CONFIG = {
|
|||
|
||||
def get_filtered_content_query(config, user):
|
||||
final_query = None
|
||||
cache_key = "far_right_artists"
|
||||
far_right_artists_ids = cache.get(cache_key)
|
||||
if far_right_artists_ids is None:
|
||||
far_right_artists_ids = list(
|
||||
Artist.objects.filter(far_right_isnull=False).values_list("pk", flat=True)
|
||||
)
|
||||
cache.set(cache_key, far_right_artists_ids, timeout=3600)
|
||||
|
||||
for filter_field, model_fields in config.items():
|
||||
query = None
|
||||
ids = user.content_filters.values_list(filter_field, flat=True)
|
||||
ids.append(far_right_artists_ids)
|
||||
for model_field in model_fields:
|
||||
q = Q(**{f"{model_field}__in": ids})
|
||||
if query:
|
||||
|
|
|
@ -5,7 +5,7 @@ from funkwhale_api.music import wikidata
|
|||
|
||||
class Command(BaseCommand):
|
||||
help = """Get the list of far right artists from wikidata and save it into db.
|
||||
Display missing MBID and missing english labels.
|
||||
Display missing MBID and missing labels.
|
||||
Be aware this is querying wikidata you could be rate limited.
|
||||
"""
|
||||
|
||||
|
|
|
@ -247,6 +247,7 @@ class Artist(APIModelMixin):
|
|||
)
|
||||
modification_date = models.DateTimeField(default=timezone.now, db_index=True)
|
||||
api = musicbrainz.api.artists
|
||||
# a wikidata object reference if the artist is known to be far right
|
||||
far_right = models.CharField(max_length=100, null=True, blank=True)
|
||||
objects = ArtistQuerySet.as_manager()
|
||||
|
||||
|
|
|
@ -819,7 +819,7 @@ def get_or_create_artist_from_ac(ac_data, attributed_to, from_activity_id):
|
|||
if artist.far_right:
|
||||
raise FarRightError(
|
||||
code="Far right artist detected",
|
||||
detail=f"The artist name has been matched with this wikidata entity \
|
||||
detail=f"The artist has been matched with this wikidata entity \
|
||||
{artist.far_right}. This artist will not be saved. No pasaran. \
|
||||
You can checkout our coc at https://www.funkwhale.audio/code-of-conduct/",
|
||||
)
|
||||
|
@ -1269,6 +1269,6 @@ def fs_import(
|
|||
command.handle(**options)
|
||||
|
||||
|
||||
@celery.app.task(name="music.wikidata_far_righ_artists")
|
||||
def wikidata_far_righ_artists():
|
||||
@celery.app.task(name="music.wikidata_far_right_artists")
|
||||
def wikidata_far_right_artists():
|
||||
wikidata.get_far_right_artists()
|
||||
|
|
|
@ -21,9 +21,10 @@ To find a common consensus/definition of far right ideology we will use wikidata
|
|||
- [x] a celery tasks that add far_right artists to the db, or update existing artist with the far_right attribute if the name matches. Launched every month.
|
||||
- [x] a cli tool to display the list of right wing artists that display the name, the mbid and the wikidata ref. Prompt a warning if mbid is missing so admins can add a mbid `docker compose run --rm api funkwhale-manage wikidata_far_right`
|
||||
- [x] A new artist attribute `far_right` displaying the wikidata id
|
||||
- [ ] Display an explicit api error response that explain why the artist in banned (link the funkwhale code of conduct and the artist wikidata id):
|
||||
- [x] Display an explicit api error response that explain why the artist in banned (link the funkwhale code of conduct and the artist wikidata id):
|
||||
- [x] on the import process : display an explicit error during import
|
||||
- [ ] on the federation artist serializers
|
||||
- ~~[ ] on the federation artist serializers~~ useless since we have the list locally
|
||||
- [x] a filter to avoid displaying the artists and related tracks. Done in `get_filtered_content_query`
|
||||
|
||||
workflow : querying wikidata -> create or update artist entries with the new `far_right` attribute -> filter out the artist based on the attribute and display logging info explaining why
|
||||
|
||||
|
@ -60,10 +61,4 @@ SELECT DISTINCT ?item ?itemLabel WHERE {
|
|||
#### Wikidata requirements
|
||||
|
||||
- To get the musibrainz id of the artist we use : https://www.wikidata.org/wiki/P434
|
||||
- To get the artist name we use the english label
|
||||
|
||||
#### Import
|
||||
|
||||
get_or_create_artists_credits_from_musicbrainz
|
||||
|
||||
### Frontend behavior
|
||||
- To get the artist name we use the wikidata label
|
||||
|
|
Loading…
Reference in New Issue