Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Add fields to properly save attribution information

Roland Geider11ef53cc0079
diff --git a/.gitignore b/.gitignore
index 1dd432d07..ec0326d8e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -74,3 +74,4 @@ venv-wger
/wger/i18n.dart
/wger/app_en.arb
/coverage.lcov
+/media/
diff --git a/extras/scripts/create_ingredients_from_foodfacts.py b/extras/scripts/create_ingredients_from_foodfacts.py
index ee1580862..ddd9d27b3 100644
--- a/extras/scripts/create_ingredients_from_foodfacts.py
+++ b/extras/scripts/create_ingredients_from_foodfacts.py
@@ -180,7 +180,8 @@ for product in db.products.find({'lang': {"$in": list(languages.keys())}, 'compl
continue
source_name = Source.OPEN_FOOD_FACTS.value
- source_url = f'https://world.openfoodfacts.org/api/v0/product/{code}.json'
+ source_url = f'https://world.openfoodfacts.org/api/v2/product/{code}.json'
+ authors = ', '.join(product.get('editors_tags', ['open food facts']))
ingredient_data = {
'language': languages[lang],
@@ -200,7 +201,9 @@ for product in db.products.find({'lang': {"$in": list(languages.keys())}, 'compl
'brand': brand,
'status': 2,
'license_id': 5,
- 'license_author': Source.OPEN_FOOD_FACTS.value,
+ 'license_author': authors,
+ 'license_title': name,
+ 'license_object_url': f'https://world.openfoodfacts.org/product/{code}/'
}
# Add entries as new products
diff --git a/wger/core/migrations/0016_alter_language_short_name.py b/wger/core/migrations/0016_alter_language_short_name.py
new file mode 100644
index 000000000..30656bf86
--- /dev/null
+++ b/wger/core/migrations/0016_alter_language_short_name.py
@@ -0,0 +1,23 @@
+# Generated by Django 4.2 on 2023-04-07 14:24
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('core', '0015_alter_language_short_name'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='language',
+ name='short_name',
+ field=models.CharField(
+ help_text='ISO 639-1',
+ max_length=2,
+ unique=True,
+ verbose_name='Language short name'
+ ),
+ ),
+ ]
diff --git a/wger/exercises/api/serializers.py b/wger/exercises/api/serializers.py
index eabe18d36..5391ab21a 100644
--- a/wger/exercises/api/serializers.py
+++ b/wger/exercises/api/serializers.py
@@ -1,5 +1,3 @@
-# -*- coding: utf-8 -*-
-
# This file is part of wger Workout Manager.
#
# wger Workout Manager is free software: you can redistribute it and/or modify
@@ -124,7 +122,11 @@ class ExerciseVideoSerializer(serializers.ModelSerializer):
'codec',
'codec_long',
'license',
+ 'license_title',
+ 'license_object_url',
'license_author',
+ 'license_author_url',
+ 'license_derivative_source_url',
'author_history',
]
@@ -264,7 +266,11 @@ class ExerciseTranslationBaseInfoSerializer(serializers.ModelSerializer):
"aliases",
"notes",
"license",
+ "license_title",
+ "license_object_url",
"license_author",
+ "license_author_url",
+ "license_derivative_source_url",
"author_history",
)
diff --git a/wger/exercises/migrations/0024_license_information.py b/wger/exercises/migrations/0024_license_information.py
new file mode 100644
index 000000000..ff0c6959c
--- /dev/null
+++ b/wger/exercises/migrations/0024_license_information.py
@@ -0,0 +1,412 @@
+# Generated by Django 4.2 on 2023-04-07 15:11
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ('exercises', '0023_make_uuid_unique'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='exercise',
+ name='license_author_url',
+ field=models.URLField(
+ blank=True,
+ max_length=100,
+ verbose_name='Link to author profile, if available',
+ ),
+ ),
+ migrations.AddField(
+ model_name='exercise',
+ name='license_derivative_source_url',
+ field=models.URLField(
+ blank=True,
+ help_text='Note that a derivative work is one which is not only based on a '
+ 'previous work, but which also contains sufficient new, creative '
+ 'content to entitle it to its own copyright.',
+ max_length=100,
+ verbose_name='Link to the original source, if this is a derivative work',
+ ),
+ ),
+ migrations.AddField(
+ model_name='exercise',
+ name='license_object_url',
+ field=models.URLField(
+ blank=True,
+ max_length=100,
+ verbose_name='Link to original object, if available',
+ ),
+ ),
+ migrations.AddField(
+ model_name='exercise',
+ name='license_title',
+ field=models.CharField(
+ blank=True,
+ max_length=100,
+ verbose_name='The original title of this object, if available',
+ ),
+ ),
+ migrations.AddField(
+ model_name='exercisebase',
+ name='license_author_url',
+ field=models.URLField(
+ blank=True,
+ max_length=100,
+ verbose_name='Link to author profile, if available',
+ ),
+ ),
+ migrations.AddField(
+ model_name='exercisebase',
+ name='license_derivative_source_url',
+ field=models.URLField(
+ blank=True,
+ help_text='Note that a derivative work is one which is not only based on a '
+ 'previous work, but which also contains sufficient new, creative '
+ 'content to entitle it to its own copyright.',
+ max_length=100,
+ verbose_name='Link to the original source, if this is a derivative work',
+ ),
+ ),
+ migrations.AddField(
+ model_name='exercisebase',
+ name='license_object_url',
+ field=models.URLField(
+ blank=True,
+ max_length=100,
+ verbose_name='Link to original object, if available',
+ ),
+ ),
+ migrations.AddField(
+ model_name='exercisebase',
+ name='license_title',
+ field=models.CharField(
+ blank=True,
+ max_length=100,
+ verbose_name='The original title of this object, if available',
+ ),
+ ),
+ migrations.AddField(
+ model_name='exerciseimage',
+ name='license_author_url',
+ field=models.URLField(
+ blank=True,
+ max_length=100,
+ verbose_name='Link to author profile, if available',
+ ),
+ ),
+ migrations.AddField(
+ model_name='exerciseimage',
+ name='license_derivative_source_url',
+ field=models.URLField(
+ blank=True,
+ help_text='Note that a derivative work is one which is not only based on a '
+ 'previous work, but which also contains sufficient new, creative '
+ 'content to entitle it to its own copyright.',
+ max_length=100,
+ verbose_name='Link to the original source, if this is a derivative work',
+ ),
+ ),
+ migrations.AddField(
+ model_name='exerciseimage',
+ name='license_object_url',
+ field=models.URLField(
+ blank=True,
+ max_length=100,
+ verbose_name='Link to original object, if available',
+ ),
+ ),
+ migrations.AddField(
+ model_name='exerciseimage',
+ name='license_title',
+ field=models.CharField(
+ blank=True,
+ max_length=100,
+ verbose_name='The original title of this object, if available'
+ ),
+ ),
+ migrations.AddField(
+ model_name='exercisevideo',
+ name='license_author_url',
+ field=models.URLField(
+ blank=True,
+ max_length=100,
+ verbose_name='Link to author profile, if available',
+ ),
+ ),
+ migrations.AddField(
+ model_name='exercisevideo',
+ name='license_derivative_source_url',
+ field=models.URLField(
+ blank=True,
+ help_text='Note that a derivative work is one which is not only based on a '
+ 'previous work, but which also contains sufficient new, creative '
+ 'content to entitle it to its own copyright.',
+ max_length=100,
+ verbose_name='Link to the original source, if this is a derivative work',
+ ),
+ ),
+ migrations.AddField(
+ model_name='exercisevideo',
+ name='license_object_url',
+ field=models.URLField(
+ blank=True,
+ max_length=100,
+ verbose_name='Link to original object, if available',
+ ),
+ ),
+ migrations.AddField(
+ model_name='exercisevideo',
+ name='license_title',
+ field=models.CharField(
+ blank=True,
+ max_length=100,
+ verbose_name='The original title of this object, if available',
+ ),
+ ),
+ migrations.AddField(
+ model_name='historicalexercise',
+ name='license_author_url',
+ field=models.URLField(
+ blank=True,
+ max_length=100,
+ verbose_name='Link to author profile, if available',
+ ),
+ ),
+ migrations.AddField(
+ model_name='historicalexercise',
+ name='license_derivative_source_url',
+ field=models.URLField(
+ blank=True,
+ help_text='Note that a derivative work is one which is not only based on a '
+ 'previous work, but which also contains sufficient new, creative '
+ 'content to entitle it to its own copyright.',
+ max_length=100,
+ verbose_name='Link to the original source, if this is a derivative work',
+ ),
+ ),
+ migrations.AddField(
+ model_name='historicalexercise',
+ name='license_object_url',
+ field=models.URLField(
+ blank=True,
+ max_length=100,
+ verbose_name='Link to original object, if available',
+ ),
+ ),
+ migrations.AddField(
+ model_name='historicalexercise',
+ name='license_title',
+ field=models.CharField(
+ blank=True,
+ max_length=100,
+ verbose_name='The original title of this object, if available',
+ ),
+ ),
+ migrations.AddField(
+ model_name='historicalexercisebase',
+ name='license_author_url',
+ field=models.URLField(
+ blank=True,
+ max_length=100,
+ verbose_name='Link to author profile, if available',
+ ),
+ ),
+ migrations.AddField(
+ model_name='historicalexercisebase',
+ name='license_derivative_source_url',
+ field=models.URLField(
+ blank=True,
+ help_text='Note that a derivative work is one which is not only based on a '
+ 'previous work, but which also contains sufficient new, creative '
+ 'content to entitle it to its own copyright.',
+ max_length=100,
+ verbose_name='Link to the original source, if this is a derivative work',
+ ),
+ ),
+ migrations.AddField(
+ model_name='historicalexercisebase',
+ name='license_object_url',
+ field=models.URLField(
+ blank=True,
+ max_length=100,
+ verbose_name='Link to original object, if available',
+ ),
+ ),
+ migrations.AddField(
+ model_name='historicalexercisebase',
+ name='license_title',
+ field=models.CharField(
+ blank=True,
+ max_length=100,
+ verbose_name='The original title of this object, if available',
+ ),
+ ),
+ migrations.AddField(
+ model_name='historicalexerciseimage',
+ name='license_author_url',
+ field=models.URLField(
+ blank=True,
+ max_length=100,
+ verbose_name='Link to author profile, if available',
+ ),
+ ),
+ migrations.AddField(
+ model_name='historicalexerciseimage',
+ name='license_derivative_source_url',
+ field=models.URLField(
+ blank=True,
+ help_text='Note that a derivative work is one which is not only based on a '
+ 'previous work, but which also contains sufficient new, creative '
+ 'content to entitle it to its own copyright.',
+ max_length=100,
+ verbose_name='Link to the original source, if this is a derivative work',
+ ),
+ ),
+ migrations.AddField(
+ model_name='historicalexerciseimage',
+ name='license_object_url',
+ field=models.URLField(
+ blank=True,
+ max_length=100,
+ verbose_name='Link to original object, if available',
+ ),
+ ),
+ migrations.AddField(
+ model_name='historicalexerciseimage',
+ name='license_title',
+ field=models.CharField(
+ blank=True,
+ max_length=100,
+ verbose_name='The original title of this object, if available',
+ ),
+ ),
+ migrations.AddField(
+ model_name='historicalexercisevideo',
+ name='license_author_url',
+ field=models.URLField(
+ blank=True,
+ max_length=100,
+ verbose_name='Link to author profile, if available',
+ ),
+ ),
+ migrations.AddField(
+ model_name='historicalexercisevideo',
+ name='license_derivative_source_url',
+ field=models.URLField(
+ blank=True,
+ help_text='Note that a derivative work is one which is not only based on a '
+ 'previous work, but which also contains sufficient new, creative '
+ 'content to entitle it to its own copyright.',
+ max_length=100,
+ verbose_name='Link to the original source, if this is a derivative work',
+ ),
+ ),
+ migrations.AddField(
+ model_name='historicalexercisevideo',
+ name='license_object_url',
+ field=models.URLField(
+ blank=True,
+ max_length=100,
+ verbose_name='Link to original object, if available',
+ ),
+ ),
+ migrations.AddField(
+ model_name='historicalexercisevideo',
+ name='license_title',
+ field=models.CharField(
+ blank=True,
+ max_length=100,
+ verbose_name='The original title of this object, if available',
+ ),
+ ),
+ migrations.AlterField(
+ model_name='exercise',
+ name='license_author',
+ field=models.CharField(
+ blank=True,
+ help_text='If you are not the author, enter the name or source here.',
+ max_length=200,
+ null=True,
+ verbose_name='Author(s)'
+ ),
+ ),
+ migrations.AlterField(
+ model_name='exercisebase',
+ name='license_author',
+ field=models.CharField(
+ blank=True,
+ help_text='If you are not the author, enter the name or source here.',
+ max_length=200,
+ null=True,
+ verbose_name='Author(s)'
+ ),
+ ),
+ migrations.AlterField(
+ model_name='exerciseimage',
+ name='license_author',
+ field=models.CharField(
+ blank=True,
+ help_text='If you are not the author, enter the name or source here.',
+ max_length=200,
+ null=True,
+ verbose_name='Author(s)'
+ ),
+ ),
+ migrations.AlterField(
+ model_name='exercisevideo',
+ name='license_author',
+ field=models.CharField(
+ blank=True,
+ help_text='If you are not the author, enter the name or source here.',
+ max_length=200,
+ null=True,
+ verbose_name='Author(s)'
+ ),
+ ),
+ migrations.AlterField(
+ model_name='historicalexercise',
+ name='license_author',
+ field=models.CharField(
+ blank=True,
+ help_text='If you are not the author, enter the name or source here.',
+ max_length=200,
+ null=True,
+ verbose_name='Author(s)'
+ ),
+ ),
+ migrations.AlterField(
+ model_name='historicalexercisebase',
+ name='license_author',
+ field=models.CharField(
+ blank=True,
+ help_text='If you are not the author, enter the name or source here.',
+ max_length=200,
+ null=True,
+ verbose_name='Author(s)'
+ ),
+ ),
+ migrations.AlterField(
+ model_name='historicalexerciseimage',
+ name='license_author',
+ field=models.CharField(
+ blank=True,
+ help_text='If you are not the author, enter the name or source here.',
+ max_length=200,
+ null=True,
+ verbose_name='Author(s)'
+ ),
+ ),
+ migrations.AlterField(
+ model_name='historicalexercisevideo',
+ name='license_author',
+ field=models.CharField(
+ blank=True,
+ help_text='If you are not the author, enter the name or source here.',
+ max_length=200,
+ null=True,
+ verbose_name='Author(s)'
+ ),
+ ),
+ ]
diff --git a/wger/nutrition/api/serializers.py b/wger/nutrition/api/serializers.py
index 1a6098f8a..d0c97ac6d 100644
--- a/wger/nutrition/api/serializers.py
+++ b/wger/nutrition/api/serializers.py
@@ -1,5 +1,3 @@
-# -*- coding: utf-8 -*-
-
# This file is part of wger Workout Manager.
#
# wger Workout Manager is free software: you can redistribute it and/or modify
@@ -96,7 +94,11 @@ class ImageSerializer(serializers.ModelSerializer):
'size',
'source_url',
'license',
+ 'license_title',
+ 'license_object_url',
'license_author',
+ 'license_author_url',
+ 'license_derivative_source_url',
]
@@ -123,7 +125,11 @@ class IngredientSerializer(serializers.ModelSerializer):
'fibres',
'sodium',
'license',
+ 'license_title',
+ 'license_object_url',
'license_author',
+ 'license_author_url',
+ 'license_derivative_source_url',
'language',
]
diff --git a/wger/nutrition/migrations/0014_license_information.py b/wger/nutrition/migrations/0014_license_information.py
new file mode 100644
index 000000000..ae2631893
--- /dev/null
+++ b/wger/nutrition/migrations/0014_license_information.py
@@ -0,0 +1,112 @@
+# Generated by Django 4.2 on 2023-04-07 15:11
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ('nutrition', '0013_ingredient_image'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='image',
+ name='license_author_url',
+ field=models.URLField(
+ blank=True,
+ max_length=100,
+ verbose_name='Link to author profile, if available',
+ ),
+ ),
+ migrations.AddField(
+ model_name='image',
+ name='license_derivative_source_url',
+ field=models.URLField(
+ blank=True,
+ help_text='Note that a derivative work is one which is not only based on a '
+ 'previous work, but which also contains sufficient new, creative '
+ 'content to entitle it to its own copyright.',
+ max_length=100,
+ verbose_name='Link to the original source, if this is a derivative work',
+ ),
+ ),
+ migrations.AddField(
+ model_name='image',
+ name='license_object_url',
+ field=models.URLField(
+ blank=True,
+ max_length=100,
+ verbose_name='Link to original object, if available',
+ ),
+ ),
+ migrations.AddField(
+ model_name='image',
+ name='license_title',
+ field=models.CharField(
+ blank=True,
+ max_length=100,
+ verbose_name='The original title of this object, if available',
+ ),
+ ),
+ migrations.AddField(
+ model_name='ingredient',
+ name='license_author_url',
+ field=models.URLField(
+ blank=True,
+ max_length=100,
+ verbose_name='Link to author profile, if available',
+ ),
+ ),
+ migrations.AddField(
+ model_name='ingredient',
+ name='license_derivative_source_url',
+ field=models.URLField(
+ blank=True,
+ help_text='Note that a derivative work is one which is not only based on a '
+ 'previous work, but which also contains sufficient new, creative '
+ 'content to entitle it to its own copyright.',
+ max_length=100,
+ verbose_name='Link to the original source, if this is a derivative work',
+ ),
+ ),
+ migrations.AddField(
+ model_name='ingredient',
+ name='license_object_url',
+ field=models.URLField(
+ blank=True,
+ max_length=100,
+ verbose_name='Link to original object, if available',
+ ),
+ ),
+ migrations.AddField(
+ model_name='ingredient',
+ name='license_title',
+ field=models.CharField(
+ blank=True,
+ max_length=100,
+ verbose_name='The original title of this object, if available',
+ ),
+ ),
+ migrations.AlterField(
+ model_name='image',
+ name='license_author',
+ field=models.CharField(
+ blank=True,
+ help_text='If you are not the author, enter the name or source here.',
+ max_length=200,
+ null=True,
+ verbose_name='Author(s)',
+ ),
+ ),
+ migrations.AlterField(
+ model_name='ingredient',
+ name='license_author',
+ field=models.CharField(
+ blank=True,
+ help_text='If you are not the author, enter the name or source here.',
+ max_length=200,
+ null=True,
+ verbose_name='Author(s)',
+ ),
+ ),
+ ]
diff --git a/wger/nutrition/models/sources.py b/wger/nutrition/models/sources.py
index eb7d5d26e..2d276966e 100644
--- a/wger/nutrition/models/sources.py
+++ b/wger/nutrition/models/sources.py
@@ -1,3 +1,18 @@
+# This file is part of wger Workout Manager <https://github.com/wger-project>.
+#
+# wger Workout Manager is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# wger Workout Manager is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
# Standard Library
from enum import Enum
diff --git a/wger/nutrition/sync.py b/wger/nutrition/sync.py
index 0f0ea6318..86b37fb84 100644
--- a/wger/nutrition/sync.py
+++ b/wger/nutrition/sync.py
@@ -123,10 +123,15 @@ def fetch_image_from_off(ingredient):
return
# Save to DB
+ url = f'https://world.openfoodfacts.org/cgi/product_image.pl?code={ingredient.code}&id=front_en'
+ uploader_url = f'https://world.openfoodfacts.org/photographer/{uploader_name}'
image_data = {
'image': os.path.basename(image_url),
'license': CC_BY_SA_3_LICENSE_ID,
+ 'license_title': 'Photo',
'license_author': uploader_name,
+ 'license_author_url': uploader_url,
+ 'license_object_url': url,
'size': len(response.content)
}
try:
diff --git a/wger/utils/models.py b/wger/utils/models.py
index e36daa11b..cf38de2e3 100644
--- a/wger/utils/models.py
+++ b/wger/utils/models.py
@@ -1,5 +1,3 @@
-# -*- coding: utf-8 -*-
-
# This file is part of Workout Manager.
#
# Workout Manager is free software: you can redistribute it and/or modify
@@ -31,6 +29,12 @@ Abstract model classes
class AbstractLicenseModel(models.Model):
"""
Abstract class that adds license information to a model
+
+ Implements TASL (Title - Author - Source - License) for proper attribution
+
+ See also
+ - https://wiki.creativecommons.org/wiki/Recommended_practices_for_attribution
+ - https://wiki.creativecommons.org/wiki/Best_practices_for_attribution
"""
class Meta:
@@ -42,20 +46,63 @@ class AbstractLicenseModel(models.Model):
default=CC_BY_SA_4_ID,
on_delete=models.CASCADE,
)
- """The item's license"""
+
+ license_title = models.CharField(
+ verbose_name=_('The original title of this object, if available'),
+ max_length=100,
+ blank=True,
+ )
+
+ license_object_url = models.URLField(
+ verbose_name=_('Link to original object, if available'),
+ max_length=100,
+ blank=True,
+ )
license_author = models.CharField(
- verbose_name=_('Author'),
- max_length=60,
+ verbose_name=_('Author(s)'),
+ max_length=200,
blank=True,
null=True,
+ help_text=_('If you are not the author, enter the name or source here.')
+ )
+
+ license_author_url = models.URLField(
+ verbose_name=_('Link to author profile, if available'),
+ max_length=100,
+ blank=True,
+ )
+
+ license_derivative_source_url = models.URLField(
+ verbose_name=_('Link to the original source, if this is a derivative work'),
help_text=_(
- 'If you are not the author, enter the name or '
- 'source here. This is needed for some licenses '
- 'e.g. the CC-BY-SA.'
- )
+ 'Note that a derivative work is one which is not only based on a previous '
+ 'work, but which also contains sufficient new, creative content to entitle it '
+ 'to its own copyright.'
+ ),
+ max_length=100,
+ blank=True,
)
- """The author if it is not the uploader"""
+
+ @property
+ def attribution_link(self):
+ out = ''
+
+ if self.license_title:
+ out += self.license_title
+
+ if self.license_author_url:
+ out += f'<a href="{self.license_author_url}">{self.license_author}</a>'
+ else:
+ out += self.license_author
+
+ out += f' is licensed under <a href="{self.license.url}">{self.license.short_name}</a>'
+
+ if self.license_source_url:
+ out += f'/ A derivative work from <a href="{self.license_source_url}">the original ' \
+ f'work</a>'
+
+ return out
class AbstractSubmissionModel(models.Model):
@@ -112,11 +159,11 @@ def collect_model_author_history(model):
return out
-def collect_models_author_history(models):
+def collect_models_author_history(model_list):
"""
Get unique set of license authors from historical records from models.
"""
out = set()
- for model in models:
+ for model in model_list:
out = out.union(collect_model_author_history(model))
return out