コード例 #1
0
def create_product(app, created_models, verbosity, interactive, **kwargs):
    if Product in created_models:
        call_command("loaddata", "cartridge_required.json")
        if interactive:
            confirm = raw_input("\nWould you like to install an initial "
                                "demo product and sale? (yes/no): ")
            while True:
                if confirm == "yes":
                    break
                elif confirm == "no":
                    return
                confirm = raw_input("Please enter either 'yes' or 'no': ")
        # This is a hack. Ideally to split fixtures between optional
        # and required, we'd use the same approach Mezzanine does,
        # within a ``createdb`` management command. Ideally to do this,
        # we'd subclass Mezzanine's createdb command and shadow it,
        # but to do that, the cartridge.shop app would need to appear
        # *after* mezzanine.core in the INSTALLED_APPS setting, but the
        # reverse is needed for template overriding (and probably other
        # bits) to work correctly.
        # SO........... we just cheat, and check sys.argv here. Namaste.
        elif "--nodata" in sys.argv:
            return
        if verbosity >= 1:
            print
            print "Creating demo product and sale ..."
            print
        call_command("loaddata", "cartridge_optional.json")
        copy_test_to_media("cartridge.shop", "product")
コード例 #2
0
ファイル: __init__.py プロジェクト: suryaj92/mezzanine
def create_pages(app, created_models, verbosity, interactive, **kwargs):
    required = set([Page, Form, Gallery])
    if settings.DEBUG and required.issubset(set(created_models)):
        if interactive:
            confirm = raw_input("\nWould you like to install some initial "
                                "content?\nEg: About page, Blog, Contact "
                                "form, Gallery. (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(
                "Creating initial content "
                "(About page, Blog, Contact form, Gallery) ...")
            print
        call_command("loaddata", "mezzanine.json")
        zip_name = "gallery.zip"
        copy_test_to_media("mezzanine.core", zip_name)
        gallery = Gallery.objects.get()
        gallery.zip_import = zip_name
        gallery.save()
コード例 #3
0
 def test_thumbnail_generation(self):
     """
     Test that a thumbnail is created and resized.
     """
     try:
         from PIL import Image
     except ImportError:
         return
     image_name = "image.jpg"
     size = (24, 24)
     copy_test_to_media("mezzanine.core", image_name)
     thumb_name = os.path.join(
         settings.THUMBNAILS_DIR_NAME,
         image_name,
         image_name.replace(".", "-%sx%s." % size),
     )
     thumb_path = os.path.join(settings.MEDIA_ROOT, thumb_name)
     thumb_image = thumbnail(image_name, *size)
     self.assertEqual(os.path.normpath(thumb_image.lstrip("/")), thumb_name)
     self.assertNotEqual(os.path.getsize(thumb_path), 0)
     thumb = Image.open(thumb_path)
     self.assertEqual(thumb.size, size)
     # Clean up.
     del thumb
     os.remove(os.path.join(settings.MEDIA_ROOT, image_name))
     os.remove(os.path.join(thumb_path))
     rmtree(os.path.join(os.path.dirname(thumb_path)))
コード例 #4
0
ファイル: tests.py プロジェクト: DamavandiKamali/mezzanine
 def test_thumbnail_generation(self):
     """
     Test that a thumbnail is created and resized.
     """
     try:
         from PIL import Image
     except ImportError:
         return
     image_name = "image.jpg"
     size = (24, 24)
     copy_test_to_media("mezzanine.core", image_name)
     thumb_name = os.path.join(settings.THUMBNAILS_DIR_NAME,
                               "thumbs-%s" % image_name,
                               image_name.replace(".", "-%sx%s." % size))
     thumb_path = os.path.join(settings.MEDIA_ROOT, thumb_name)
     thumb_image = thumbnail(image_name, *size)
     self.assertEqual(os.path.normpath(thumb_image.lstrip("/")), thumb_name)
     self.assertNotEqual(os.path.getsize(thumb_path), 0)
     thumb = Image.open(thumb_path)
     self.assertEqual(thumb.size, size)
     # Clean up.
     del thumb
     os.remove(os.path.join(settings.MEDIA_ROOT, image_name))
     os.remove(os.path.join(thumb_path))
     rmtree(os.path.join(os.path.dirname(thumb_path)))
コード例 #5
0
ファイル: createdb.py プロジェクト: herrdu/mezzanine
 def create_shop(self):
     call_command("loaddata", "cartridge_required.json")
     install_optional = not self.no_data and self.confirm(
         "\nWould you like to install an initial "
         "demo product and sale? (yes/no): ")
     if install_optional:
         if self.verbosity >= 1:
             print("\nCreating demo product and sale ...\n")
         call_command("loaddata", "cartridge_optional.json")
         copy_test_to_media("cartridge.shop", "product")
コード例 #6
0
ファイル: createdb.py プロジェクト: MarkTseng/mezzanine
 def create_shop(self):
     call_command("loaddata", "cartridge_required.json")
     install_optional = not self.no_data and self.confirm(
         "\nWould you like to install an initial "
         "demo product and sale? (yes/no): ")
     if install_optional:
         if self.verbosity >= 1:
             print("\nCreating demo product and sale ...\n")
         call_command("loaddata", "cartridge_optional.json")
         copy_test_to_media("cartridge.shop", "product")
コード例 #7
0
ファイル: __init__.py プロジェクト: Amisiti/mezzanine
def install_optional_data(verbosity):
    call_command("loaddata", "mezzanine_optional.json")
    zip_name = "gallery.zip"
    copy_test_to_media("mezzanine.core", zip_name)
    gallery = Gallery.objects.get()
    gallery.zip_import = zip_name
    gallery.save()
    if verbosity >= 1:
        print
        print ("Creating demo content "
               "(About page, Blog, Contact form, Gallery) ...")
        print
