##// END OF EJS Templates
schema: preparer should keep case by default.
marcink -
r1244:1975437d stable
parent child Browse files
Show More
@@ -1,88 +1,88 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2016-2016 RhodeCode GmbH
3 # Copyright (C) 2016-2016 RhodeCode GmbH
4 #
4 #
5 # This program is free software: you can redistribute it and/or modify
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
7 # (only), as published by the Free Software Foundation.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU Affero General Public License
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
16 #
17 # This program is dual-licensed. If you wish to learn more about the
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
20
21 import unicodedata
21 import unicodedata
22
22
23
23
24 def strip_preparer(value):
24 def strip_preparer(value):
25 """
25 """
26 strips given values using .strip() function
26 strips given values using .strip() function
27 """
27 """
28
28
29 if value:
29 if value:
30 value = value.strip()
30 value = value.strip()
31 return value
31 return value
32
32
33
33
34 def slugify_preparer(value):
34 def slugify_preparer(value, keep_case=True):
35 """
35 """
36 Slugify given value to a safe representation for url/id
36 Slugify given value to a safe representation for url/id
37 """
37 """
38 from rhodecode.lib.utils import repo_name_slug
38 from rhodecode.lib.utils import repo_name_slug
39 if value:
39 if value:
40 value = repo_name_slug(value.lower())
40 value = repo_name_slug(value if keep_case else value.lower())
41 return value
41 return value
42
42
43
43
44 def non_ascii_strip_preparer(value):
44 def non_ascii_strip_preparer(value):
45 """
45 """
46 trie to replace non-ascii letters to their ascii representation
46 trie to replace non-ascii letters to their ascii representation
47 eg::
47 eg::
48
48
49 `ΕΌoΕ‚w` converts into `zolw`
49 `ΕΌoΕ‚w` converts into `zolw`
50 """
50 """
51 if value:
51 if value:
52 value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore')
52 value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore')
53 return value
53 return value
54
54
55
55
56 def unique_list_preparer(value):
56 def unique_list_preparer(value):
57 """
57 """
58 Converts an list to a list with only unique values
58 Converts an list to a list with only unique values
59 """
59 """
60
60
61 def make_unique(value):
61 def make_unique(value):
62 seen = []
62 seen = []
63 return [c for c in value if
63 return [c for c in value if
64 not (c in seen or seen.append(c))]
64 not (c in seen or seen.append(c))]
65
65
66 if isinstance(value, list):
66 if isinstance(value, list):
67 ret_val = make_unique(value)
67 ret_val = make_unique(value)
68 elif isinstance(value, set):
68 elif isinstance(value, set):
69 ret_val = list(value)
69 ret_val = list(value)
70 elif isinstance(value, tuple):
70 elif isinstance(value, tuple):
71 ret_val = make_unique(value)
71 ret_val = make_unique(value)
72 elif value is None:
72 elif value is None:
73 ret_val = []
73 ret_val = []
74 else:
74 else:
75 ret_val = [value]
75 ret_val = [value]
76
76
77 return ret_val
77 return ret_val
78
78
79
79
80 def unique_list_from_str_preparer(value):
80 def unique_list_from_str_preparer(value):
81 """
81 """
82 Converts an list to a list with only unique values
82 Converts an list to a list with only unique values
83 """
83 """
84 from rhodecode.lib.utils2 import aslist
84 from rhodecode.lib.utils2 import aslist
85
85
86 if isinstance(value, basestring):
86 if isinstance(value, basestring):
87 value = aslist(value, ',')
87 value = aslist(value, ',')
88 return unique_list_preparer(value) No newline at end of file
88 return unique_list_preparer(value)
General Comments 0
You need to be logged in to leave comments. Login now