clean code

This commit is contained in:
Pierre-antoine Comby 2020-03-24 23:02:12 +01:00
parent 41568916b8
commit 9f53bda1cd
2 changed files with 25 additions and 21 deletions

View File

@ -56,6 +56,10 @@ class HistoryTable(tables.Table):
def render_valid(self, value): def render_valid(self, value):
return "" if value else "" return "" if value else ""
# function delete_button(id) provided in template file
delete_template = """
<button id="{{ record.pk }}" class="btn btn-danger" onclick="delete_button(this.id)"> {{ delete_trans }}</a>
"""
class AliasTable(tables.Table): class AliasTable(tables.Table):
class Meta: class Meta:
@ -69,13 +73,9 @@ class AliasTable(tables.Table):
show_header = False show_header = False
name = tables.Column(attrs={'td': {'class': 'text-center'}}) name = tables.Column(attrs={'td': {'class': 'text-center'}})
delete = tables.LinkColumn('member:user_alias_delete', delete = tables.TemplateColumn(template_code=delete_template,
args=[A('pk')], extra_context={"delete_trans":_('delete')},
attrs={ attrs={'td':{'class': 'col-sm-1'}})
'td': {'class': 'col-sm-2'},
'a': {'class': 'btn btn-danger'}},
text='delete', accessor='pk')
class ButtonTable(tables.Table): class ButtonTable(tables.Table):
class Meta: class Meta:
attrs = { attrs = {
@ -90,10 +90,16 @@ class ButtonTable(tables.Table):
model = TransactionTemplate model = TransactionTemplate
edit = tables.LinkColumn('note:template_update',
args=[A('pk')],
attrs={
'td': {'class': 'col-sm-1'},
'a': {'class': 'btn btn-primary'}},
text=_('edit'), accessor='pk')
delete = tables.TemplateColumn(template_code=""" delete = tables.TemplateColumn(template_code=delete_template,
<button id="{{ record.pk }}" class="btn btn-danger" onclick="delete_button(this.id)"> delete </a> extra_context={"delete_trans":_('delete')},
""") attrs={'td':{'class':'col-sm-1'}})
def render_amount(self, value): def render_amount(self, value):
return pretty_money(value) return pretty_money(value)

View File

@ -63,15 +63,13 @@ function search_field_moved(secondfield) {
$.ajax({ $.ajax({
url:"/api/note/transaction/template/"+button_id, url:"/api/note/transaction/template/"+button_id,
method:"DELETE", method:"DELETE",
headers: { headers: {"X-CSRFTOKEN": CSRF_TOKEN}
"X-CSRFTOKEN": CSRF_TOKEN })
}, .done(function(){
success: function(){
addMsg('{% trans "button successfully deleted "%}','success'); addMsg('{% trans "button successfully deleted "%}','success');
$("#buttons_table").load('{% url "note:template_list" %} #buttons_tables'); $("#buttons_table").load("{% url 'note:template_list' %} #buttons_table");
}, })
error: addMsg(' {% trans "Unable to delete button "%} #' + button_id,'danger' ) .fail(addMsg(' {% trans "Unable to delete button "%} #' + button_id,'danger' ));
}); }
}
</script> </script>
{% endblock %} {% endblock %}