Skip to content
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

disable automatic installation of demonstration content #222

Closed
electroniceagle opened this issue May 10, 2012 · 17 comments
Closed

disable automatic installation of demonstration content #222

electroniceagle opened this issue May 10, 2012 · 17 comments

Comments

@electroniceagle
Copy link
Contributor

I'm running into a problem when doing automated deployments where your demonstration initial content (About page, Blog, Contact, Gallery) reappears on a fresh database installation. There is no way to suppress this behavior currently.

Two solutions:

  1. Add an override in settings.py
(dev)bschott@ironman:mezzanine$ git diff core/management/__init__.py
diff --git a/mezzanine/core/management/__init__.py b/mezzanine/core/management/__init__.py
index 360fb75..46133db 100644
--- a/mezzanine/core/management/__init__.py
+++ b/mezzanine/core/management/__init__.py
@@ -32,6 +32,10 @@ def create_user(app, created_models, verbosity, interactive, **kwargs):

 def create_pages(app, created_models, verbosity, interactive, **kwargs):
     required = set([Page, Form, Gallery])
+
+    if not getattr(settings, 'MEZZANINE_INSTALL_INITIAL_CONTENT', False):
+        return
+
     if required.issubset(set(created_models)):
         if interactive:
             confirm = raw_input("\nWould you like to install some initial "

or, 2) Change the default non-interactive --noinput behavior to NOT install demo content.


diff --git a/mezzanine/core/management/__init__.py b/mezzanine/core/management/__init__.py
index 360fb75..c022d51 100644
--- a/mezzanine/core/management/__init__.py
+++ b/mezzanine/core/management/__init__.py
@@ -43,6 +43,8 @@ def create_pages(app, created_models, verbosity, interactive, **kwargs):
                 elif confirm == "no":
                     return
                 confirm = raw_input("Please enter either 'yes' or 'no': ")