コード例 #8
0
ファイル: __init__.py プロジェクト: damianignacio/mezzanine
def install_optional_data(verbosity):
    if verbosity >= 1:
        print
        print "Creating demo pages: About us, Contact form, Gallery ..."
        print
    from mezzanine.galleries.models import Gallery
    call_command("loaddata", "mezzanine_optional.json")
    zip_name = "gallery.zip"
    copy_test_to_media("mezzanine.core", zip_name)
    gallery = Gallery.objects.get()
    gallery.zip_import = zip_name
    gallery.save()
コード例 #9
0
ファイル: __init__.py プロジェクト: westinedu/evershould
def install_optional_data(verbosity):
    call_command("loaddata", "mezzanine_optional.json")
    zip_name = "gallery.zip"
    copy_test_to_media("mezzanine.core", zip_name)
    gallery = Gallery.objects.get()
    gallery.zip_import = zip_name
    gallery.save()
    if verbosity >= 1:
        print
        print(
            "Creating demo content "
            "(About page, Blog, Contact form, Gallery) ...")
        print
コード例 #10
0
 def test_gallery_import(self):
     """
     Test that a gallery creates images when given a zip file to
     import, and that descriptions are created.
     """
     zip_name = "gallery.zip"
     copy_test_to_media("mezzanine.core", zip_name)
     title = str(uuid4())
     gallery = Gallery.objects.create(title=title, zip_import=zip_name)
     images = list(gallery.images.all())
     self.assertTrue(images)
     self.assertTrue(all([image.description for image in images]))
     # Clean up.
     rmtree(os.path.join(settings.MEDIA_ROOT, GALLERIES_UPLOAD_DIR, title))
コード例 #11
0
ファイル: tests.py プロジェクト: nym/mezzanine
 def test_gallery_import(self):
     """
     Test that a gallery creates images when given a zip file to
     import, and that descriptions are created.
     """
     zip_name = "gallery.zip"
     copy_test_to_media("mezzanine.core", zip_name)
     title = str(uuid4())
     gallery = Gallery.objects.create(title=title, zip_import=zip_name)
     images = list(gallery.images.all())
     self.assertTrue(images)
     self.assertTrue(all([image.description for image in images]))
     # Clean up.
     rmtree(unicode(os.path.join(settings.MEDIA_ROOT, GALLERIES_UPLOAD_DIR, title)))
コード例 #12
0
ファイル: __init__.py プロジェクト: zouluclara/cartridge
def install_optional_data(verbosity):
    if not is_full_install():
        return
    if verbosity >= 1:
        print()
        print("Creating demo pages: About us, Contact form, Gallery ...")
        print()
    from mezzanine.galleries.models import Gallery
    call_command("loaddata", "mezzanine_optional.json")
    zip_name = "gallery.zip"
    copy_test_to_media("mezzanine.core", zip_name)
    gallery = Gallery.objects.get()
    gallery.zip_import = zip_name
    gallery.save()
コード例 #13
0
def create_initial_product(app, created_models, verbosity, **kwargs):
    if Product in created_models:
        if kwargs.get("interactive"):
            confirm = raw_input("\nWould you like to install an initial "
                                "Category and Product? (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 "Creating initial Category and Product ..."
            print
        call_command("loaddata", "cartridge.json")
        copy_test_to_media("cartridge.shop", "product")
コード例 #14
0
ファイル: createdb.py プロジェクト: herrdu/mezzanine
 def create_pages(self):
     call_command("loaddata", "mezzanine_required.json")
     install_optional = not self.no_data and self.confirm(
         "\nWould you like to install some initial "
         "demo pages?\nEg: About us, Contact form, "
         "Gallery. (yes/no): ")
     if install_optional:
         if self.verbosity >= 1:
             print("\nCreating demo pages: About us, Contact form, "
                   "Gallery ...\n")
         from mezzanine.galleries.models import Gallery
         call_command("loaddata", "mezzanine_optional.json")
         zip_name = "gallery.zip"
         copy_test_to_media("mezzanine.core", zip_name)
         gallery = Gallery.objects.get()
         gallery.zip_import = zip_name
         gallery.save()
コード例 #15
0
ファイル: createdb.py プロジェクト: MarkTseng/mezzanine
 def create_pages(self):
     call_command("loaddata", "mezzanine_required.json")
     install_optional = not self.no_data and self.confirm(
         "\nWould you like to install some initial "
         "demo pages?\nEg: About us, Contact form, "
         "Gallery. (yes/no): ")
     if install_optional:
         if self.verbosity >= 1:
             print("\nCreating demo pages: About us, Contact form, "
                     "Gallery ...\n")
         from mezzanine.galleries.models import Gallery
         call_command("loaddata", "mezzanine_optional.json")
         zip_name = "gallery.zip"
         copy_test_to_media("mezzanine.core", zip_name)
         gallery = Gallery.objects.get()
         gallery.zip_import = zip_name
         gallery.save()
コード例 #16
0
ファイル: __init__.py プロジェクト: DanHoerst/mezzanine
def create_pages(app, created_models, verbosity, interactive, **kwargs):
    required = set([Page, Form, Gallery])
    if settings.DEBUG and required.issubset(set(created_models)):
        if interactive:
            confirm = raw_input("\nWould you like to install some initial "
                                "content?\nEg: About page, Blog, Contact "
                                "form, Gallery. (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 ("Creating initial content "
                   "(About page, Blog, Contact form, Gallery) ...")
            print
        call_command("loaddata", "mezzanine.json")
        zip_name = "gallery.zip"
        copy_test_to_media("mezzanine.core", zip_name)
        gallery = Gallery.objects.get()
        gallery.zip_import = zip_name
        gallery.save()