Mercurial > libervia-backend
comparison src/tools/xml_tools.py @ 993:301b342c697a
core: use of the new core.log module:
/!\ this is a massive refactoring and was largely automated, it probably did bring some bugs /!\
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 19 Apr 2014 19:19:19 +0200 |
parents | 58a57ce5932a |
children | 35048cafb18d |
comparison
equal
deleted
inserted
replaced
992:f51a1895275c | 993:301b342c697a |
---|---|
16 | 16 |
17 # You should have received a copy of the GNU Affero General Public License | 17 # You should have received a copy of the GNU Affero General Public License |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 from sat.core.i18n import _ | 20 from sat.core.i18n import _ |
21 from logging import debug, info, error, warning | 21 from sat.core.log import getLogger |
22 log = getLogger(__name__) | |
22 from xml.dom import minidom, NotFoundErr | 23 from xml.dom import minidom, NotFoundErr |
23 from wokkel import data_form | 24 from wokkel import data_form |
24 from twisted.words.xish import domish | 25 from twisted.words.xish import domish |
25 from sat.core import exceptions | 26 from sat.core import exceptions |
26 | 27 |
44 widget_kwargs = {} | 45 widget_kwargs = {} |
45 if field.fieldType == 'fixed' or field.fieldType is None: | 46 if field.fieldType == 'fixed' or field.fieldType is None: |
46 widget_type = 'text' | 47 widget_type = 'text' |
47 if field.value is None: | 48 if field.value is None: |
48 if field.label is None: | 49 if field.label is None: |
49 warning(_("Fixed field has neither value nor label, ignoring it")) | 50 log.warning(_("Fixed field has neither value nor label, ignoring it")) |
50 field.value = "" | 51 field.value = "" |
51 else: | 52 else: |
52 field.value = field.label | 53 field.value = field.label |
53 field.label = None | 54 field.label = None |
54 widget_args[0] = field.value | 55 widget_args[0] = field.value |
63 elif field.fieldType == 'list-single': | 64 elif field.fieldType == 'list-single': |
64 widget_type = "list" | 65 widget_type = "list" |
65 del widget_args[0] | 66 del widget_args[0] |
66 widget_kwargs["options"] = [(option.value, option.label or option.value) for option in field.options] | 67 widget_kwargs["options"] = [(option.value, option.label or option.value) for option in field.options] |
67 else: | 68 else: |
68 error(u"FIXME FIXME FIXME: Type [%s] is not managed yet by SàT" % field.fieldType) | 69 log.error(u"FIXME FIXME FIXME: Type [%s] is not managed yet by SàT" % field.fieldType) |
69 widget_type = "string" | 70 widget_type = "string" |
70 | 71 |
71 if field.var: | 72 if field.var: |
72 widget_kwargs["name"] = field.var | 73 widget_kwargs["name"] = field.var |
73 | 74 |
129 item_elts = form_xml.elements('jabber:x:data', 'item') | 130 item_elts = form_xml.elements('jabber:x:data', 'item') |
130 | 131 |
131 for item_elt in item_elts: | 132 for item_elt in item_elts: |
132 for elt in item_elt.elements(): | 133 for elt in item_elt.elements(): |
133 if elt.name != 'field': | 134 if elt.name != 'field': |
134 warning("Unexpected tag (%s)" % elt.name) | 135 log.warning("Unexpected tag (%s)" % elt.name) |
135 continue | 136 continue |
136 field = data_form.Field.fromElement(elt) | 137 field = data_form.Field.fromElement(elt) |
137 | 138 |
138 widget_type, widget_args, widget_kwargs = _dataFormField2XMLUIData(field) | 139 widget_type, widget_args, widget_kwargs = _dataFormField2XMLUIData(field) |
139 xmlui.addWidget(widget_type, *widget_args, **widget_kwargs) | 140 xmlui.addWidget(widget_type, *widget_args, **widget_kwargs) |
697 """ | 698 """ |
698 if style is None: | 699 if style is None: |
699 style = set() | 700 style = set() |
700 styles = set(style) | 701 styles = set(style) |
701 if not options: | 702 if not options: |
702 warning(_('empty "options" list')) | 703 log.warning(_('empty "options" list')) |
703 if not styles.issubset(['multi']): | 704 if not styles.issubset(['multi']): |
704 raise exceptions.DataError(_("invalid styles")) | 705 raise exceptions.DataError(_("invalid styles")) |
705 super(ListWidget, self).__init__(xmlui, name, parent) | 706 super(ListWidget, self).__init__(xmlui, name, parent) |
706 self.addOptions(options, selected) | 707 self.addOptions(options, selected) |
707 for style in styles: | 708 for style in styles: |