-
Notifications
You must be signed in to change notification settings - Fork 2k
/
patch.py
140 lines (108 loc) · 4.43 KB
/
patch.py
1
2
3
4
5
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# encoding: utf-8
'''API functions for partial updates of existing data in CKAN'''
import ckan.logic.action.update as _update
from ckan.logic import (
get_action as _get_action,
check_access as _check_access,
get_or_bust as _get_or_bust,
)
def package_patch(context, data_dict):
'''Patch a dataset (package).
:param id: the id or name of the dataset
:type id: string
The difference between the update and patch methods is that the patch will
perform an update of the provided parameters, while leaving all other
parameters unchanged, whereas the update methods deletes all parameters
not explicitly provided in the data_dict.
You are able to partially update and/or create resources with
package_patch. If you are updating existing resources be sure to provide
the resource id. Existing resources excluded from the package_patch
data_dict will be removed. Resources in the package data_dict without
an id will be treated as new resources and will be added. New resources
added with the patch method do not create the default views.
You must be authorized to edit the dataset and the groups that it belongs
to.
'''
_check_access('package_patch', context, data_dict)
show_context = {
'model': context['model'],
'session': context['session'],
'user': context['user'],
'auth_user_obj': context['auth_user_obj'],
'ignore_auth': context.get('ignore_auth', False),
}
package_dict = _get_action('package_show')(
show_context,
{'id': _get_or_bust(data_dict, 'id')})
patched = dict(package_dict)
patched.update(data_dict)
patched['id'] = package_dict['id']
return _update.package_update(context, patched)
def resource_patch(context, data_dict):
'''Patch a resource
:param id: the id of the resource
:type id: string
The difference between the update and patch methods is that the patch will
perform an update of the provided parameters, while leaving all other
parameters unchanged, whereas the update methods deletes all parameters
not explicitly provided in the data_dict
'''
_check_access('resource_patch', context, data_dict)
show_context = {
'model': context['model'],
'session': context['session'],
'user': context['user'],
'auth_user_obj': context['auth_user_obj'],
}
resource_dict = _get_action('resource_show')(
show_context,
{'id': _get_or_bust(data_dict, 'id')})
patched = dict(resource_dict)
patched.update(data_dict)
return _update.resource_update(context, patched)
def group_patch(context, data_dict):
'''Patch a group
:param id: the id or name of the group
:type id: string
The difference between the update and patch methods is that the patch will
perform an update of the provided parameters, while leaving all other
parameters unchanged, whereas the update methods deletes all parameters
not explicitly provided in the data_dict
'''
_check_access('group_patch', context, data_dict)
show_context = {
'model': context['model'],
'session': context['session'],
'user': context['user'],
'auth_user_obj': context['auth_user_obj'],
}
group_dict = _get_action('group_show')(
show_context,
{'id': _get_or_bust(data_dict, 'id')})
patched = dict(group_dict)
patched.pop('display_name', None)
patched.update(data_dict)
return _update.group_update(context, patched)
def organization_patch(context, data_dict):
'''Patch an organization
:param id: the id or name of the organization
:type id: string
The difference between the update and patch methods is that the patch will
perform an update of the provided parameters, while leaving all other
parameters unchanged, whereas the update methods deletes all parameters
not explicitly provided in the data_dict
'''
_check_access('organization_patch', context, data_dict)
show_context = {
'model': context['model'],
'session': context['session'],
'user': context['user'],
'auth_user_obj': context['auth_user_obj'],
}
organization_dict = _get_action('organization_show')(
show_context,
{'id': _get_or_bust(data_dict, 'id')})
patched = dict(organization_dict)
patched.pop('display_name', None)
patched.update(data_dict)
return _update.organization_update(context, patched)