From 33abeb1acaf6edc1a468f1ba80af880a1184e492 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 5 Mar 2022 09:12:01 -0600 Subject: [PATCH] Improve the Poser Setup page; allow poser dir refresh --- tailbone/templates/poser/setup.mako | 136 +++++++++++++++++++++------- tailbone/views/common.py | 64 +++++++++++-- 2 files changed, 160 insertions(+), 40 deletions(-) diff --git a/tailbone/templates/poser/setup.mako b/tailbone/templates/poser/setup.mako index 18fda0d7..8d01bb33 100644 --- a/tailbone/templates/poser/setup.mako +++ b/tailbone/templates/poser/setup.mako @@ -6,42 +6,116 @@ <%def name="page_content()">
-

- Before you can use Poser features, ${app_title} must create the - file structure for it. -

+ % if not poser_dir_exists: -

- A new folder will be created at this location:    - - ${poser_dir} - -

+

+ Before you can use Poser features, ${app_title} must create the + file structure for it. +

-

- Once set up, ${app_title} can generate code for certain features, - in the Poser folder.  You can then access these features from - within ${app_title}. -

+

+ A new folder will be created at this location:    + + ${poser_dir} + +

-

- You are free to edit most files in the Poser folder as well.  - When you do so ${app_title} should pick up on the changes with no - need for app restart. -

+

+ Once set up, ${app_title} can generate code for certain features, + in the Poser folder.  You can then access these features from + within ${app_title}. +

-

- Proceed? -

+

+ You are free to edit most files in the Poser folder as well.  + When you do so ${app_title} should pick up on the changes with no + need for app restart. +

- ${h.form(request.current_route_url(), **{'@submit': 'setupSubmitting = true'})} - ${h.csrf_token(request)} - - {{ setupSubmitting ? "Working, please wait..." : "Go for it!" }} - - ${h.end_form()} +

+ Proceed? +

+ + ${h.form(request.current_route_url(), **{'@submit': 'setupSubmitting = true'})} + ${h.csrf_token(request)} + + {{ setupSubmitting ? "Working, please wait..." : "Go for it!" }} + + ${h.end_form()} + + % else: + +

Root Folder

+ +

+ Poser folder already exists at:    + + ${poser_dir} + +

+ + ${h.form(request.current_route_url(), class_='block', **{'@submit': 'setupSubmitting = true'})} + ${h.csrf_token(request)} + ${h.hidden('action', value='refresh')} + + {{ setupSubmitting ? "Working, please wait..." : "Refresh Folder" }} + + ${h.end_form()} + +

Modules

+ + + + % endif <%def name="modify_this_page_vars()"> diff --git a/tailbone/views/common.py b/tailbone/views/common.py index 3f846f75..1a0567e5 100644 --- a/tailbone/views/common.py +++ b/tailbone/views/common.py @@ -26,6 +26,7 @@ Various common views from __future__ import unicode_literals, absolute_import +import os import six from rattail.db import model @@ -206,22 +207,67 @@ class CommonView(View): app = self.get_rattail_app() app_title = self.rattail_config.app_title() poser_handler = app.get_poser_handler() + poser_dir = poser_handler.get_default_poser_dir() + poser_dir_exists = os.path.isdir(poser_dir) if self.request.method == 'POST': - try: - path = poser_handler.make_poser_dir() - except Exception as error: - self.request.session.flash(simple_error(error), 'error') - else: - self.request.session.flash("Poser folder created at: {}".format(path)) - self.request.session.flash("Please restart the web app!", 'warning') - return self.redirect(self.request.route_url('home')) + + # maybe refresh poser dir + if self.request.POST.get('action') == 'refresh': + poser_handler.refresh_poser_dir() + self.request.session.flash("Poser folder has been refreshed.") + + else: # otherwise make poser dir + + if poser_dir_exists: + self.request.session.flash("Poser folder already exists!", 'error') + else: + try: + path = poser_handler.make_poser_dir() + except Exception as error: + self.request.session.flash(simple_error(error), 'error') + else: + self.request.session.flash("Poser folder created at: {}".format(path)) + self.request.session.flash("Please restart the web app!", 'warning') + return self.redirect(self.request.route_url('home')) + + try: + from poser import reports + reports_error = None + except Exception as error: + reports = None + reports_error = simple_error(error) + + try: + from poser.web import views + views_error = None + except Exception as error: + views = None + views_error = simple_error(error) + + try: + import poser + poser_error = None + except Exception as error: + poser = None + poser_error = simple_error(error) return { 'use_buefy': use_buefy, 'app_title': app_title, 'index_title': app_title, - 'poser_dir': poser_handler.get_default_poser_dir(), + 'poser_dir': poser_dir, + 'poser_dir_exists': poser_dir_exists, + 'poser_imported': { + 'poser': poser, + 'reports': reports, + 'views': views, + }, + 'poser_import_errors': { + 'poser': poser_error, + 'reports': reports_error, + 'views': views_error, + }, } @classmethod