mirror of https://github.com/fmartingr/iosfu.git
Added backup settings on GUI: Name, notes and enable/disable global cache. Tap #13
This commit is contained in:
parent
0ed6820d77
commit
64b53b4be6
|
@ -45,9 +45,6 @@ class Backup(object):
|
|||
# Backup id
|
||||
id = None
|
||||
|
||||
# Backup name (settings)
|
||||
name = None
|
||||
|
||||
# Backup path
|
||||
path = None
|
||||
|
||||
|
@ -80,6 +77,11 @@ class Backup(object):
|
|||
self.init_check()
|
||||
self.read_data_file()
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
name = self.data('name') or self.id
|
||||
return name
|
||||
|
||||
def get_data_file(self):
|
||||
return "{}.iosfu".format(self.path)
|
||||
|
||||
|
@ -103,7 +105,6 @@ class Backup(object):
|
|||
Get all the basic info for the backup
|
||||
"""
|
||||
self.id = basename(self.path)
|
||||
self.name = self.id
|
||||
|
||||
# Check all files
|
||||
for filename in listdir(self.path):
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from flask import Flask, session, render_template, redirect, url_for, flash, \
|
||||
render_template_string
|
||||
render_template_string, request
|
||||
|
||||
from iosfu.plugin.library import Library
|
||||
from iosfu.gui.core import GUIController
|
||||
|
@ -28,8 +28,15 @@ backup_manager.lookup()
|
|||
# CONTEXT
|
||||
#
|
||||
@server.context_processor
|
||||
def backup_list():
|
||||
return dict(backups=backup_manager.backups)
|
||||
def backup():
|
||||
if 'backup' in session:
|
||||
current_backup = backup_manager.backups[session['backup']]
|
||||
else:
|
||||
current_backup = None
|
||||
return dict(
|
||||
backups=backup_manager.backups,
|
||||
current_backup=current_backup
|
||||
)
|
||||
|
||||
|
||||
@server.context_processor
|
||||
|
@ -127,3 +134,31 @@ def select_backup(backup_id):
|
|||
flash('The backup you selected was not found.', 'danger')
|
||||
|
||||
return redirect(url_for('main'))
|
||||
|
||||
|
||||
@server.route("/backup/", methods=['get', 'post'])
|
||||
def backup_data():
|
||||
if 'backup' in session:
|
||||
backup = backup_manager.backups[session['backup']]
|
||||
|
||||
# Handle form
|
||||
if request.method == 'POST':
|
||||
backup.data('name', request.form.get('name', ''))
|
||||
backup.data('notes', request.form.get('notes', ''))
|
||||
cache_enabled = request.form.get('cache_enabled', False)
|
||||
backup.data('cache.enabled', cache_enabled == 'on')
|
||||
backup.write_data_file()
|
||||
flash('Settings saved!', 'success')
|
||||
|
||||
# Context
|
||||
ctx = {
|
||||
'backup_info': {
|
||||
'name': backup.data('name'),
|
||||
'notes': backup.data('notes'),
|
||||
'cache_enabled': backup.data('cache.enabled')
|
||||
}
|
||||
}
|
||||
return render_template('backup/settings.jinja', **ctx)
|
||||
else:
|
||||
flash('No backup is selected.', 'danger')
|
||||
redirect(url_for('main'))
|
||||
|
|
|
@ -42,7 +42,8 @@
|
|||
<!-- Right -->
|
||||
<p class="navbar-text navbar-right">
|
||||
{% if session.backup %}
|
||||
{{ session.backup }}
|
||||
<a href="/backup/"><span class="glyphicon glyphicon-wrench"></span></a>
|
||||
{{ current_backup.name }}
|
||||
{% endif %}
|
||||
</p>
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
{% extends "_layout.jinja" %}
|
||||
|
||||
{% block content %}
|
||||
<form class="form-horizontal row" role="form" method="post" action="/backup/">
|
||||
<div class="col-lg-8">
|
||||
<h2>General</h2>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">
|
||||
Name
|
||||
</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" class="form-control" name="name" value="{{ backup_info.name or '' }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">
|
||||
Notes
|
||||
</label>
|
||||
<div class="col-sm-10">
|
||||
<textarea name="notes" class="form-control" rows="10">{{ backup_info.notes or '' }}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-4">
|
||||
<h2>Cache</h2>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">
|
||||
Enable?
|
||||
</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="checkbox" name="cache_enabled"
|
||||
{% if backup_info.cache_enabled %}
|
||||
checked="checked"
|
||||
{% endif %}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary btn-block">
|
||||
Save
|
||||
</button>
|
||||
</form>
|
||||
{% endblock %}
|
Loading…
Reference in New Issue