tweekmonster / django-plus.vim

:guitar: Improvements to the handling of Django related files in Vim
MIT License
179 stars 15 forks source link

improve settings detection #2

Closed aleprovencio closed 8 years ago

aleprovencio commented 8 years ago

Like in the cookiecutter project, the settings structure is arranged this way:

settings/
    common.py
    local.py
    production.py
    test.py
tweekmonster commented 8 years ago

I just looked over the cookiecutter template, and the settings should still be found as long as manage.py is found. Is it not working?

aleprovencio commented 8 years ago

It doesn't seem to, at least b:is_django_settings does not get set. Maybe I'm also not getting the correct form of using settings completions, can you please clear that up for me?

tweekmonster commented 8 years ago

Where is manage.py relative to your settings directory and what's the value of DJANGO_SETTINGS_MODULE in that script? Could you tell me the layout of the project?

aleprovencio commented 8 years ago

This is "vanilla" cookiecutter, where DJANGO_SETTINGS_MODULE points to config.settings.local, organized this way:

...
manage.py
config/
    ...
    settings/
tweekmonster commented 8 years ago

I was asking for your layout (assuming it was slightly different from cookiecutter). Anyways, I made a mistake in my assumption. I think I see why it's not working for you. The completion script is assuming that the scripts are only one directory deep. I misread the source 😅

tweekmonster commented 8 years ago

Could you confirm that this is fixed?

aleprovencio commented 8 years ago

Unfortunately it still does not...Just to make sure I've tested a non-cookiecutter layout which does set b:is_django_settings. However I still wonder what kind of completions I'm able to get from it. Anyways, thank you for your efforts @tweekmonster !

tweekmonster commented 8 years ago

I just tested with an arbitrary path for the settings module. I got the error:

django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.

After setting SECRET_KEY it worked. Maybe there's an error you're just not seeing. You can test the script directly with:

env _DJANGOPLUS_MANAGEMENT=/path/to/manage.py python /path/to/django-plus.vim/bin/completions.py
aleprovencio commented 8 years ago

Really at a loss here, maybe a missing else on your code?

→ env _DJANGOPLUS_MANAGEMENT=manage.py python ~/.vim/plugged/django-plus.vim/bin/completions.py
Traceback (most recent call last):
  File "/home/aleprovencio/.vim/plugged/django-plus.vim/bin/completions.py", line 26, in <module>
    os.environ['DJANGO_SETTINGS_MODULE'] = settings_module
NameError: name 'settings_module' is not defined
tweekmonster commented 8 years ago

Nah, the script assumes that the manage.py script exists. Would you mind posting the contents of manage.py?

tweekmonster commented 8 years ago

Nevermind, I see the problem now. The cookiecutter project uses single quotes instead of double quotes.

aleprovencio commented 8 years ago
env _DJANGOPLUS_MANAGEMENT=manage.py python ~/.vim/plugged/django-plus.vim/bin/completions.py
Traceback (most recent call last):
  File "/home/aleprovencio/.vim/plugged/django-plus.vim/bin/completions.py", line 31, in <module>
    os.chdir(base)
OSError: [Errno 2] No such file or directory: ''
tweekmonster commented 8 years ago

Is that the whole exception? It doesn't look like it.

tweekmonster commented 8 years ago

Have you tried it in Vim? I'll still fix that error, but it should work now since the plugin uses full paths for the completion script.

aleprovencio commented 8 years ago

When on config/settings/common.py, config/settings/production.py, etc, b:is_django_settings still does not get set.

tweekmonster commented 8 years ago

Ah, yeah it's still expecting to find settings.py. I'll see if that can be changed easily.

aleprovencio commented 8 years ago

That's awesome @tweekmonster, it does work! Maybe README also deserves update. Big thanks!

tweekmonster commented 8 years ago

Great 🙂 What do you suggest should be mentioned in the README? My thought is that it (now) does what the README says in the case for cookiecutter boilerplates.

aleprovencio commented 8 years ago

I guess it should mention that the detection method also understands cookicutter-like layouts, that's all :)

josefson commented 4 years ago

@aleprovencio Are you still using this plugin in a way that perhaps you could help me out with configuring it properly to get queryset completion? ergo: #19

aleprovencio commented 4 years ago

I'm sorry, have not been using it anymore :/

KentBrockman commented 3 years ago

@josefson I've been using the plugin. Happy to help out if you'd like