From 1b6a9956c5c4cab05c7dd078ca649327221f1dc0 Mon Sep 17 00:00:00 2001 From: Christian Lawson-Perfect Date: Thu, 20 Feb 2025 13:04:31 +0000 Subject: [PATCH] Use a default path in the editor When opening a think with no path specified, try some of the most common paths and show the first one that exists. --- thinks/views.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/thinks/views.py b/thinks/views.py index 263c186..e0eb83d 100644 --- a/thinks/views.py +++ b/thinks/views.py @@ -82,6 +82,12 @@ class RemixThinkView(ThinkMixin, generic.UpdateView): class ThinkView(ThinkMixin, generic.DetailView): template_name = "thinks/think.html" + default_paths = [ + 'src/App.elm', + 'script.js', + 'index.html', + ] + def get_context_data(self, *args, **kwargs): context = super().get_context_data(*args, **kwargs) @@ -93,6 +99,12 @@ class ThinkView(ThinkMixin, generic.DetailView): path = think.file_path(strpath) + if path is None: + for f in self.default_paths: + if (root / f).exists(): + path = root / f + break + relpath = path.relative_to(root) if path is not None else None if path is None: