-
Notifications
You must be signed in to change notification settings - Fork 308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to modify database from external script? #1149
Comments
@CtrlC-Root From your code sample, it looks like you're looking to update flowblock data. Lektors flowblock-editing code is kinda hokey right now in that half of the serialization/deserialization of The EditorSession, from In the normal Admin GUI editing flow, parsing and serialization of flow data happens in the Admin frontend (JavaScript). (See FlowWidget, etc.) On the Python side, FlowType and friends know how to parse and render the flow data, but do not know how to serialize flowblock data. I don't think there is currently any Python code in Lektor to help with flow data serialization. For a one-off, it probably wouldn't be too hard to roll-your-own. ([Here's)(https://github.com/lektor/lektor/blob/05ba62fff422dc7ec75fb958085eeb2e09d7b69f/frontend/js/widgets/flow/metaformat.tsx#L74) the javascript code that does what's needed.) In the long term, I think it would be good to move the de/serialzation of flow data to the Python side. Doing it cleanly will take some thought and planning, however. |
Indeed, many of the automated changes I want to make involve flow blocks.
I did inspect the HTTP requests sent from the frontend to the backend while modifing a flow field and saw it was sending the entire serialized content of the field to the
Thank you for the links! Yeah, I'll end up implementing something in my scripts to do this. If this functionality were to exist in Lektor do you know where it would be or how it would look? I ask because if I can write mine that way up front then it should be easier to make a PR for it later.
I agree with regards to refactoring the existing code but I think having CRUD access to the database through Lektor APIs, even if it's not used by the frontend, would be useful as an interim step. Obviously if there was support for other formats, which already have tooling available, that would sidestep the entire issue. |
I'm not sure. I think it's complicated and messy. My first thought (which could easily be wrong) is that code to de/serialize the flowblock data for editing belongs in lektor.editor.EditorSession (and its friends
If I'm envisioning being able to do something like:
My guess is that it will take a fair amount of work to implement this cleanly. |
I'd like to modify the database content from an external script. I've looked through the documentation, open issues, closed issues, and started reading the code to figure out how to do this. I'm posting here asking for help in case there is some really obvious way to do this I've missed in my search so far. Example:
I made up an arbitrary example of a DB modification above because the more in-depth changes I plan to make are not relevant here as far as I can tell. I'll keep reading the source code to see if I can figure it out but in the meantime if someone knows how to do this or can point me in the right direction I would really appreciate it.
P.S. I really enjoy using Lektor so thank you to everyone who has contributed to make this awesome tool!
The text was updated successfully, but these errors were encountered: