mirror of
https://github.com/cwinfo/powerdns-admin.git
synced 2024-11-09 15:10:27 +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.debug(traceback.format_exec())
|
||||
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
|
@ -33,15 +33,19 @@
|
||||
{% for setting in settings %}
|
||||
<tr class="odd ">
|
||||
<td>{{ setting.name }}</td>
|
||||
{% if setting.value == "True" or setting.value == "False" %}
|
||||
<td>{{ setting.value }}</td>
|
||||
{% else %}
|
||||
<td><input name="value" id="value" value="{{ setting.value }}"></td>
|
||||
{% endif %}
|
||||
<td width="6%">
|
||||
{% if setting.value == "True" or setting.value == "False" %}
|
||||
<button type="button" class="btn btn-flat btn-warning setting-toggle-button" id="{{ setting.name }}">
|
||||
Toggle <i class="fa fa-info"></i>
|
||||
</button>
|
||||
{% else %}
|
||||
<button type="button" class="btn btn-flat btn-warning setting-edit-button" id="{{ setting.name }}">
|
||||
Edit <i class="fa fa-info"></i>
|
||||
<button type="button" class="btn btn-flat btn-warning setting-save-button" id="{{ setting.name }}">
|
||||
Save <i class="fa fa-info"></i>
|
||||
</button>
|
||||
{% endif %}
|
||||
</td>
|
||||
@ -76,10 +80,11 @@
|
||||
applyChanges('','/admin/setting/' + setting + '/toggle', false, true)
|
||||
});
|
||||
|
||||
// TODO: allow editing of value field
|
||||
$(".setting-edit-button").click(function() {
|
||||
$(".setting-save-button").click(function() {
|
||||
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>
|
||||
{% endblock %}
|
||||
|
@ -132,9 +132,14 @@
|
||||
"ordering" : true,
|
||||
"info" : true,
|
||||
"autoWidth" : false,
|
||||
{% if default_record_table_size_setting in ['5','15','20'] %}
|
||||
"lengthMenu": [ [5, 15, 20, -1],
|
||||
[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": {
|
||||
"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()
|
||||
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
|
||||
@app.before_request
|
||||
def before_request():
|
||||
@ -508,6 +513,19 @@ def admin_settings_toggle(setting):
|
||||
else:
|
||||
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'])
|
||||
@login_required
|
||||
def user_profile():
|
||||
|
@ -12,11 +12,13 @@ user_role = Role('User', 'User')
|
||||
maintenance_setting = Setting('maintenance', 'False')
|
||||
fullscreen_layout_setting = Setting('fullscreen_layout', '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(user_role)
|
||||
db.session.add(maintenance_setting)
|
||||
db.session.add(fullscreen_layout_setting)
|
||||
db.session.add(record_helper_setting)
|
||||
db.session.add(default_table_size_setting)
|
||||
db.session.commit()
|
||||
if not os.path.exists(SQLALCHEMY_MIGRATE_REPO):
|
||||
api.create(SQLALCHEMY_MIGRATE_REPO, 'database repository')
|
||||
|
Loading…
Reference in New Issue
Block a user