+        else:
+            return
         if verbosity >= 1:
             print
             print ("Creating initial content "
@electroniceagle
Copy link
Contributor Author

I implemented a slightly different solution after some testing. This version obeys the setting, else asks if interactive, else does not do the install on non-interactive.

https://github.com/nimbis/mezzanine/commit/1e552df6fea74c536fd76a2d7684a4e064e675a4

diff --git a/mezzanine/core/management/__init__.py b/mezzanine/core/management/__init__.py
index 360fb75..b155fc6 100644
--- a/mezzanine/core/management/__init__.py
+++ b/mezzanine/core/management/__init__.py
@@ -33,7 +33,9 @@ def create_user(app, created_models, verbosity, interactive, **kwargs):
 def create_pages(app, created_models, verbosity, interactive, **kwargs):
     required = set([Page, Form, Gallery])
     if required.issubset(set(created_models)):
-        if interactive:
+        if not getattr(settings, 'MEZZANINE_INSTALL_INITIAL_CONTENT', False):
+            return
+        elif interactive:
             confirm = raw_input("\nWould you like to install some initial "
                                 "content?\nEg: About page, Blog, Contact "
                                 "form, Gallery. (yes/no): ")
@@ -43,6 +45,8 @@ def create_pages(app, created_models, verbosity, interactive, **kwargs):
                 elif confirm == "no":
                     return
                 confirm = raw_input("Please enter either 'yes' or 'no': ")
+        else:
+            return
         if verbosity >= 1:
             print
             print ("Creating initial content "

@stephenmcd
Copy link
Owner

Yeah this has never been quite right. Thanks for bring it up. The problem is that there's two types of data, pure demo stuff, and stuff that's required for everything to work. For example there's no way to get to the blog without a blog page set up.

What we'd need to first do is split these apart, so that if we're not installing the demo data, the blog page still gets install. Maybe this isn't quite right, and we need a way to basically install NO data, like you're saying, but I think the most common use case here would be - don't install demo data, but give me the minimum I need for things to work.

Rather than a setting, I was thinking it might be more appropriate to have an arg for the management commands, something like --nodata, so:

python manage.py --noinput --nodata

The question remains would it still install the blog page, even with --nodata. If --nodata is absolute and doesn't install the blog page, we need a way to allow for this, that is, don't install demo data, but install the blog page and anything else that might be required for everything to function.

@electroniceagle
Copy link
Contributor Author

I'll take a look at it. I think I was saved by the fact that the .json templates I'm auto importing myself has the blog page. The real issue was Cartridge. One of our team deleted the initial products, created new ones, and I got SKU unique constraint conflicts. If there is mandatory initial data, then it should probably be in the initial_data.json fixture in the blog app rather than a named fixture. I can try to break that out, but I'm still figuring my way around your schema.

If we do that, the optional demo stuff can be loaded only interactively. Agree that the setting is overkill. I only think you want the demo content for a test project, so I suspect you turn it on by default to make your demo site work right.

Brian Schott
bfschott@gmail.com

On May 10, 2012, at 4:59 PM, Stephen McDonald wrote:

Yeah this has never been quite right. Thanks for bring it up. The problem is that there's two types of data, pure demo stuff, and stuff that's required for everything to work. For example there's no way to get to the blog without a blog page set up.

What we'd need to first do is split these apart, so that if we're not installing the demo data, the blog page still gets install. Maybe this isn't quite right, and we need a way to basically install NO data, like you're saying, but I think the most common use case here would be - don't install demo data, but give me the minimum I need for things to work.

Rather than a setting, I was thinking it might be more appropriate to have an arg for the management commands, something like --nodata, so:

python manage.py --noinput --nodata

The question remains would it still install the blog page, even with --nodata. If --nodata is absolute and doesn't install the blog page, we need a way to allow for this, that is, don't install demo data, but install the blog page and anything else that might be required for everything to function.


Reply to this email directly or view it on GitHub:
#222 (comment)

@stephenmcd
Copy link
Owner

Love the idea of splitting the fixtures out. Let's not use initial_data as the name though, as we then lose control over installing it since Django will do so by default. Maybe mezzanine_required.json, mezzanine_optional.json, and same for Cartridge. So required will include the blog page for Mezzanine, and the shop page for Cartridge, and everything else can go in optional (other pages, demo product, etc).

Then we just need a --nodata arg for the createdb command that when specified will not load the optional fixtures (and not prompt the user for them if --noinput isn't specified).

@electroniceagle
Copy link
Contributor Author

Looking at the code now. Unfortunately, the management/init.py looks to be catching a post syncdb migrate signal, so I don't think there is an easy way to pass down a --noinput flag without changing this behavior? Settings is much easier to implement unless I'm missing something obvious.

Also, what's the reason to create a blog page even if mezzanine.blog app isn't installed? I'm trying to find how blog is connected. It should either have its own page at /blog and add itself to the menu or be its own Page subclass and let folks create multiple top-level blogs. We really want a /news and a /blog at the top level to both be blogs, for example.

@stephenmcd
Copy link
Owner

What we can do is remove the functionality from the syncdb signals and put it directly into the createdb command, that way we can add the new --nodata option and make use of it there.

@electroniceagle
Copy link
Contributor Author

OK, I'll take a look at it but probably not this sprint (few weeks). I've merged a quick hack into my own master branch because it was holding up a user story but will back it out when we work out a more permanent solution. I know you are slammed with things for 1.1.

@seanvoss
Copy link
Contributor

Wow github is smart, check out the commit, I have some minor cleanup to do and there is a bit of redundant code surrounding the galleries creation, but what do you think? I tested it seems to work.

@stephenmcd
Copy link
Owner

Thanks Sean - I'll go over it tomorrow hopefully.

@stephenmcd
Copy link
Owner

Sean I've had a look over it and it looks good. I didn't test it yet, I'll do that once a final pull request is set up.

Only thing I noticed is that you've added code for this in both the blog importers as well as the collecttemplates command - is that necessary? I can't see why it would be, but I may be missing something.

@seanvoss
Copy link
Contributor

seanvoss commented Oct 1, 2012

I cleaned up the extra code, the last question I have is on the ammended commit

mezzanine/core/management/init.py
&
mezzanine/core/management/commands/createdb.py

Have some duplicate code that they do need to run, starting with "call_command" + 5 lines, would you like to place that somewhere where they can both access it, so it only needs to be written once? If so, where is appropriate?

@stephenmcd
Copy link
Owner

I guess creating a function inside the init module would suffice.

@seanvoss
Copy link
Contributor

seanvoss commented Oct 4, 2012

Pull request is open.
#423

@stephenmcd
Copy link
Owner

Awesome Sean, thanks soooo much for working on this. I'll go over it tomorrow hopefully and merge it in.

@seanvoss
Copy link
Contributor

seanvoss commented Oct 4, 2012

Cool, assuming all goes well, let me know if you want me to port over to Cartridge or if you got it.

Cheers,

Sean

@stephenmcd
Copy link
Owner

Well if there are any problems we'll sort them out (I glanced over it and it looks fine). So once it's all in Mezz it would be great to fix up Cartridge too. But let's wait for it to go into Mezz first in case anything does change.

@stephenmcd
Copy link
Owner

Closed by f2933d5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants