19
19
from frontend.models.loop import Loop
22
# Default delimiter to separate values from keys in the text field.
23
DEFAULT_DELIMITER = '='
22
26
class TextFieldLoop(Loop):
28
This is the base class model for the loops that want to be a free-form loop
29
with just a text field to insert values.
30
A loop of this kind is not much useful, it needs to be chained with another
33
This model in particular is an abstract model, it is necessary to inherits
24
37
app_label = 'frontend'
26
40
values = models.TextField()
28
42
def schedule_build(self, parameters=None):
31
def parse_values(self):
45
def values_to_dict(self):
47
Returns a dictionary representation of the values inserted. The
48
key<>value pairs are split on DEFAULT_DELIMITER.
50
:return A dictionary of the values inserted.
53
valid, lines = self.valid_values(self.values)
57
key, value = line.split(DEFAULT_DELIMITER)
58
text_to_dict[key.lower()] = value
63
def valid_values(values):
65
Checks if the values inserted by the user are well formed, meaning that
66
each key<>value pair is using the correct delimiter.
68
:param values: the string with all the key<>value pairs, separated with
71
:return a boolean for the validity, and the list of lines.
74
lines = values.splitlines()
76
if DEFAULT_DELIMITER in line: