Example #1
0
        def migrate_data(from_table, to_table):
            """
            ``from_table`` is not migrated, ``to_table`` is
            """
            data_list = get_table_records(from_table)
            sql = 'INSERT INTO %s (cmsplugin_ptr_id, url, width, height, auto_play, loop_video, oembed_data, ' \
                  'custom_params, iframe_width, iframe_height) VALUES ' % to_table
            for record in data_list:
                iframe_width = re.search('width="(\d+)"', record[4])
                iframe_width = iframe_width.groups(
                )[0] if iframe_width else 'null'

                iframe_height = re.search('height="(\d+)"', record[4])
                iframe_height = iframe_height.groups(
                )[0] if iframe_width else 'null'

                # get embed code
                if record[2] and record[3]:
                    embed_code = get_embed_code(url=record[1],
                                                maxwidth=record[2],
                                                maxheight=record[3])
                elif record[2]:
                    embed_code = get_embed_code(url=record[1],
                                                maxwidth=record[2])
                elif record[3]:
                    embed_code = get_embed_code(url=record[1],
                                                maxheight=record[3])
                else:
                    embed_code = get_embed_code(url=record[1])

                new_record_data = {
                    'cmsplugin_ptr_id': record[0],
                    'url': record[1],
                    'width': record[2] or 'null',
                    'height': record[3] or 'null',
                    'auto_play': 'false',
                    'loop_video': 'false',
                    'embed_code': json.dumps(embed_code),
                    'custom_params': '',
                    'iframe_width': iframe_width,
                    'iframe_height': iframe_height,
                }

                new_record_sql = \
                    "(%(cmsplugin_ptr_id)i, '%(url)s', %(width)s, %(height)s, %(auto_play)s, %(loop_video)s, " \
                    "'%(embed_code)s', '%(custom_params)s', %(iframe_width)s, %(iframe_height)s)," % new_record_data

                sql += new_record_sql

            # strip last comma and add semicolon to finish of the statement
            sql = sql[:-1] + ';'
            return db.execute(sql)
Example #2
0
        def migrate_data(from_table, to_table):
            """
            ``from_table`` is not migrated, ``to_table`` is
            """
            data_list = get_table_records(from_table)
            sql = 'INSERT INTO %s (cmsplugin_ptr_id, url, width, height, auto_play, loop_video, oembed_data, ' \
                  'custom_params, iframe_width, iframe_height) VALUES ' % to_table
            for record in data_list:
                iframe_width = re.search('width="(\d+)"', record[4])
                iframe_width = iframe_width.groups()[0] if iframe_width else 'null'

                iframe_height = re.search('height="(\d+)"', record[4])
                iframe_height = iframe_height.groups()[0] if iframe_width else 'null'

                # get embed code
                if record[2] and record[3]:
                    embed_code = get_embed_code(url=record[1], maxwidth=record[2], maxheight=record[3])
                elif record[2]:
                    embed_code = get_embed_code(url=record[1], maxwidth=record[2])
                elif record[3]:
                    embed_code = get_embed_code(url=record[1], maxheight=record[3])
                else:
                    embed_code = get_embed_code(url=record[1])

                new_record_data = {
                    'cmsplugin_ptr_id': record[0],
                    'url': record[1],
                    'width': record[2] or 'null',
                    'height': record[3] or 'null',
                    'auto_play': 'false',
                    'loop_video': 'false',
                    'embed_code': json.dumps(embed_code),
                    'custom_params': '',
                    'iframe_width': iframe_width,
                    'iframe_height': iframe_height,
                }

                new_record_sql = \
                    "(%(cmsplugin_ptr_id)i, '%(url)s', %(width)s, %(height)s, %(auto_play)s, %(loop_video)s, " \
                    "'%(embed_code)s', '%(custom_params)s', %(iframe_width)s, %(iframe_height)s)," % new_record_data

                sql += new_record_sql

            # strip last comma and add semicolon to finish of the statement
            sql = sql[:-1] + ';'
            return db.execute(sql)
 def forwards(self, orm):
     "Write your forwards methods here."
     rename_tables_old_to_new(db)
     for plugin in orm.oembedvideoplugin.objects.all():
         # Depending on the amount of plugins, this could take a while.
         data = get_embed_code(url=plugin.url, **self.get_oembed_params(plugin))
         player_url = re.search(IFRAME_SRC_REGEX, data.get('html', ''))
         if player_url:
             data['player_url'] = player_url.groups()[0]
         plugin.oembed_data = data
         plugin.save()
Example #4
0
 def forwards(self, orm):
     "Write your forwards methods here."
     rename_tables_old_to_new(db)
     for plugin in orm.oembedvideoplugin.objects.all():
         # Depending on the amount of plugins, this could take a while.
         data = get_embed_code(url=plugin.url,
                               **self.get_oembed_params(plugin))
         player_url = re.search(IFRAME_SRC_REGEX, data.get('html', ''))
         if player_url:
             data['player_url'] = player_url.groups()[0]
         plugin.oembed_data = data
         plugin.save()