udata 9.2.1.dev31556__py2.py3-none-any.whl → 9.2.2__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 (44) hide show
  1. udata/__init__.py +1 -1
  2. udata/core/contact_point/api.py +6 -1
  3. udata/core/contact_point/forms.py +4 -1
  4. udata/core/contact_point/models.py +10 -1
  5. udata/core/dataservices/models.py +1 -4
  6. udata/core/dataset/csv.py +4 -16
  7. udata/core/discussions/api.py +24 -1
  8. udata/core/discussions/csv.py +22 -0
  9. udata/static/chunks/{10.1d9b1714c0289863ba0a.js → 10.c1c9496ebfc8949f3de2.js} +3 -3
  10. udata/static/chunks/{10.1d9b1714c0289863ba0a.js.map → 10.c1c9496ebfc8949f3de2.js.map} +1 -1
  11. udata/static/chunks/{11.215a951b6106fb100482.js → 11.16618d9eedd3f6a7a3c2.js} +3 -3
  12. udata/static/chunks/{11.215a951b6106fb100482.js.map → 11.16618d9eedd3f6a7a3c2.js.map} +1 -1
  13. udata/static/chunks/{19.c42864d5a39bde8e641e.js → 19.f1ff6cd5816f2d9debc4.js} +3 -3
  14. udata/static/chunks/{19.c42864d5a39bde8e641e.js.map → 19.f1ff6cd5816f2d9debc4.js.map} +1 -1
  15. udata/static/chunks/{8.caab9498d0ea0a6a3992.js → 8.b50a30118e9e2e1ab436.js} +2 -2
  16. udata/static/chunks/{8.caab9498d0ea0a6a3992.js.map → 8.b50a30118e9e2e1ab436.js.map} +1 -1
  17. udata/static/chunks/{9.5009f558f2268bbe4094.js → 9.8ad948dd393d38f07a7a.js} +3 -3
  18. udata/static/chunks/{9.5009f558f2268bbe4094.js.map → 9.8ad948dd393d38f07a7a.js.map} +1 -1
  19. udata/static/common.js +1 -1
  20. udata/static/common.js.map +1 -1
  21. udata/tests/api/test_contact_points.py +40 -1
  22. udata/tests/dataset/test_csv_adapter.py +9 -2
  23. udata/tests/test_discussions.py +61 -0
  24. udata/translations/ar/LC_MESSAGES/udata.mo +0 -0
  25. udata/translations/ar/LC_MESSAGES/udata.po +88 -92
  26. udata/translations/de/LC_MESSAGES/udata.mo +0 -0
  27. udata/translations/de/LC_MESSAGES/udata.po +88 -92
  28. udata/translations/es/LC_MESSAGES/udata.mo +0 -0
  29. udata/translations/es/LC_MESSAGES/udata.po +88 -92
  30. udata/translations/fr/LC_MESSAGES/udata.mo +0 -0
  31. udata/translations/fr/LC_MESSAGES/udata.po +88 -92
  32. udata/translations/it/LC_MESSAGES/udata.mo +0 -0
  33. udata/translations/it/LC_MESSAGES/udata.po +88 -92
  34. udata/translations/pt/LC_MESSAGES/udata.mo +0 -0
  35. udata/translations/pt/LC_MESSAGES/udata.po +88 -92
  36. udata/translations/sr/LC_MESSAGES/udata.mo +0 -0
  37. udata/translations/sr/LC_MESSAGES/udata.po +88 -92
  38. udata/translations/udata.pot +89 -93
  39. {udata-9.2.1.dev31556.dist-info → udata-9.2.2.dist-info}/METADATA +10 -2
  40. {udata-9.2.1.dev31556.dist-info → udata-9.2.2.dist-info}/RECORD +44 -43
  41. {udata-9.2.1.dev31556.dist-info → udata-9.2.2.dist-info}/LICENSE +0 -0
  42. {udata-9.2.1.dev31556.dist-info → udata-9.2.2.dist-info}/WHEEL +0 -0
  43. {udata-9.2.1.dev31556.dist-info → udata-9.2.2.dist-info}/entry_points.txt +0 -0
  44. {udata-9.2.1.dev31556.dist-info → udata-9.2.2.dist-info}/top_level.txt +0 -0
udata/__init__.py CHANGED
@@ -4,5 +4,5 @@
4
4
  udata
