diff --git a/iosfu/backup.py b/iosfu/backup.py index f34ce82..b6a4f74 100644 --- a/iosfu/backup.py +++ b/iosfu/backup.py @@ -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): diff --git a/iosfu/gui/app.py b/iosfu/gui/app.py index 2292226..5bb337e 100644 --- a/iosfu/gui/app.py +++ b/iosfu/gui/app.py @@ -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')) diff --git a/iosfu/gui/templates/_layout.jinja b/iosfu/gui/templates/_layout.jinja index 3b00d35..3e9ab67 100644 --- a/iosfu/gui/templates/_layout.jinja +++ b/iosfu/gui/templates/_layout.jinja @@ -42,7 +42,8 @@