udata 8.0.2.dev29263__py2.py3-none-any.whl → 8.0.2.dev29284__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of udata might be problematic. Click here for more details.

Files changed (28) hide show
  1. udata/commands/purge.py +8 -2
  2. udata/core/dataservices/api.py +11 -3
  3. udata/core/dataservices/models.py +14 -2
  4. udata/core/dataservices/permissions.py +7 -0
  5. udata/core/dataservices/tasks.py +25 -0
  6. udata/static/chunks/{11.ae54612e36c6d46f85db.js → 11.7266fef2dddc1db403d9.js} +3 -3
  7. udata/static/chunks/{11.ae54612e36c6d46f85db.js.map → 11.7266fef2dddc1db403d9.js.map} +1 -1
  8. udata/static/chunks/{13.d8ccb992a49875966313.js → 13.91b177d7d531fd55cf5d.js} +2 -2
  9. udata/static/chunks/{13.d8ccb992a49875966313.js.map → 13.91b177d7d531fd55cf5d.js.map} +1 -1
  10. udata/static/chunks/{16.4565605e68bab129a471.js → 16.e866757bab9f6b0a3f1b.js} +2 -2
  11. udata/static/chunks/{16.4565605e68bab129a471.js.map → 16.e866757bab9f6b0a3f1b.js.map} +1 -1
  12. udata/static/chunks/{19.f993a75d5bfe2382548d.js → 19.619b83ac597516dcd03e.js} +3 -3
  13. udata/static/chunks/{19.f993a75d5bfe2382548d.js.map → 19.619b83ac597516dcd03e.js.map} +1 -1
  14. udata/static/chunks/{5.cc2e7bf65ef32f9c8604.js → 5.48417db6b33328fa9d6a.js} +3 -3
  15. udata/static/chunks/{5.cc2e7bf65ef32f9c8604.js.map → 5.48417db6b33328fa9d6a.js.map} +1 -1
  16. udata/static/chunks/{6.cad898a38692eda28965.js → 6.f84539bd4c419b36cc19.js} +3 -3
  17. udata/static/chunks/{6.cad898a38692eda28965.js.map → 6.f84539bd4c419b36cc19.js.map} +1 -1
  18. udata/static/chunks/{9.d5b992e9ef51921aeb57.js → 9.07503e7f7ec02919f696.js} +2 -2
  19. udata/static/chunks/{9.d5b992e9ef51921aeb57.js.map → 9.07503e7f7ec02919f696.js.map} +1 -1
  20. udata/static/common.js +1 -1
  21. udata/static/common.js.map +1 -1
  22. udata/tests/dataservice/test_dataservice_tasks.py +46 -0
  23. {udata-8.0.2.dev29263.dist-info → udata-8.0.2.dev29284.dist-info}/METADATA +3 -1
  24. {udata-8.0.2.dev29263.dist-info → udata-8.0.2.dev29284.dist-info}/RECORD +28 -25
  25. {udata-8.0.2.dev29263.dist-info → udata-8.0.2.dev29284.dist-info}/LICENSE +0 -0
  26. {udata-8.0.2.dev29263.dist-info → udata-8.0.2.dev29284.dist-info}/WHEEL +0 -0
  27. {udata-8.0.2.dev29263.dist-info → udata-8.0.2.dev29284.dist-info}/entry_points.txt +0 -0
  28. {udata-8.0.2.dev29263.dist-info → udata-8.0.2.dev29284.dist-info}/top_level.txt +0 -0
udata/commands/purge.py CHANGED
@@ -5,6 +5,7 @@ import click
5
5
  from udata.commands import cli, success
6
6
 
7
7
  from udata.core.dataset.tasks import purge_datasets
8
+ from udata.core.dataservices.tasks import purge_dataservices
8
9
  from udata.core.organization.tasks import purge_organizations
9
10
  from udata.core.reuse.tasks import purge_reuses
10
11
 
@@ -15,13 +16,14 @@ log = logging.getLogger(__name__)
15
16
  @click.option('-d', '--datasets', is_flag=True)
16
17
  @click.option('-r', '--reuses', is_flag=True)
17
18
  @click.option('-o', '--organizations', is_flag=True)
18
- def purge(datasets, reuses, organizations):
19
+ @click.option('--dataservices', is_flag=True)
20
+ def purge(datasets, reuses, organizations, dataservices):
19
21
  '''
20
22
  Permanently remove data flagged as deleted.
21
23
 
22
24
  If no model flag is given, all models are purged.
23
25
  '''
24
- purge_all = not any((datasets, reuses, organizations))
26
+ purge_all = not any((datasets, reuses, organizations, dataservices))
25
27
 
26
28
  if purge_all or datasets:
27
29
  log.info('Purging datasets')
@@ -35,4 +37,8 @@ def purge(datasets, reuses, organizations):
35
37
  log.info('Purging organizations')
36
38
  purge_organizations()
37
39
 
40
+ if purge_all or dataservices:
41
+ log.info('Purging dataservices')
42
+ purge_dataservices()
43
+
38
44
  success('Done')
@@ -6,11 +6,12 @@ import mongoengine
6
6
  from udata.api import api, API
