示例#1
0
def copy_members():
    cur.execute("""SELECT * from people_member""")
    for row in cur.fetchall():
        print('member:', row[2])
        member = Member(
            publish=True,
            first_name=row[1].decode('utf-8'),
            last_name=row[2].decode('utf-8'),
            bio=html2text(row[4]).decode('utf-8'),
            email=row[5].decode('utf-8'),
            city=row[6].decode('utf-8'),
            state=row[7].decode('utf-8'),
            headshot=None,
        )
        db_session.add(member)
        db_session.flush()

        headshot_path = row[8]
        _rel_dir = os.path.join('images', 'people', '{}_{}'.format(member.id, member.slug))
        _dir = os.path.join(BASE_DIR, 'static', _rel_dir)
        try:
            os.mkdir(_dir)
            shutil.copy(os.path.join(BASE_DIR, 'static', 'old', headshot_path), _dir)
        except OSError:
            pass
        member.headshot = os.path.join(_rel_dir, os.path.basename(headshot_path))

    db_session.commit()
示例#2
0
def copy_projects():
    # PROJECTS
    cur.execute("""SELECT * from work_project""")
    rows = cur.fetchall()
    for row in rows:
        old_id = row[0]
        print('project:', row[2])
        project = Project(
            publish=True, name=row[2].decode('utf-8'), long_name=row[10].decode('utf-8'),
            year=int(row[6]), category_id=int(row[8]), order=int(row[15]),
            location=row[11].decode('utf-8'), client=row[12].decode('utf-8'),
            award=row[13].decode('utf-8'), thumbnail=None,
            project_type_id=1, text=None # project_type_id=row[9]
        )
        db_session.add(project)
        db_session.flush()

        project.publish = True
        project.order = int(row[15])
        PROJECT_ID_MAP[row[0]] = project.id

        cur.execute("""SELECT * FROM work_projecttext WHERE project_id={}""".format(row[0]))
        try:
            textrow = cur.fetchone()
            project.text = html2text(textrow[1].decode('utf-8'))
        except:
            pass

        thumbnail_path = row[14]
        _rel_dir = os.path.join('images', 'projects', '{}_{}'.format(project.id, project.slug))
        _dir = os.path.join(BASE_DIR, 'static', _rel_dir)
        try:
            os.mkdir(_dir)
            shutil.copy(os.path.join(BASE_DIR, 'static', 'old', thumbnail_path), _dir)
        except OSError:
            pass
        project.thumbnail = os.path.join(_rel_dir, os.path.basename(thumbnail_path))

    # PROJECT IMAGES
        cur.execute("""SELECT * from work_projectimage WHERE project_id={}""".format(row[0]))
        for row in cur.fetchall():
            image_path = str(row[7])
            try:
                shutil.copy(os.path.join(BASE_DIR, 'static', 'old', image_path), _dir)
            except OSError:
                pass
            project_image = ProjectImage(
                publish=True,
                project_id=project.id,
                path=os.path.join(_rel_dir, os.path.basename(image_path)),
                width=row[4],
                height=row[5],
            )
            db_session.add(project_image)
            db_session.flush()
            project_image.publish = True
            project_image.order = int(row[3])

        # cur.execute("""SELECT * from work_projectresource WHERE project_id={}""".format(old_id))
        # for row in cur.fetchall():
        #     project_url = ProjectUrl(
        #         publish=True,
        #         name=row[2].decode('utf-8'),
        #         order=int(row[6]),
        #         project_id=project.id,
        #         url=row[10].decode('utf-8'),
        #     )
        #     db_session.add(project_url)
        #     db_session.flush()
        #     project_url.order = int(row[6])
        #     project_url.publish = True

    db_session.commit()
示例#3
0
def copy_itemsforsale():
    # PROJECTS
    cur.execute("""SELECT * from shop_itemforsale""")
    for row in cur.fetchall():
        old_id = row[0]
        print('product:', row[2])
        product = Product(
            publish=True,
            name=row[2].decode('utf-8'),
            long_name=row[8].decode('utf-8'),
            project_id=PROJECT_ID_MAP[row[7]],
            order=int(row[6]),
            paypal_code=row[11],
            thumbnail=None,
            text=None,
            price=row[12],
        )
        db_session.add(product)
        db_session.flush()

        product.order = int(row[6])
        product.publish = True
        PRODUCT_ID_MAP[row[0]] = product.id

        cur.execute("""SELECT * FROM shop_itemforsaletext WHERE item_id={}""".format(row[0]))
        try:
            textrow = cur.fetchone()
            product.text = html2text(textrow[1].decode('utf-8'))
        except:
            pass

        thumbnail_path = row[9]
        _rel_dir = os.path.join('images', 'products', '{}_{}'.format(product.id, product.slug))
        _dir = os.path.join(BASE_DIR, 'static', _rel_dir)
        try:
            os.mkdir(_dir)
            shutil.copy(os.path.join(BASE_DIR, 'static', 'old', thumbnail_path), _dir)
        except OSError:
            pass
        product.thumbnail = os.path.join(_rel_dir, os.path.basename(thumbnail_path))

        # PRODUCT IMAGES
        cur.execute("""SELECT * from shop_itemforsaleimage WHERE item_id={}""".format(row[0]))
        for row in cur.fetchall():
            image_path = str(row[7])
            try:
                shutil.copy(os.path.join(BASE_DIR, 'static', 'old', image_path), _dir)
            except OSError:
                pass
            product_image = ProductImage(
                publish=True,
                order=row[3],
                product_id=product.id,
                path=os.path.join(_rel_dir, os.path.basename(image_path)),
                width=row[4],
                height=row[5],
            )
            db_session.add(product_image)
            db_session.flush()
            product_image.order = int(row[3])
            product_image.publish = True

        cur.execute("""SELECT * from shop_itemforsaleresource WHERE item_id={}""".format(old_id))
        # print(len(cur.fetchall()))
        for row in cur.fetchall():
            product_url = ProductUrl(
                publish=True,
                name=row[2].decode('utf-8'),
                order=int(row[6]),
                product_id=product.id,
                url=row[10].decode('utf-8'),
            )
            db_session.add(product_url)
            db_session.flush()
            product_url.order = int(row[6])
            product_url.publish = True

    db_session.commit()