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