-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathviews.py
More file actions
65 lines (58 loc) · 1.81 KB
/
views.py
File metadata and controls
65 lines (58 loc) · 1.81 KB
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
# -*- coding: utf-8 -*-
from django.db.models import Subquery
from rest_framework import status as http_status
from flask import request
import logging
# admin notes取得viewのためのimport
from osf.models import RdmAddonOption
from . import SHORT_NAME
from . import settings
from framework.exceptions import HTTPError
from website.project.decorators import (
must_be_contributor_or_public,
must_have_addon,
must_be_valid_project,
must_have_permission,
)
logger = logging.getLogger(__name__)
@must_be_valid_project
@must_have_permission('admin')
@must_have_addon(SHORT_NAME, 'node')
def myskelton_get_config(**kwargs):
node = kwargs['node'] or kwargs['project']
addon = node.get_addon(SHORT_NAME)
return {'param_1': addon.get_param_1()}
@must_be_valid_project
@must_have_permission('admin')
@must_have_addon(SHORT_NAME, 'node')
def myskelton_set_config(**kwargs):
node = kwargs['node'] or kwargs['project']
addon = node.get_addon(SHORT_NAME)
try:
param_1 = request.json['param_1']
except KeyError:
raise HTTPError(http_status.HTTP_400_BAD_REQUEST)
logger.info('param_1: {}'.format(param_1))
addon.set_param_1(param_1)
return {}
# admin notes取得view
@must_be_valid_project
@must_have_addon(SHORT_NAME, 'node')
def myskelton_get_admin_notes(**kwargs):
node = kwargs['node'] or kwargs['project']
res = []
for ins in node.affiliated_institutions.all():
opt = RdmAddonOption.objects.filter(
provider=SHORT_NAME,
institution_id=ins.id,
is_allowed=True
).first()
if opt is not None:
res.append({
'institution': {
'id': ins.id,
'name': ins.name,
},
'value': opt.admin_notes
})
return res