refactor of license django model #119

This commit is contained in:
Liam Brydon
2025-11-10 14:51:44 +13:00
parent e26d5a21e3
commit 42b1e77fb9
7 changed files with 45 additions and 25 deletions

View File

@ -11,11 +11,14 @@ from epdb.models import (
EnviFormer,
Permission,
User,
ExternalDatabase,
ExternalDatabase, License,
)
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument("-ol", "--only-licenses", action="store_true", help="Only create licenses.")
def create_users(self):
# Anonymous User
if not User.objects.filter(email="anon@envipath.com").exists():
@ -83,6 +86,16 @@ class Command(BaseCommand):
return anon, admin, g, user0
def create_licenses(self):
"""Create the six default licenses supported by enviPath"""
cc_strings = ["by", "by-nc", "by-nc-nd", "by-nc-sa", "by-nd", "by-sa"]
for cc_string in cc_strings:
new_license = License()
new_license.cc_string = cc_string
new_license.link = f"https://creativecommons.org/licenses/{cc_string}/4.0/"
new_license.image_link = f"https://licensebuttons.net/l/{cc_string}/4.0/88x31.png"
new_license.save()
def import_package(self, data, owner):
return PackageManager.import_legacy_package(
data, owner, keep_ids=True, add_import_timestamp=False, trust_reviewed=True
@ -158,6 +171,9 @@ class Command(BaseCommand):
@transaction.atomic
def handle(self, *args, **options):
# Create users
self.create_licenses()
if options.get("only_licenses", False):
return
anon, admin, g, user0 = self.create_users()
self.populate_common_external_databases()