Spaces:
Runtime error
Runtime error
Dmitry Kirsanov commited on
Commit ·
1b5739d
1
Parent(s): 6e287b6
comments
Browse files
fad.py
CHANGED
|
@@ -32,14 +32,19 @@ class Fad:
|
|
| 32 |
self.properties["value"] = value
|
| 33 |
|
| 34 |
def get(self, name=None):
|
| 35 |
-
value = self.properties[name if name is not None else "value"]
|
| 36 |
-
if isinstance(value, int): # any int value is supposed to be a ref to id
|
| 37 |
-
return self.parentfad.notes[value].get() # so we pass it to the target mark, recursively
|
| 38 |
elif isinstance(value, list):
|
| 39 |
return ", ".join([(self.parentfad.notes[v].get() if isinstance(v, int) else v) for v in value if v]) # do the same for each element in list
|
| 40 |
else:
|
| 41 |
return value
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
def set(self, name, value):
|
| 44 |
if isinstance(value, int): # any int value is supposed to be a ref to id
|
| 45 |
assert(value in self.parentfad.notes.keys()) # so we ensure this id exists
|
|
@@ -167,18 +172,18 @@ class Fad:
|
|
| 167 |
|
| 168 |
def set_property_to_mark(self, fad, notetype, mark_n, property, value, valuetype, startfrom=0):
|
| 169 |
noteid = self.get_note_for_mark_n(fad, notetype, mark_n, startfrom)
|
| 170 |
-
if valuetype != None:
|
| 171 |
id = self.get_note_by_value(value, valuetype)
|
| 172 |
self.notes[noteid].set(property, id)
|
| 173 |
-
else:
|
| 174 |
self.notes[noteid].set(property, value)
|
| 175 |
|
| 176 |
def add_property_to_mark(self, fad, notetype, mark_n, property, value, valuetype, startfrom=0):
|
| 177 |
noteid = self.get_note_for_mark_n(fad, notetype, mark_n, startfrom)
|
| 178 |
-
if valuetype != None:
|
| 179 |
id = self.get_note_by_value(value, valuetype)
|
| 180 |
self.notes[noteid].add(property, id)
|
| 181 |
-
else:
|
| 182 |
self.notes[noteid].add(property, value)
|
| 183 |
|
| 184 |
|
|
|
|
| 32 |
self.properties["value"] = value
|
| 33 |
|
| 34 |
def get(self, name=None):
|
| 35 |
+
value = self.properties[name if name is not None else "value"] # "value" is default property
|
| 36 |
+
if isinstance(value, int): # any int value is supposed to be a ref to id; if you need to store numbers, use floats
|
| 37 |
+
return self.parentfad.notes[value].get() # so we pass it to the target mark, recursively, but without name: target note gives us just its value
|
| 38 |
elif isinstance(value, list):
|
| 39 |
return ", ".join([(self.parentfad.notes[v].get() if isinstance(v, int) else v) for v in value if v]) # do the same for each element in list
|
| 40 |
else:
|
| 41 |
return value
|
| 42 |
|
| 43 |
+
def set(self, value):
|
| 44 |
+
if isinstance(value, int): # any int value is supposed to be a ref to id
|
| 45 |
+
assert(value in self.parentfad.notes.keys()) # so we ensure this id exists
|
| 46 |
+
self.properties["value"] = value
|
| 47 |
+
|
| 48 |
def set(self, name, value):
|
| 49 |
if isinstance(value, int): # any int value is supposed to be a ref to id
|
| 50 |
assert(value in self.parentfad.notes.keys()) # so we ensure this id exists
|
|
|
|
| 172 |
|
| 173 |
def set_property_to_mark(self, fad, notetype, mark_n, property, value, valuetype, startfrom=0):
|
| 174 |
noteid = self.get_note_for_mark_n(fad, notetype, mark_n, startfrom)
|
| 175 |
+
if valuetype != None: # we're setting value to ref to a note whose type is valuetype
|
| 176 |
id = self.get_note_by_value(value, valuetype)
|
| 177 |
self.notes[noteid].set(property, id)
|
| 178 |
+
else: # we're setting leaf string value to property
|
| 179 |
self.notes[noteid].set(property, value)
|
| 180 |
|
| 181 |
def add_property_to_mark(self, fad, notetype, mark_n, property, value, valuetype, startfrom=0):
|
| 182 |
noteid = self.get_note_for_mark_n(fad, notetype, mark_n, startfrom)
|
| 183 |
+
if valuetype != None: # we're setting value to ref to a note whose type is valuetype
|
| 184 |
id = self.get_note_by_value(value, valuetype)
|
| 185 |
self.notes[noteid].add(property, id)
|
| 186 |
+
else: # we're setting leaf string value to property
|
| 187 |
self.notes[noteid].add(property, value)
|
| 188 |
|
| 189 |
|