Skip to content

Commit 295b311

Browse files
Add neceray attribute creation on initialiaing of conversational
1 parent 5d6a70e commit 295b311

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

sdk/diffgram/file/conversational.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,60 @@ def __init__(self, project, name):
88
directory_id=project.default_directory.id,
99
file_type="compound/conversational"
1010
)
11-
11+
self.project = project
1212
self.messgaes_meta = []
1313

14+
self.add_conversationa_attributes_if_doesnt_exist()
15+
16+
def add_conversationa_attributes_if_doesnt_exist(self):
17+
default_schema = self.project.schema.default_schema()
18+
attribute_list = self.project.attribute.list(default_schema)
19+
20+
message_author_attribute = None
21+
message_time_attribute = None
22+
message_date_attribute = None
23+
24+
for attribute in attribute_list['attribute_group_list']:
25+
if attribute['name'] == 'message_author':
26+
message_author_attribute = attribute
27+
elif attribute['name'] == 'message_time':
28+
message_time_attribute = attribute
29+
elif attribute['name'] == 'message_date':
30+
message_date_attribute = attribute
31+
32+
if message_author_attribute is None:
33+
new_message_author_attribute = self.project.attribute.new(default_schema)
34+
self.project.attribute.update(
35+
new_message_author_attribute,
36+
prompt="Author",
37+
kind="text",
38+
name="message_author",
39+
is_global = True,
40+
global_type = 'file'
41+
)
42+
43+
if message_time_attribute is None:
44+
new_message_time_attribute = self.project.attribute.new(default_schema)
45+
self.project.attribute.update(
46+
new_message_time_attribute,
47+
prompt="Time",
48+
kind="time",
49+
name="message_time",
50+
is_global = True,
51+
global_type = 'file'
52+
)
53+
54+
if message_date_attribute is None:
55+
new_message_date_attribute = self.project.attribute.new(default_schema)
56+
self.project.attribute.update(
57+
new_message_date_attribute,
58+
prompt="Date",
59+
kind="date",
60+
name="message_date",
61+
is_global = True,
62+
global_type = 'file'
63+
)
64+
1465
def add_message(self, message_file, author=None, time=None, date=None):
1566
message_meta = {
1667
"author": author,

sdk/diffgram/schema/attribute.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def update(self,
3333
attribute,
3434
prompt,
3535
kind,
36+
name = None,
3637
is_global = False,
3738
label_file_list = None,
3839
global_type = 'file'
@@ -42,6 +43,7 @@ def update(self,
4243
"group_id": attribute['attribute_template_group']['id'],
4344
"mode": "UPDATE",
4445
"prompt": prompt,
46+
"name": name,
4547
"kind": kind,
4648
"is_global": is_global,
4749
"label_file_list": label_file_list,

0 commit comments

Comments
 (0)