From 9adf3054e394d502be3d7dcfd045c58cd5546fb5 Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Tue, 9 Apr 2024 16:19:10 +0200 Subject: [PATCH] Add license to the Fake Data This is not the most elegant way of doing this. We could do like we do for tags. That said, this also solves the problem. Without this Blender complains that "license" is empty to some of the JSON entries. --- common/management/commands/generate_fake_data.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/common/management/commands/generate_fake_data.py b/common/management/commands/generate_fake_data.py index ccbe3ca9..bf90b76f 100644 --- a/common/management/commands/generate_fake_data.py +++ b/common/management/commands/generate_fake_data.py @@ -7,7 +7,7 @@ from common.tests.factories.files import FileFactory from common.tests.factories.teams import TeamFactory from files.models import File from constants.version_permissions import VERSION_PERMISSION_FILE, VERSION_PERMISSION_NETWORK -from constants.licenses import LICENSE_GPL2 +from constants.licenses import LICENSE_GPL2, LICENSE_GPL3 from extensions.models import Extension, Tag FILE_SOURCES = { @@ -54,6 +54,7 @@ to setup the `addon preferences`. ... ''' +LICENSES = (LICENSE_GPL2.id, LICENSE_GPL3.id) class Command(BaseCommand): @@ -100,7 +101,7 @@ class Command(BaseCommand): # Create a few publicly listed extensions for i in range(10): extension__type = random.choice(Extension.TYPES)[0] - create_approved_version( + version = create_approved_version( file__status=File.STATUSES.APPROVED, # extension__status=Extension.STATUSES.APPROVED, extension__type=extension__type, @@ -116,16 +117,20 @@ class Command(BaseCommand): ) ], ) + for i in range(random.randint(1, len(LICENSES))): + version.licenses.add(LICENSES[i]) # Create a few unlisted extension versions for i in range(5): extension__type = random.choice(Extension.TYPES)[0] - create_version( + version = create_version( file__status=random.choice( (File.STATUSES.DISABLED, File.STATUSES.DISABLED_BY_AUTHOR) ), tags=random.sample(tags[extension__type], k=1), ) + for i in range(random.randint(1, len(LICENSES))): + version.licenses.add(LICENSES[i]) example_version.extension.average_score = 5.0 example_version.extension.save(update_fields={'average_score'}) -- 2.30.2