Anvil Community Forum

Save A Form Layout For Importing

I would like to be able to download/save a form layout (individually) and then re-import it into another project. You can see the layouts when you download a whole project in YAML format. This is the same except just a single form (plus the re-importing bit)

This is not the same as adding a dependency, this is just being able to have a library of predefined forms that you can share locally or even publicly.

And it’s not quite the same as cutting and pasting between projects, firstly because that’s proving a little unreliable right now and secondly because I can’t cut a form to paste & share with someone else.

I guess this could be done using git, but git scares me, and probably a lot of others, too. Having to pull/push on git to get just one new form inserted is…well…I dunno…just sort of … you know …

1 Like

When I first saw the full-project .yaml file, I knew it could be parsed, and there would be great value, for the developer, in doing so.

But putting one back together again? In a form Anvil will accept? No, thanks. I’m here to develop apps, not tools for Anvil developers.

Sad to say, you’re right about Git. Version control should be built as the simplest thing that could possibly work, for the task at hand. Maybe something can be built atop Git, for the desktop, to provide a simple, clear mental model (and safer defaults!), but Git itself is anything but.

To be fair, Git was built as a toolkit, to allow solving a vastly larger and more complex problem, with thousands of times as many files, folders, and contributors. The toolkit aspect is no doubt what allowed Anvil to incorporate limited version control into its IDE.

I adopted Git anyway, because it’s (currently) the only way to

  1. do Search and Replace (the simplest refactoring) across both source code (.py) and forms (.yaml)
  2. use intra- and inter-project file-comparison tools like WinMerge. (This is critical when you have both a Development version and a Production version, as two separate Anvil apps.)
  3. copy entire forms from one project to another (your use-case)
  4. retain additional files (e.g., supporting code, data, and docs) in the project’s folder tree

Git’s anything but foolproof. I still get commands out-of-order. I still screw up a .yaml file here or there, making my entire project un-loadable. But by keeping local backups, I can recover from that, even without understanding the guts of Git.

Overall, even with a bare-bones Git learning curve, the tradeoffs have saved me time. Obviously, a simple, straightforward version-control system would have netted me much more time.

I’m very much in favor of your suggestion. Unlike Git, it very much fits Anvil’s philosophy of keeping things as simple as possible (but no simpler).

1 Like

I agree with you both.

I use Anvil because it takes care of many things for me and makes my life easier. But I also like to know that sometimes, when the Anvil magic doesn’t work, there are more or less hacky alternatives. Using SQL to go farther than the offical app_tables interface is not as hacky as using git for digging in the yaml files, but I use them both because they do the job.

I’m here only to add that I use PyCharm as my git interface.

I create one folder per app, clone both the development and the production apps in subfolders of the app folder and create a project in PyCharm using the app folder as reference. Then I add other folders with their own repositories for uplink scripts or Excel macros.

PyCharm will show all the git repositories in all the subfolders as one big repository, allows me to diff files of different repositories (instead of using WinMerge) and allows me to use git without knowing how to use git.

Here is an example of what I see in PyCharm with an app folder with 4 repository subfolders:


I need to look at using git & get over the fear :slight_smile:

I don’t expect Anvil will add the feature any time soon, but I wanted to at least get it out there.