Newer
Older
from django_filters import rest_framework as filters
from urllib.parse import urlsplit
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
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):
"""
Insert a datalocation from a srm string (e.g. srm://surm:4321/path.tar)
:param str location_string: SRM url
:return: DataLocation object
rtype: DataLocations
"""
_, netloc, *_ = urlsplit(location_string)
dataloc = DataLocation(name=netloc, uri=location_string.rstrip('/'))
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)
project = models.CharField(max_length=15)
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)