google-code-export / django-values

Automatically exported from code.google.com/p/django-values
1 stars 1 forks source link

Module wide settings appear twice on admin page and in DB #16

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi, 

first of all thakns for a great Django app ;)
Unfortunately I'm experiencing some problems with module wide settings. I
define my settings in the models.py:

---
from cms import dbsettings
class IntranetOptions(dbsettings.Group):    
    show_hidden_files = dbsettings.BooleanValue()
configuration = IntranetOptions()

---

This works fine when I open up the admin for the first time (before I
access a view using the settings) and the "show_hidden_files" setting shows
up on the dbsettings admin page.

Here's the database table row at this point:

---
(5, 1, 'cms.intranet.models', '', 'show_hidden_files', 'True');

---

Now I use the settings in a view function like this:

---
# At the top of the views.py
from cms.intranet.models import Client, ClientInvitation, configuration
# Further down in views.py in a view function
for filename in client_filenames:
    if not configuration.show_hidden_files and filename.startswith('.'):
        continue
    # ... more code

---

Again this works fine in principal - the show_hidden_files settings is used
correctly. 
But: After I have accessed the view containing the above code. The
"show_hidden_files" settings appears twice on the dbsettings admin page.
Looking at the dbsettings table in the database, I find two rows:

---
(6, 1, 'intranet.models', '', 'show_hidden_files', 'False'),
(5, 1, 'cms.intranet.models', '', 'show_hidden_files', 'True');

---

I'm keeping the dbsettings app in a subdirectory 'cms' which is on my
PYTHONPATH, but I don't understand, where the above problem stems from.
Any hints?

Regards,
peschler

Original issue reported on code.google.com by pesch...@gmail.com on 19 May 2008 at 11:06

GoogleCodeExporter commented 9 years ago
It looks to me like you're importing it as intranet.models.configuration 
instead of
cms.intranet.models.configuration somewhere. Python can't know in advance that 
those
two modules are the same, not until they're both imported, and it gives each of 
them
a name based on how it was imported. Since just importing the module is enough 
to
trigger the setting getting registered, it gets registered twice, each with a
different module name, as you see in your database settings.

Make sure all your code is always importing it as 
cms.intranet.models.configuration
*or* intranet.models.configuration, but not both.

Original comment by gulop...@gmail.com on 19 May 2008 at 11:21

GoogleCodeExporter commented 9 years ago
Thanks for the fast response.
Unfortunately I alreday checked the imports and the only import line in the 
whole
project is as I stated in the main issue text:

from cms.intranet.models import Client, ClientInvitation, configuration

There is *no* import without the 'cms' module (grepped the whole project files) 
-
that's why I initially reported this. If fully agree with your problem 
analysis, but
since there is no mixed import statement, the problem is somewhere else. I am 
now
going to dig deeper and report back what I've found.

BTW: I'm using dbsettings with newforms-admin-branch (rev 7233 and trunk) - 
maybe
this is a side-effect of some new features.

Original comment by pesch...@gmail.com on 19 May 2008 at 12:26