Browse Source

feature: dump and load data

master
Lucas 3 weeks ago
parent
commit
ad601a3202
  1. 14
      lua/django/input.lua
  2. 14
      lua/django/mappings.lua
  3. 34
      lua/django/utils.lua

14
lua/django/input.lua

@ -31,6 +31,10 @@ local defaults = {
}, },
border = { border = {
style = 'rounded', style = 'rounded',
text = {
top="",
top_align="left"
}
}, },
win_options = { win_options = {
winhighlight = 'Normal:Normal,FloatBorder:FloatBorder', winhighlight = 'Normal:Normal,FloatBorder:FloatBorder',
@ -99,8 +103,14 @@ M.setup = function(config, input_opts, callback)
} }
end end
M.open = function(opts, callback) M.open = function(opts, popup_opts, callback)
local ui = M.setup(state.user_opts, opts, callback) local pop_opts = defaults.popup
state.user_opts = {}
if popup_opts ~= nil or popup_opts == {} then
pop_opts = popup_opts
end
local state_user_opts = fn.merge(state.user_opts, pop_opts)
local ui = M.setup(state_user_opts, opts, callback)
fn.check_nvim() fn.check_nvim()
M.inp = require('nui.input')(ui.popup, ui.input) M.inp = require('nui.input')(ui.popup, ui.input)

14
lua/django/mappings.lua

@ -9,6 +9,20 @@ local mappings = {
end, end,
desc = "create app", desc = "create app",
}, },
["<leader>jd"] = {
function()
django.dump_data()
end,
desc = "dump data",
},
["<leader>jo"] = {
function()
django.load_data()
end,
desc = "load data",
},
["<leader>jp"] = { ["<leader>jp"] = {
function() function()
django.create_package() django.create_package()

34
lua/django/utils.lua

@ -185,11 +185,11 @@ local function env_ip(ip)
end end
function M.create_app() function M.create_app()
inp.open({ prompt = "create app: " }, perform_create_app) inp.open({ prompt = "create app: " },{},perform_create_app)
end end
function M.create_package() function M.create_package()
inp.open({ prompt = "create package: " }, perform_create_package) inp.open({ prompt = "create package: " },{}, perform_create_package)
end end
function M.create_env_file(opts) function M.create_env_file(opts)
@ -283,5 +283,35 @@ function M.compile_messages()
toggleterm.exec("./manage.py compilemessages", term_num, 100, ".", "float", "compile_messages", false) toggleterm.exec("./manage.py compilemessages", term_num, 100, ".", "float", "compile_messages", false)
end end
local function perform_dump_data(value)
local term_num = 13
toggleterm.exec(
"./manage.py dumpdata --natural-foreign --natural-primary -e contenttypes -e auth.Permission -e sessions.session -e admin.logentry --indent 2 > " .. value .. ".json",
term_num,
100,
".",
"float",
"dump_data",
false
)
end
local function perform_load_data(value)
local term_num = 14
toggleterm.exec("./manage.py loaddata" .. value .. ".json", term_num, 100, ".", "float", "load_data", false)
end
function M.dump_data()
inp.open({ prompt = "name: ", default_value ="dump_db"},
{popup = {border = {text = {top ="Dump data", top_align="left"}}}},
perform_dump_data)
end
function M.load_data()
inp.open({ prompt = "name: ", default_value = "dump_db"},
{ popup = {border = {text = {top ="Load data", top_align="left"}}}},
perform_load_data)
end
return M return M

Loading…
Cancel
Save