Exemplo n.º 1
0
    def handle_noargs(self, **options):
        verbosity = int(options.get("verbosity", 0))
        interactive = int(options.get("interactive", 0))
        no_data = int(options.get("nodata", 0))
        if "conf_setting" in connection.introspection.table_names():
            raise CommandError("Database already created, you probably "
                               "want the syncdb or migrate command")

        syncdb.Command().execute(**options)
        if not interactive and not no_data:
            install_optional_data(verbosity)
        if settings.USE_SOUTH:
            try:
                from south.management.commands import migrate
            except ImportError:
                return
            if interactive:
                confirm = input("\nSouth is installed for this project."
                                "\nWould you like to fake initial "
                                "migrations? (yes/no): ")
                while True:
                    if confirm == "yes":
                        break
                    elif confirm == "no":
                        return
                    confirm = input("Please enter either 'yes' or 'no': ")
            if verbosity >= 1:
                print()
                print("Faking initial migrations ...")
                print()
            migrate.Command().execute(fake=True)
Exemplo n.º 2
0
    def handle_noargs(self, **options):
        verbosity = int(options.get("verbosity", 0))
        interactive = int(options.get("interactive", 0))
        no_data = int(options.get("nodata", 0))
        if "conf_setting" in connection.introspection.table_names():
            raise CommandError("Database already created, you probably "
                               "want the syncdb or migrate command")

        syncdb.Command().execute(**options)
        if not interactive and not no_data:
            install_optional_data(verbosity)
        if settings.USE_SOUTH:
            try:
                from south.management.commands import migrate
            except ImportError:
                return
            if interactive:
                confirm = raw_input("\nSouth is installed for this project."
                                    "\nWould you like to fake initial "
                                    "migrations? (yes/no): ")
                while True:
                    if confirm == "yes":
                        break
                    elif confirm == "no":
                        return
                    confirm = raw_input("Please enter either 'yes' or 'no': ")
            if verbosity >= 1:
                print
                print "Faking initial migrations ..."
                print
            migrate.Command().execute(fake=True)
Exemplo n.º 3
0
 def handle_noargs(self, **options):
     verbosity = int(options.get("verbosity", 0))
     interactive = int(options.get("interactive", 0))
     no_data = int(options.get("nodata", 0))
     syncdb.Command().execute(**options)
     if not interactive and not no_data:
         install_optional_data(verbosity)
     if settings.USE_SOUTH:
         try:
             from south.management.commands import migrate
         except ImportError:
             return
         if interactive:
             confirm = raw_input("\nWould you like to fake initial "
                                 "migrations? (yes/no): ")
             while True:
                 if confirm == "yes":
                     break
                 elif confirm == "no":
                     return
                 confirm = raw_input("Please enter either 'yes' or 'no': ")
         if verbosity >= 1:
             print
             print "Faking initial migrations ..."
             print
         migrate.Command().execute(fake=True)
Exemplo n.º 4
0
    def handle_noargs(self, **options):

        # Build a list of demo-editable models, which is everything
        # in Cartridge and Mezzanine, apart from mezzanine.twitter
        packages = ("mezzanine", "cartridge")
        keep_apps = ("mezzanine.conf", "mezzanine.twitter")
        reset = lambda a: a.split(".")[0] in packages and a not in keep_apps
        apps = [a.split(".")[-1] for a in settings.INSTALLED_APPS if reset(a)]
        models = [m for m in get_models() if m._meta.app_label in apps]

        # Delete all demo-editable data.
        for model in models:
            meta = model._meta
            print "Flushing %s.%s" % (meta.app_label, meta.object_name)
            model.objects.all().delete()

        # Maintain permissons for the demo account.
        demo_username = "******"
        demo_user, created = User.objects.get_or_create(username=demo_username)
        if created:
            demo_user.set_password("demo")
            demo_user.is_staff = True
            demo_user.save()
        demo_user.user_permissions.remove()
        demo_user.first_name = "Demo"
        demo_user.last_name = "User"
        demo_user.save()
        for model in models:
            ct = ContentType.objects.get_for_model(model)
            for permission in Permission.objects.filter(content_type=ct):
                demo_user.user_permissions.add(permission)

        # Delete any created user accounts.
        keep_users = Q(is_superuser=True) | Q(username=demo_username)
        User.objects.exclude(keep_users).delete()

        # Delete any uploaded files.
        uploads = os.path.join(settings.MEDIA_ROOT, "uploads")
        if os.path.exists(uploads):
            rmtree(uploads)
        os.mkdir(uploads)

        # Load initial demo data.
        create_pages(None, models, verbosity=1, interactive=False)
        create_product(None, models, verbosity=1, interactive=False)
        install_optional_data(verbosity=1)
        call_command("import_rss", rss_url="http://blog.jupo.org/atom.xml",
                     mezzanine_user=demo_username, **options)
        mezzanine_posts = Q(title__icontains="mezzanine")
        cartridge_posts = Q(title__icontains="cartridge")
        BlogPost.objects.exclude(mezzanine_posts | cartridge_posts).delete()