5
5
  """
6
6
 
7
- __version__ = "9.2.1.dev"
7
+ __version__ = "9.2.2"
8
8
  __description__ = "Open data portal"
@@ -1,3 +1,5 @@
1
+ import mongoengine
2
+
1
3
  from udata.api import API, api
2
4
  from udata.api.parsers import ModelApiParser
3
5
 
@@ -29,7 +31,10 @@ class ContactPointsListAPI(API):
29
31
  def post(self):
30
32
  """Creates a contact point"""
31
33
  form = api.validate(ContactPointForm)
32
- contact_point = form.save()
34
+ try:
35
+ contact_point = form.save()
36
+ except mongoengine.errors.ValidationError as e:
37
+ api.abort(400, e.message)
33
38
  return contact_point, 201
34
39
 
35
40
 
@@ -12,6 +12,9 @@ class ContactPointForm(ModelForm):
12
12
  _("Name"),
13
13
  [validators.DataRequired(), validators.NoURLs(_("URLs not allowed in this field"))],
14
14
  )
15
- email = fields.StringField(_("Email"), [validators.DataRequired(), validators.Email()])
15
+ email = fields.StringField(_("Email"), [validators.optional(), validators.Email()])
16
+ contact_form = fields.URLField(
17
+ _("Contact form"), description=_("The organization web contact form")
18
+ )
16
19
  owner = fields.CurrentUserField()
17
20
  organization = fields.PublishAsField(_("Publish as"))
@@ -1,11 +1,20 @@
1
1
  from udata.core.owned import Owned, OwnedQuerySet
2
+ from udata.i18n import lazy_gettext as _
2
3
  from udata.mongo import db
3
4
 
4
5
  __all__ = ("ContactPoint",)
5
6
 
6
7
 
7
8
  class ContactPoint(db.Document, Owned):
8
- email = db.StringField(max_length=255, required=True)
9
9
  name = db.StringField(max_length=255, required=True)
10
+ email = db.StringField(max_length=255)
11
+ contact_form = db.URLField()
10
12
 
11
13
  meta = {"queryset_class": OwnedQuerySet}
14
+
15
+ def validate(self, clean=True):
16
+ if not self.email and not self.contact_form:
17
+ raise db.ValidationError(
18
+ _("At least an email or a contact form is required for a contact point")
19
+ )
20
+ return super().validate(clean=clean)
@@ -122,10 +122,7 @@ class Dataservice(WithMetrics, Owned, db.Document):
122
122
  readonly=True,
123
123
  )
124
124
  description = field(db.StringField(default=""), description="In markdown")
125
- base_api_url = field(
126
- db.URLField(required=True),
127
- sortable=True,
128
- )
125
+ base_api_url = field(db.URLField(), sortable=True)
129
126
  endpoint_description_url = field(db.URLField())
130
127
  authorization_request_url = field(db.URLField())
131
128
  availability = field(db.FloatField(min=0, max=100), example="99.99")
udata/core/dataset/csv.py CHANGED
@@ -1,4 +1,5 @@
1
- from udata.core.discussions.models import Discussion
1
+ # for backwards compatibility (see https://github.com/opendatateam/udata/pull/3152)
2
+ from udata.core.discussions.csv import DiscussionCsvAdapter # noqa: F401
2
3
  from udata.frontend import csv
3
4
 
4
5
  from .models import Dataset, Resource
@@ -36,11 +37,13 @@ class DatasetCsvAdapter(csv.Adapter):
36
37
  ("archived", lambda o: o.archived or False),
37
38
  ("resources_count", lambda o: len(o.resources)),
38
39
  ("main_resources_count", lambda o: len([r for r in o.resources if r.type == "main"])),
40
+ ("resources_formats", lambda o: ",".join(set(r.format for r in o.resources if r.format))),
39
41
  "downloads",
40
42
  ("harvest.backend", lambda r: r.harvest and r.harvest.backend),
41
43
  ("harvest.domain", lambda r: r.harvest and r.harvest.domain),
42
44
  ("harvest.created_at", lambda r: r.harvest and r.harvest.created_at),
43
45
  ("harvest.modified_at", lambda r: r.harvest and r.harvest.modified_at),
46
+ ("harvest.remote_url", lambda r: r.harvest and r.harvest.remote_url),
44
47
  ("quality_score", lambda o: format(o.quality["score"], ".2f")),
45
48
  # schema? what is the schema of a dataset?
46
49
  )
@@ -90,18 +93,3 @@ class ResourcesCsvAdapter(csv.NestedAdapter):
90
93
  ("preview_url", lambda o: o.preview_url or False),
91
94
  )
92
95
  attribute = "resources"
93
-
94
-
95
- @csv.adapter(Discussion)
96
- class DiscussionCsvAdapter(csv.Adapter):
97
- fields = (
98
- "id",
99
- "user",
100
- "subject",
101
- "title",
102
- ("size", lambda o: len(o.discussion)),
103
- ("messages", lambda o: "\n".join(msg.content for msg in o.discussion)),
104
- "created",
105
- "closed",
106
- "closed_by",
107
- )
@@ -6,6 +6,10 @@ from flask_security import current_user
6
6
 
7
7
  from udata.api import API, api, fields
8
8
  from udata.auth import admin_permission
9
+ from udata.core.dataservices.models import Dataservice
10
+ from udata.core.dataset.models import Dataset
11
+ from udata.core.organization.models import Organization
12
+ from udata.core.reuse.models import Reuse
9
13
  from udata.core.spam.api import SpamAPIMixin
10
14
  from udata.core.spam.fields import spam_fields
11
15
  from udata.core.user.api_fields import user_ref_fields
@@ -73,8 +77,15 @@ comment_discussion_fields = api.model(
73
77
  discussion_page_fields = api.model("DiscussionPage", fields.pager(discussion_fields))
74
78
 
75
79
  parser = api.parser()
80
+ sorting_keys: list[str] = ["created", "title", "closed"]
81
+ sorting_choices: list[str] = sorting_keys + ["-" + k for k in sorting_keys]
76
82
  parser.add_argument(
77
- "sort", type=str, default="-created", location="args", help="The sorting attribute"
83
+ "sort",
84
+ type=str,
85
+ default="-created",
86
+ choices=sorting_choices,
87
+ location="args",
88
+ help="The field (and direction) on which sorting apply",
78
89
  )
79
90
  parser.add_argument(
80
91
  "closed",
@@ -85,6 +96,9 @@ parser.add_argument(
85
96
  parser.add_argument(
86
97
  "for", type=str, location="args", action="append", help="Filter discussions for a given subject"
87
98
  )
99
+ parser.add_argument(
100
+ "org", type=str, location="args", help="Filter discussions for a given organization"
101
+ )
88
102
  parser.add_argument("user", type=str, location="args", help="Filter discussions created by a user")
89
103
  parser.add_argument("page", type=int, default=1, location="args", help="The page to fetch")
90
104
  parser.add_argument(
@@ -198,6 +212,15 @@ class DiscussionsAPI(API):
198
212
  discussions = Discussion.objects
199
213
  if args["for"]:
200
214
  discussions = discussions.generic_in(subject=args["for"])
215
+ if args["org"]:
216
+ org = Organization.objects.get_or_404(id=id_or_404(args["org"]))
217
+ if not org:
218
+ api.abort(404, "Organization does not exist")
219
+ reuses = Reuse.objects(organization=org).only("id")
220
+ datasets = Dataset.objects(organization=org).only("id")
221
+ dataservices = Dataservice.objects(organization=org).only("id")
222
+ subjects = list(reuses) + list(datasets) + list(dataservices)
223
+ discussions = discussions(subject__in=subjects)
201
224
  if args["user"]:
202
225
  discussions = discussions(discussion__posted_by=ObjectId(args["user"]))
203
226
  if args["closed"] is False:
@@ -0,0 +1,22 @@
1
+ from udata.frontend import csv
2
+
3
+ from .models import Discussion
4
+
5
+
6
+ @csv.adapter(Discussion)
7
+ class DiscussionCsvAdapter(csv.Adapter):
8
+ fields = (
9
+ "id",
10
+ "user",
11
+ "subject",
12
+ ("subject_class", "subject._class_name"),
13
+ ("subject_id", "subject.id"),
14
+ "title",
15
+ ("size", lambda o: len(o.discussion)),
16
+ ("participants", lambda o: ",".join(set(str(msg.posted_by.id) for msg in o.discussion))),
17
+ ("messages", lambda o: "\n".join(msg.content.replace("\n", " ") for msg in o.discussion)),
18
+ "created",
19
+ "closed",
20
+ "closed_by",
21
+ ("closed_by_id", "closed_by.id"),
22
+ )