7
7
  from udata.api_fields import patch
8
8
  from udata.core.dataset.permissions import OwnablePermission
9
+ from udata.core.followers.api import FollowAPI
9
10
  from .models import Dataservice
10
- from udata.models import db
11
11
 
12
12
  ns = api.namespace('dataservices', 'Dataservices related operations (beta)')
13
13
 
14
+
14
15
  @ns.route('/', endpoint='dataservices')
15
16
  class DataservicesAPI(API):
16
17
  '''Dataservices collection endpoint'''
@@ -39,6 +40,7 @@ class DataservicesAPI(API):
39
40
 
40
41
  return dataservice, 201
41
42
 
43
+
42
44
  @ns.route('/<dataservice:dataservice>/', endpoint='dataservice')
43
45
  class DataserviceAPI(API):
44
46
  @api.doc('get_dataservice')
@@ -47,7 +49,7 @@ class DataserviceAPI(API):
47
49
  if dataservice.deleted_at and not OwnablePermission(dataservice).can():
48
50
  api.abort(410, 'Dataservice has been deleted')
49
51
  return dataservice
50
-
52
+
51
53
  @api.secure
52
54
  @api.doc('update_dataservice', responses={400: 'Validation error'})
53
55
  @api.expect(Dataservice.__write_fields__)
@@ -75,10 +77,16 @@ class DataserviceAPI(API):
75
77
  api.abort(410, 'dataservice has been deleted')
76
78
 
77
79
  OwnablePermission(dataservice).test()
78
-
79
80
  dataservice.deleted_at = datetime.utcnow()
80
81
  dataservice.modified_at = datetime.utcnow()
81
82
  dataservice.save()
82
83
 
83
84
  return '', 204
84
85
 
86
+
87
+ @ns.route('/<id>/followers/', endpoint='dataservice_followers')
88
+ @ns.doc(get={'id': 'list_dataservice_followers'},
89
+ post={'id': 'follow_dataservice'},
90
+ delete={'id': 'unfollow_dataservice'})
91
+ class DataserviceFollowersAPI(FollowAPI):
92
+ model = Dataservice
@@ -3,11 +3,11 @@ from udata.api_fields import field, function_field, generate_fields
3
3
  from udata.core.dataset.models import Dataset
4
4
  from udata.core.metrics.models import WithMetrics
5
5
  from udata.core.owned import Owned, OwnedQuerySet
6
- from udata.i18n import lazy_gettext as _
7
6
  import udata.core.contact_point.api_fields as contact_api_fields
8
7
  import udata.core.dataset.api_fields as datasets_api_fields
8
+ from udata.i18n import lazy_gettext as _
9
9
 
10
- from udata.models import db
10
+ from udata.models import db, Discussion, Follow
11
11
  from udata.uris import endpoint_for
12
12
 
13
13
  # "frequency"
@@ -128,3 +128,15 @@ class Dataservice(WithMetrics, Owned, db.Document):
128
128
  # temporal_coverage = db.EmbeddedDocumentField(db.DateRange)
129
129
  # spatial = db.EmbeddedDocumentField(SpatialCoverage)
130
130
  # harvest = db.EmbeddedDocumentField(HarvestDatasetMetadata)
131
+
132
+ @property
133
+ def is_hidden(self):
134
+ return self.private or self.deleted_at or self.archived_at
135
+
136
+ def count_discussions(self):
137
+ self.metrics['discussions'] = Discussion.objects(subject=self, closed=None).count()
138
+ self.save()
139
+
140
+ def count_followers(self):
141
+ self.metrics['followers'] = Follow.objects(until=None).followers(self).count()
142
+ self.save()
@@ -0,0 +1,7 @@
1
+ from udata.core.dataset.permissions import (
2
+ OwnablePermission
3
+ )
4
+
5
+ class DataserviceEditPermission(OwnablePermission):
6
+ '''Permissions to edit a Dataservice'''
7
+ pass
@@ -0,0 +1,25 @@
1
+ from celery.utils.log import get_task_logger
2
+
3
+ from udata.core.dataservices.models import Dataservice
4
+ # from udata.harvest.models import HarvestJob
5
+ from udata.models import (Follow, Discussion, Activity, Transfer)
6
+ from udata.tasks import job
7
+
8
+ log = get_task_logger(__name__)
9
+
10
+
11
+ @job('purge-dataservices')
12
+ def purge_dataservices(self):
13
+ for dataservice in Dataservice.objects(deleted_at__ne=None):
14
+ log.info(f'Purging dataservice {dataservice}')
15
+ # Remove followers
16
+ Follow.objects(following=dataservice).delete()
17
+ # Remove discussions
18
+ Discussion.objects(subject=dataservice).delete()
19
+ # Remove HarvestItem references
20
+ # TODO: uncomment when adding dataservice harvest
21
+ # HarvestJob.objects(items__dataservice=dataservice).update(set__items__S__dataservice=None)
22
+ # Remove associated Transfers
23
+ Transfer.objects(subject=dataservice).delete()
24
+ # Remove dataservice
25
+ dataservice.delete()