Exemplo n.º 5
0
    def handle_noargs(self, **options):

        # Build a list of demo-editable models, which is everything
        # in Cartridge and Mezzanine, apart from mezzanine.twitter
        packages = ("mezzanine", "cartridge")
        keep_apps = ("mezzanine.conf", "mezzanine.twitter")
        reset = lambda a: a.split(".")[0] in packages and a not in keep_apps
        apps = [a.split(".")[-1] for a in settings.INSTALLED_APPS if reset(a)]
        models = [m for m in get_models() if m._meta.app_label in apps]

        # Delete all demo-editable data.
        for model in models:
            meta = model._meta
            print "Flushing %s.%s" % (meta.app_label, meta.object_name)
            model.objects.all().delete()

        # Maintain permissons for the demo account.
        demo_username = "******"
        demo_user, created = User.objects.get_or_create(username=demo_username)
        if created:
            demo_user.set_password("demo")
            demo_user.is_staff = True
            demo_user.save()
        demo_user.user_permissions.remove()
        demo_user.save()
        for model in models:
            ct = ContentType.objects.get_for_model(model)
            for permission in Permission.objects.filter(content_type=ct):
                demo_user.user_permissions.add(permission)

        # Delete any created user accounts.
        keep_users = Q(is_superuser=True) | Q(username=demo_username)
        User.objects.exclude(keep_users).delete()

        # Delete any uploaded files.
        uploads = os.path.join(settings.MEDIA_ROOT, "uploads")
        if os.path.exists(uploads):
            rmtree(uploads)
        os.mkdir(uploads)

        # Load initial demo data.
        create_pages(None, models, verbosity=1, interactive=False)
        create_product(None, models, verbosity=1, interactive=False)
        install_optional_data(verbosity=1)
        call_command("import_rss",
                     rss_url="http://blog.jupo.org/atom.xml",
                     mezzanine_user=demo_username,
                     **options)
        mezzanine_posts = Q(keywords_string__contains="mezzanine")
        cartridge_posts = Q(keywords_string__contains="cartridge")
        BlogPost.objects.exclude(mezzanine_posts | cartridge_posts).delete()
Exemplo n.º 6
0
    def handle_noargs(self, **options):
        verbosity = int(options.get("verbosity", 0))
        interactive = int(options.get("interactive", 0))
        no_data = int(options.get("nodata", 0))
        if "conf_setting" in connection.introspection.table_names():
            raise CommandError("Database already created, you probably "
                               "want the syncdb or migrate command")

        syncdb.Command().execute(**options)
        if not interactive and not no_data:
            install_optional_data(verbosity)
        if settings.USE_SOUTH:
            try:
                from south.management.commands import migrate
            except ImportError:
                pass
            else:
                confirm = "yes"
                if interactive:
                    confirm = input("\nSouth is installed for this project."
                                        "\nWould you like to fake initial "
                                        "migrations? (yes/no): ")
                    while confirm not in ("yes", "no",):
                        confirm = input("Please enter either 'yes' or 'no': ")
                if confirm == "yes":
                    if verbosity >= 1:
                        print()
                        print("Faking initial migrations ...")
                        print()
                    migrate.Command().execute(fake=True)
        if settings.USE_MODELTRANSLATION and settings.USE_I18N:
            try:
                from modeltranslation.management.commands \
                        import update_translation_fields
            except ImportError:
                return
            if interactive:
                confirm = input("\nDjango-modeltranslation is installed for "
                                "this project and you have specified to use "
                                "i18n.\nWould you like to update translation "
                                "fields from the default ones? (yes/no): ")
                while True:
                    if confirm == "yes":
                        break
                    elif confirm == "no":
                        return
                    confirm = input("Please enter either 'yes' or 'no': ")
            update_translation_fields.Command().execute(verbosity=verbosity)