misc: use a more readable conversion of python to css class name (#39314)

This commit is contained in:
Frédéric Péters 2020-01-27 19:04:50 +01:00
parent 01e435d8f5
commit acbcbbc132
3 changed files with 13 additions and 6 deletions

View File

@ -571,12 +571,19 @@ class CellBase(six.with_metaclass(CellMeta, models.Model)):
return ''
@property
def class_name(self):
def legacy_class_name(self):
# legacy class name used in some themes
return self.__class__.__name__.lower()
@property
def class_name(self):
# convert CamelCase Python class name into a lower and dashed version
# appropriate for CSS
return re.sub('([A-Z]+)', r'-\1', self.__class__.__name__).lower()[1:]
@property
def css_class_names(self):
return self.class_name + ' ' + self.extra_css_class
return ' '.join([self.class_name, self.legacy_class_name, self.extra_css_class])
@classmethod
def get_cell_classes(cls, class_filter=lambda x: True):

View File

@ -254,13 +254,13 @@ $(function() {
}
}
$('.cell.tipipaymentformcell select').on('change', function() {
$('.cell.tipi-payment-form-cell select').on('change', function() {
handle_tipi_form($(this));
compute_max_height($(this).parents('div.cell'));
});
$('.cell.tipipaymentformcell select').trigger('change');
$('.cell.tipi-payment-form-cell select').trigger('change');
$('.cell.tipipaymentformcell').on('combo:cellform-reloaded', function() {
$('.cell.tipi-payment-form-cell').on('combo:cellform-reloaded', function() {
var $select = $(this).find('select');
$select.on('change', function() {
handle_tipi_form($select);

View File

@ -399,7 +399,7 @@ def test_config_json_cell():
assert cell.get_label() == 'Foobar'
assert cell.url == 'http://test/'
assert cell.template_name == 'combo/json/foobar.html'
assert cell.css_class_names.split() == ['configjsoncell', 'foobar']
assert cell.css_class_names.split() == ['config-json-cell', 'configjsoncell', 'foobar']
with mock.patch('combo.utils.requests.get') as requests_get:
requests_get.return_value = mock_json_response(content=json.dumps({'hello': 'world'}), status_code=200)