-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcreate_form.py
More file actions
executable file
·104 lines (88 loc) · 2.92 KB
/
Copy pathcreate_form.py
File metadata and controls
executable file
·104 lines (88 loc) · 2.92 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
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
#!/usr/bin/env python3
from __future__ import print_function
import rspace_client
def print_forms(response):
for form in response["forms"]:
print(form["globalId"], form["name"])
def create_form(fields):
response = client.create_form(
"Test Form", tags=["testing", "example"], fields=fields
)
return response
# Parse command line parameters
client = rspace_client.utils.createELNClient()
print("Listing all forms:")
response = client.get_forms()
print_forms(response)
# Get the remaining forms if the response is paginated
while client.link_exists(response, "next"):
response = client.get_link_contents(response, "next")
print_forms(response)
# Creates a new form
print("Creating a new form...")
fields = [
{
"name": "A String Field",
"type": "String",
"defaultValue": "An optional default value",
},
{
"name": "text FormField Example",
"type": "Text",
"defaultValue": "Some placeholder text,can be simple <em>HTML</em>",
},
{
"name": "Number FormField Example",
"type": "Number",
"defaultValue": 23,
"min": 0,
},
{
"name": "Choice FormField Example",
"type": "Choice",
"multipleChoice": True,
"options": ["antibody1", "antibody2", "antibody3"],
"defaultOptions": ["antibody2", "antibody3"],
},
{
"name": "Radio FormField Example",
"type": "Radio",
"options": ["antibody1", "antibody2", "antibody3"],
"defaultOption": "antibody2",
},
{
"name": "date FormField Example",
"type": "Date",
"defaultValue": "2018-03-21",
"min": "2018-02-21",
"max": "2018-04-21",
},
]
response = create_form(fields)
print("Newly created form info:", response["globalId"], response["name"])
# Get form details (these are also returned when creating a new form)
print("Getting details about a form:", response["globalId"])
response = client.get_form(response["globalId"])
print("Retrieved information about a form:", response["globalId"], response["name"])
print("Fields:")
for field in response["fields"]:
print(field["type"], field["name"])
# Publish the form
print("Publishing form:", response["globalId"])
client.publish_form(response["globalId"])
# Share the form
print("Sharing form:", response["globalId"])
client.share_form(response["globalId"])
# Unshare the form
print("Unsharing form:", response["globalId"])
client.unshare_form(response["globalId"])
# Unpublish the form
print("Unpublishing form:", response["globalId"])
client.unpublish_form(response["globalId"])
## Creating a new form for deletion
print("Creating a new form to show form deletion")
response = create_form(fields)
print("Newly created form info:", response["globalId"], response["name"])
print("Deleting the NEW form")
deleted = client.delete_form(response["globalId"])
print("Form {} is now deleted".format(response["globalId"]))