Skip to content

Commit

Permalink
Attribute sources of sounds as well
Browse files Browse the repository at this point in the history
  • Loading branch information
ffont committed Mar 11, 2024
1 parent 125b7f3 commit b564d47
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions sounds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,18 +932,27 @@ def get_license_history(self):

@cached_property
def attribution_texts(self):
return {
'plain_text': f'{self.original_filename} by {self.user.username} -- {url2absurl(reverse("short-sound-link", args=[self.id]))} -- License: {self.license.name_with_version}',
'html': f'<a href="{url2absurl(self.get_absolute_url())}">{self.original_filename}</a> by <a href="{url2absurl(reverse("account", args=[self.user.username]))}">{self.user.username}</a> | License: <a href="{ self.license.deed_url }">{self.license.name_with_version}</a>',
'json': json.dumps({
'sound_url': url2absurl(self.get_absolute_url()),
'sound_name': self.original_filename,
'author_url': url2absurl(reverse("account", args=[self.user.username])),
'author_name': self.user.username,
'license_url': self.license.deed_url,
'license_name': self.license.name_with_version,
})
}
attribution_texts = {
'plain_text': f'{self.original_filename} by {self.user.username} -- {url2absurl(reverse("short-sound-link", args=[self.id]))} -- License: {self.license.name_with_version}',
'html': f'<a href="{url2absurl(self.get_absolute_url())}">{self.original_filename}</a> by <a href="{url2absurl(reverse("account", args=[self.user.username]))}">{self.user.username}</a> | License: <a href="{ self.license.deed_url }">{self.license.name_with_version}</a>',
'json': json.dumps({
'sound_url': url2absurl(self.get_absolute_url()),
'sound_name': self.original_filename,
'author_url': url2absurl(reverse("account", args=[self.user.username])),
'author_name': self.user.username,
'license_url': self.license.deed_url,
'license_name': self.license.name_with_version,
})
}
if not self.sources.exists():
return attribution_texts
else:
sources_attribution_texts = [s.attribution_texts for s in self.sources.all()]
attribution_texts['plain_text'] = "\n\n".join([attribution_texts['plain_text']] + [st['plain_text'] for st in sources_attribution_texts])
attribution_texts['html'] = "<br>\n".join([attribution_texts['html']] + [st['html'] for st in sources_attribution_texts])
attribution_texts['json'] = json.dumps([json.loads(attribution_texts['json'])] + [json.loads(st['json']) for st in sources_attribution_texts])
return attribution_texts


def get_sound_tags(self, limit=None):
"""
Expand Down

0 comments on commit b564d47

Please sign in to comment.