def handle(self, *args, **options):
        backup_name = options['backup_name']
        site_id = options['site_id']

        if not backup_name or not site_id:
            raise Exception('backup_name or site_id is missing')

        models = ["magiccontent.Widget",
                  "magiccontent.Area",
                  "magiccontent.SiteLink",
                  "magicgallery.Gallery",
                  "magicgallery.GalleryItem",
                  "textimagecontent.TextImageContent",
                  "formattedtextimagecontent.FormattedTextImageContent",
                  "iconcontent.IconContent",
                  "background.BackgroundArea",
                  "dividertextcontent.DividerTextContent",
                  "imagecontent.ImageContent",
                  "magiccontentnavigation.MenuItem",
                  "core.SitePreferences",
                  "magicthemes.ThemePreferences", ]

        backup = MagicBackup().site(site_id).save_as(backup_name)
        for model in models:
            print(green('backuping {0}...'.format(model)))
            backup.model(model).backup()

        print(green('new backup created at {0}'.format(backup.target_dir)))
    def handle(self, *args, **options):
        backup_name = options['backup_name']
        site_id = options['site_id']

        if not backup_name or not site_id:
            raise Exception('backup_name or site_id is missing')

        # IMPORTANT: if you update this list, please,
        #            see the site_creator.py module too
        models_list = ["magiccontent.Widget",
                       "magiccontent.Area",
                       "magiccontent.SiteLink",
                       "magicgallery.Gallery",
                       "magicgallery.GalleryItem",
                       "textimagecontent.TextImageContent",
                       "formattedtextimagecontent.FormattedTextImageContent",
                       "iconcontent.IconContent",
                       "background.BackgroundArea",
                       "dividertextcontent.DividerTextContent",
                       "imagecontent.ImageContent",
                       "magiccontentnavigation.MenuItem",
                       "core.SitePreferences",
                       "magicthemes.ThemePreferences", ]

        restore = MagicBackup() \
            .from_backup(backup_name) \
            .to_site(site_id)

        for model in models_list:
            print(green('Restoring {0}...'.format(model)))
            restore.model(model).restore()

        print(green('site id {0} populated with backup {1}'.format(
            site_id, restore.original_path)))
Пример #3
0
    def setUp(self):
        # Creating some data
        self._current_site = Site.objects.get_current()
        self._pet_model.objects.create(name="Lucky")
        self._pet_model.objects.create(name="Paçoca")

        # Creating a backup for the given data
        backup = MagicBackup() \
            .site(self._current_site.id) \
            .save_as('mypets-backup')
        backup.model("tests.Pet").backup()

        # Deleting all data
        self._pet_model.objects.all().delete()
Пример #4
0
    def test_should_save_a_simple_model_item_to_json_file(self):
        # Given some data
        dog = self._pet_model.objects.create(name="Lucky")

        # When the backup is called
        backup = MagicBackup() \
            .site(self._current_site.id) \
            .save_as('my-magic-backup-folder') \
            .model("tests.Pet").backup()

        # Then the output should be
        mypet = [{u'pk': 1,
                  u'model': u'tests.pet',
                  u'fields': {u'site': 1, u'name': u'Lucky'}}]

        self.assertIsNot(dog, None)
        self.assertEqual(backup.output(), mypet)