-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fixes #12124] Implementation of assets
- Loading branch information
1 parent
c0c9e57
commit a6bbe39
Showing
12 changed files
with
312 additions
and
30 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
geonode/base/migrations/0091_asset_remove_resourcebase_files_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Generated by Django 4.2.9 on 2024-03-13 09:38 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import django.utils.timezone | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("base", "0090_alter_resourcebase_polymorphic_ctype"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Asset", | ||
fields=[ | ||
("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), | ||
("title", models.CharField(max_length=255)), | ||
("description", models.TextField(blank=True, null=True)), | ||
("type", models.CharField(max_length=255)), | ||
("created", models.DateTimeField(default=django.utils.timezone.now)), | ||
("owner", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
( | ||
"polymorphic_ctype", | ||
models.ForeignKey( | ||
editable=False, | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="polymorphic_%(app_label)s.%(class)s_set+", | ||
to="contenttypes.contenttype", | ||
), | ||
), | ||
], | ||
options={ | ||
"verbose_name_plural": "Assets", | ||
}, | ||
), | ||
migrations.AlterField( | ||
model_name="hierarchicalkeyword", | ||
name="slug", | ||
field=models.SlugField(allow_unicode=True, max_length=100, unique=True, verbose_name="slug"), | ||
), | ||
migrations.CreateModel( | ||
name="LocalAsset", | ||
fields=[ | ||
( | ||
"asset_ptr", | ||
models.OneToOneField( | ||
auto_created=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
parent_link=True, | ||
primary_key=True, | ||
serialize=False, | ||
to="base.asset", | ||
), | ||
), | ||
("location", models.CharField(max_length=255)), | ||
], | ||
options={ | ||
"verbose_name_plural": "Local assets", | ||
}, | ||
bases=("base.asset",), | ||
), | ||
migrations.AddField( | ||
model_name="link", | ||
name="asset", | ||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to="base.asset"), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Generated by Django 4.2.9 on 2024-03-12 11:55 | ||
|
||
from django.conf import settings | ||
from django.db import migrations | ||
from django.db.models import Q | ||
from geonode.base.enumerations import LINK_TYPES | ||
|
||
from geonode.base.models import Link, LocalAsset, ResourceBase | ||
|
||
|
||
|
||
def migrate_files(apps, schema_editor): | ||
if hasattr(ResourceBase, "files"): | ||
# looping on available resources with files to generate the LocalAssets | ||
for resource in ResourceBase.objects.exclude(Q(files__isnull=True) | Q(files__exact=[])).iterator(): | ||
# creating the local asset object | ||
asset = LocalAsset( | ||
title="files", | ||
description="Original uploaded files path", | ||
owner=resource.owner, | ||
location=resource.files | ||
) | ||
asset.save() | ||
# creating the association between asset and Link | ||
# lets check if a original link exists | ||
|
||
link = resource.link_set.filter(link_type="original").first() | ||
if link: | ||
# if exists, we can assign the asset to the link | ||
link.asset = asset | ||
link.save() | ||
else: | ||
# otherwise we create the link with the assigned asset | ||
Link.objects.create( | ||
resource=resource.get_self_resource(), | ||
asset=asset, | ||
link_type="original", | ||
name="Original", | ||
url=resource.get_real_instance().download_url | ||
) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("base", "0091_asset_remove_resourcebase_files_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(migrate_files, migrations.RunPython.noop), | ||
migrations.RemoveField( | ||
model_name="resourcebase", | ||
name="files", | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 4.2.9 on 2024-03-14 10:32 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("base", "0092_generate_assets"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="localasset", | ||
name="location", | ||
field=models.JSONField(blank=True, default=list), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.