Skip to content

Commit

Permalink
Make file not mandatory and add external access URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
pdelboca committed Jan 5, 2024
1 parent ab2741f commit 32b79d8
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
20 changes: 20 additions & 0 deletions dcat/migrations/0011_alter_distribution_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 5.0 on 2024-01-05 16:33

import dcat.models
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("dcat", "0010_dataset_landing_page"),
]

operations = [
migrations.AlterField(
model_name="distribution",
name="file",
field=models.FileField(
blank=True, upload_to=dcat.models.Distribution._get_storage_path
),
),
]
17 changes: 17 additions & 0 deletions dcat/migrations/0012_distribution_external_access_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 5.0 on 2024-01-05 16:39

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("dcat", "0011_alter_distribution_file"),
]

operations = [
migrations.AddField(
model_name="distribution",
name="external_access_url",
field=models.URLField(blank=True, default=""),
),
]
12 changes: 10 additions & 2 deletions dcat/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,22 +109,30 @@ def _get_storage_path(instance, filename):
return f"files/datasets/{instance.dataset.pk}/{filename}"

# Mandatory properties
dataset = models.ForeignKey("Dataset", on_delete=models.CASCADE)
@property
def access_url(self):
"""Return the access url of the file.
If the file is hosted in another portal, the access_url is provided
in the distribution. Otherwise, the access_url is the URL to the
distribution.
"""
pass

# Recomened properties
title = models.CharField(max_length=255, blank=True)
description = models.TextField(blank=True)
file = models.FileField(upload_to=_get_storage_path)
dataset = models.ForeignKey("Dataset", on_delete=models.CASCADE)
file = models.FileField(upload_to=_get_storage_path, blank=True)
format = models.ForeignKey(
"MediaType", on_delete=models.SET_NULL, blank=True, null=True
)
licence = models.ForeignKey(
"LicenceDocument", on_delete=models.SET_NULL, blank=True, null=True
)

external_download_url = models.URLField(blank=True, default="")
external_access_url = models.URLField(blank=True, default="")

# Optional properties
checksum = models.OneToOneField(
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = django-dcat
version = 0.0.4
version = 0.0.5
description = A Django app that provides a model layer and tools for DCAT applications.
long_description = file: README.rst
url = https://github.com/pdelboca/django-dcat/
Expand Down

0 comments on commit 32b79d8

Please sign in to comment.