mirror of
https://github.com/cwinfo/powerdns-admin.git
synced 2024-11-08 22:50:26 +00:00
Add 'default_record_table_size' setting to allow changing table size.
Fixes #36.
This commit is contained in:
parent
29094b04ea
commit
39564f9c6e
@ -1052,4 +1052,22 @@ class Setting(db.Model):
|
|||||||
logging.error('Cannot toggle setting %s' % setting)
|
logging.error('Cannot toggle setting %s' % setting)
|
||||||
logging.debug(traceback.format_exec())
|
logging.debug(traceback.format_exec())
|
||||||
db.session.rollback()
|
db.session.rollback()
|
||||||
|
return False
|
||||||
|
|
||||||
|
def set(self, setting, value):
|
||||||
|
setting = str(setting)
|
||||||
|
new_value = str(value)
|
||||||
|
current_setting = Setting.query.filter(Setting.name==setting).first()
|
||||||
|
try:
|
||||||
|
if current_setting:
|
||||||
|
current_setting.value = new_value
|
||||||
|
db.session.commit()
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
logging.error('Setting %s does not exist' % setting)
|
||||||
|
return False
|
||||||
|
except:
|
||||||
|
logging.error('Cannot edit setting %s' % setting)
|
||||||
|
logging.debug(traceback.format_exec())
|
||||||
|
db.session.rollback()
|
||||||
return False
|
return False
|
@ -33,15 +33,19 @@
|
|||||||
{% for setting in settings %}
|
{% for setting in settings %}
|
||||||
<tr class="odd ">
|
<tr class="odd ">
|
||||||
<td>{{ setting.name }}</td>
|
<td>{{ setting.name }}</td>
|
||||||
|
{% if setting.value == "True" or setting.value == "False" %}
|
||||||
<td>{{ setting.value }}</td>
|
<td>{{ setting.value }}</td>
|
||||||
|
{% else %}
|
||||||
|
<td><input name="value" id="value" value="{{ setting.value }}"></td>
|
||||||
|
{% endif %}
|
||||||
<td width="6%">
|
<td width="6%">
|
||||||
{% if setting.value == "True" or setting.value == "False" %}
|
{% if setting.value == "True" or setting.value == "False" %}
|
||||||
<button type="button" class="btn btn-flat btn-warning setting-toggle-button" id="{{ setting.name }}">
|
<button type="button" class="btn btn-flat btn-warning setting-toggle-button" id="{{ setting.name }}">
|
||||||
Toggle <i class="fa fa-info"></i>
|
Toggle <i class="fa fa-info"></i>
|
||||||
</button>
|
</button>
|
||||||
{% else %}
|
{% else %}
|
||||||
<button type="button" class="btn btn-flat btn-warning setting-edit-button" id="{{ setting.name }}">
|
<button type="button" class="btn btn-flat btn-warning setting-save-button" id="{{ setting.name }}">
|
||||||
Edit <i class="fa fa-info"></i>
|
Save <i class="fa fa-info"></i>
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
@ -76,10 +80,11 @@
|
|||||||
applyChanges('','/admin/setting/' + setting + '/toggle', false, true)
|
applyChanges('','/admin/setting/' + setting + '/toggle', false, true)
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: allow editing of value field
|
$(".setting-save-button").click(function() {
|
||||||
$(".setting-edit-button").click(function() {
|
|
||||||
var setting = $(this).prop('id');
|
var setting = $(this).prop('id');
|
||||||
applyChanges('','/admin/setting/' + setting + '/edit', false, true)
|
var value = $(this).parents('tr').find('#value')[0].value;
|
||||||
|
var postdata = {'value': value};
|
||||||
|
applyChanges(postdata, '/admin/setting/' + setting + '/edit', false, true)
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -132,9 +132,14 @@
|
|||||||
"ordering" : true,
|
"ordering" : true,
|
||||||
"info" : true,
|
"info" : true,
|
||||||
"autoWidth" : false,
|
"autoWidth" : false,
|
||||||
|
{% if default_record_table_size_setting in ['5','15','20'] %}
|
||||||
"lengthMenu": [ [5, 15, 20, -1],
|
"lengthMenu": [ [5, 15, 20, -1],
|
||||||
[5, 15, 20, "All"]],
|
[5, 15, 20, "All"]],
|
||||||
"pageLength": 15,
|
{% else %}
|
||||||
|
"lengthMenu": [ [5, 15, 20, {{ default_record_table_size_setting }}, -1],
|
||||||
|
[5, 15, 20, {{ default_record_table_size_setting }}, "All"]],
|
||||||
|
{% endif %}
|
||||||
|
"pageLength": {{ default_record_table_size_setting }},
|
||||||
"language": {
|
"language": {
|
||||||
"lengthMenu": " _MENU_ records"
|
"lengthMenu": " _MENU_ records"
|
||||||
},
|
},
|
||||||
|
18
app/views.py
18
app/views.py
@ -27,6 +27,11 @@ def inject_record_helper_setting():
|
|||||||
record_helper_setting = Setting.query.filter(Setting.name == 'record_helper').first()
|
record_helper_setting = Setting.query.filter(Setting.name == 'record_helper').first()
|
||||||
return dict(record_helper_setting=strtobool(record_helper_setting.value))
|
return dict(record_helper_setting=strtobool(record_helper_setting.value))
|
||||||
|
|
||||||
|
@app.context_processor
|
||||||
|
def inject_default_record_table_size_setting():
|
||||||
|
default_record_table_size_setting = Setting.query.filter(Setting.name == 'default_record_table_size').first()
|
||||||
|
return dict(default_record_table_size_setting=default_record_table_size_setting.value)
|
||||||
|
|
||||||
# START USER AUTHENTICATION HANDLER
|
# START USER AUTHENTICATION HANDLER
|
||||||
@app.before_request
|
@app.before_request
|
||||||
def before_request():
|
def before_request():
|
||||||
@ -508,6 +513,19 @@ def admin_settings_toggle(setting):
|
|||||||
else:
|
else:
|
||||||
return make_response(jsonify( { 'status': 'error', 'msg': 'Unable to toggle setting.' } ), 500)
|
return make_response(jsonify( { 'status': 'error', 'msg': 'Unable to toggle setting.' } ), 500)
|
||||||
|
|
||||||
|
@app.route('/admin/setting/<string:setting>/edit', methods=['POST'])
|
||||||
|
@login_required
|
||||||
|
@admin_role_required
|
||||||
|
def admin_settings_edit(setting):
|
||||||
|
pdata = request.data
|
||||||
|
jdata = json.loads(pdata)
|
||||||
|
new_value = jdata['value']
|
||||||
|
result = Setting().set(setting, new_value)
|
||||||
|
if (result):
|
||||||
|
return make_response(jsonify( { 'status': 'ok', 'msg': 'Toggled setting successfully.' } ), 200)
|
||||||
|
else:
|
||||||
|
return make_response(jsonify( { 'status': 'error', 'msg': 'Unable to toggle setting.' } ), 500)
|
||||||
|
|
||||||
@app.route('/user/profile', methods=['GET', 'POST'])
|
@app.route('/user/profile', methods=['GET', 'POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def user_profile():
|
def user_profile():
|
||||||
|
@ -12,11 +12,13 @@ user_role = Role('User', 'User')
|
|||||||
maintenance_setting = Setting('maintenance', 'False')
|
maintenance_setting = Setting('maintenance', 'False')
|
||||||
fullscreen_layout_setting = Setting('fullscreen_layout', 'True')
|
fullscreen_layout_setting = Setting('fullscreen_layout', 'True')
|
||||||
record_helper_setting = Setting('record_helper', 'True')
|
record_helper_setting = Setting('record_helper', 'True')
|
||||||
|
default_table_size_setting = Setting('default_table_size', '15')
|
||||||
db.session.add(admin_role)
|
db.session.add(admin_role)
|
||||||
db.session.add(user_role)
|
db.session.add(user_role)
|
||||||
db.session.add(maintenance_setting)
|
db.session.add(maintenance_setting)
|
||||||
db.session.add(fullscreen_layout_setting)
|
db.session.add(fullscreen_layout_setting)
|
||||||
db.session.add(record_helper_setting)
|
db.session.add(record_helper_setting)
|
||||||
|
db.session.add(default_table_size_setting)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
if not os.path.exists(SQLALCHEMY_MIGRATE_REPO):
|
if not os.path.exists(SQLALCHEMY_MIGRATE_REPO):
|
||||||
api.create(SQLALCHEMY_MIGRATE_REPO, 'database repository')
|
api.create(SQLALCHEMY_MIGRATE_REPO, 'database repository')
|
||||||
|
Loading…
Reference in New Issue
Block a user