Newer
Older
from django_filters import rest_framework as filters
from urllib.parse import urlsplit
class DataLocation(models.Model):
name = models.CharField(max_length=50, primary_key=True)
uri = models.CharField(max_length=200)
@staticmethod
def insert_location_from_string(location_string):
"""

Roy de Goei
committed
Insert a datalocation from a srm string (e.g. srm://srm-url:4321)
Data Location names are: Sara, Juelich and Poznan
:param str location_string: SRM url
:return: DataLocation object
"""

Roy de Goei
committed
# netloc will become srm-url:4321

Roy de Goei
committed
if "sara" in netloc.lower():
loc_name = "Sara"
elif "fz-juelich" in netloc.lower():
loc_name = "Juelich"
elif "psnc" in netloc.lower():
loc_name = "Poznan"
else:
loc_name = "Unknown"
dataloc = DataLocation(name=loc_name, uri=netloc)
dataloc.save()
return dataloc
class DataProduct(models.Model):
obs_id = models.CharField(verbose_name="OBS_ID", max_length=15)
oid_source = models.CharField(verbose_name='OBS_ID_SOURCE', max_length=15)
dataproduct_source = models.CharField(max_length=20)
dataproduct_type = models.CharField(max_length=50)

Roy de Goei
committed
project = models.CharField(max_length=50)
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
location = models.ForeignKey(DataLocation, on_delete=models.DO_NOTHING)
activity = models.CharField(max_length=50)
surl = models.CharField(max_length=200)
filesize = models.PositiveBigIntegerField()
additional_meta = models.JSONField()
@staticmethod
def insert_dataproduct(obs_id,
oid_source,
dataproduct_source,
dataproduct_type,
project,
activity,
surl,
filesize,
additional_meta):
scheme, netloc, *_ = urlsplit(surl)
dp = DataProduct(obs_id=obs_id,
oid_source=oid_source,
dataproduct_source=dataproduct_source,
dataproduct_type=dataproduct_type,
project=project,
location=DataLocation.insert_location_from_string('://'.join((scheme, netloc))),
activity=activity,
filesize=filesize,
additional_meta=additional_meta,
surl=surl
)
dp.save()
return dp
class DataProductFilter(models.Model):
field = models.CharField(max_length=100)
name = models.CharField(max_length=20)
lookup_type = models.CharField(max_length=100)