def add_jurymembers(apps, schema_editor): JuryMember = apps.get_model('cpm_data.JuryMember') SeasonJuryMember = apps.get_model('cpm_data.SeasonRelatedJuryMember') Image = get_image_model(apps) Collection = apps.get_model('wagtailcore.Collection') collection_id = Collection.objects.filter(depth=1)[0] season = _get_season(apps) for item in sorted(_get_data(), key=itemgetter('name_en'), reverse=True): photo = Image(title=item['name_en'], collection=collection_id) with open(_get_photo_path(item['photo']), 'rb') as photo_file: photo.file.save(name=item['photo'], content=File(photo_file)) photo.save() jury_member = JuryMember(name_en=item['name_en'], name_be=item['name_be'], name_ru=item['name_ru'], info_en=item['info_en'], info_be=item['info_be'], info_ru=item['info_ru'], country=item['country'], photo=photo) jury_member.save() SeasonJuryMember(season=season, jury_member=jury_member).save()
def remove_jury_member_pages(apps, schema_editor): HomePage = apps.get_model('home.HomePage') Image = get_image_model(apps) Collection = apps.get_model('wagtailcore.Collection') IndexPage = apps.get_model('cpm_generic.IndexPage') JuryMemberPage = apps.get_model("results.JuryMemberPage") index_page_ct = get_content_type(apps, 'cpm_generic', 'indexpage') jury_member_page_ct = get_content_type(apps, 'results', 'jurymemberpage') collection_id = Collection.objects.filter(depth=1)[0] homepage = HomePage.objects.get(slug='home') juryindex_page = IndexPage.objects.get(slug=_get_juryindex_kw()['slug']) for item in _get_data(): photo = Image.objects.get(title=item['title'], collection=collection_id) photo.delete() remove_subpage( parent=juryindex_page, model=JuryMemberPage, content_type=jury_member_page_ct, **_get_jurymember_kw(item) ) remove_subpage( parent=homepage, model=IndexPage, content_type=index_page_ct, **_get_juryindex_kw() )
def add_jurymembers(apps, schema_editor, season_name): season = _get_season(apps, season_name=season_name) JuryMember = apps.get_model('cpm_data.JuryMember') Image = get_image_model(apps) Collection = apps.get_model('wagtailcore.Collection') collection_id = Collection.objects.filter(depth=1)[0] for item in _get_data(season_name): photo = Image(title=item['name_en'], collection=collection_id) with open(_get_photo_path(item['photo']), 'rb') as photo_file: photo.file.save(name=item['photo'], content=File(photo_file)) photo.save() jurymember, _created = JuryMember.objects.get_or_create( name_en=item['name_en'], name_be=item['name_be'], name_ru=item['name_ru'], info_en=item['info_en'], info_be=item['info_be'], info_ru=item['info_ru'], country=item['country'], photo=photo, ) SeasonJuryMember = apps.get_model('cpm_data.SeasonRelatedJuryMember') SeasonJuryMember( jury_member=jurymember, season=season, category_en='', category_be='', category_ru='', ).save()
def add_jury_member_pages(apps, schema_editor): Image = get_image_model(apps) IndexPage = apps.get_model('cpm_generic.IndexPage') JuryMemberPage = apps.get_model("results.JuryMemberPage") Collection = apps.get_model('wagtailcore.Collection') jury_member_page_ct = get_content_type(apps, 'results', 'jurymemberpage') collection_id = Collection.objects.filter(depth=1)[0] juryindex_page = IndexPage.objects.get(slug='jury') for item in get_jury_data(): photo = Image(title=item['title'], collection=collection_id) photo_file = os.path.join(MIGRATION_DIR, item['photo']) photo.file.save(name=item['title'] + os.extsep + item['photo_ext'], content=File(open(photo_file, 'rb'))) photo.save() slug = slugify(item['title']) add_subpage( parent=juryindex_page, model=JuryMemberPage, title=item['title'], slug=slug, name_en=item['name_en'], name_be=item['name_be'], name_ru=item['name_ru'], info_en=item['info_en'], info_be=item['info_be'], info_ru=item['info_ru'], country=item['country'], photo=photo, content_type=jury_member_page_ct, )
def add_jury_member_pages(apps, schema_editor): HomePage = apps.get_model('home.HomePage') Image = get_image_model(apps) Collection = apps.get_model('wagtailcore.Collection') IndexPage = apps.get_model('cpm_generic.IndexPage') JuryMemberPage = apps.get_model("results.JuryMemberPage") index_page_ct = get_content_type(apps, 'cpm_generic', 'indexpage') jury_member_page_ct = get_content_type(apps, 'results', 'jurymemberpage') collection_id = Collection.objects.filter(depth=1)[0] homepage = HomePage.objects.get(slug='home') juryindex_page = add_subpage( parent=homepage, model=IndexPage, content_type=index_page_ct, **_get_juryindex_kw() ) for item in _get_data(): photo = Image(title=item['title'], collection=collection_id) with open(_get_photo_path(item['photo']), 'rb') as photo_file: photo.file.save(name=item['photo'], content=File(photo_file)) photo.save() add_subpage( parent=juryindex_page, model=JuryMemberPage, photo=photo, content_type=jury_member_page_ct, **_get_jurymember_kw(item) )
def add_partners(apps, schema_editor, season_name): Partner = apps.get_model('cpm_data.Partner') SeasonRelatedPartner = apps.get_model('cpm_data.SeasonRelatedPartner') Image = get_image_model(apps) Collection = apps.get_model('wagtailcore.Collection') collection_id = Collection.objects.filter(depth=1)[0] season = _get_season(apps, season_name) for item in sorted(_get_data(season_name), reverse=True): image = Image(title=item['name_en'], collection=collection_id) with open(_get_image_path(item['image']), 'rb') as image_file: image.file.save(name=item['image'], content=File(image_file)) image.save() partner, _created = Partner.objects.get_or_create( name_en=item['name_en'], name_be=item['name_be'], name_ru=item['name_ru'], link=item['link'], image=image ) SeasonRelatedPartner(season=season, partner=partner).save()
def add_jury_member_pages(apps, schema_editor): HomePage = apps.get_model('home.HomePage') Image = get_image_model(apps) Collection = apps.get_model('wagtailcore.Collection') IndexPage = apps.get_model('cpm_generic.IndexPage') JuryMemberPage = apps.get_model("results.JuryMemberPage") index_page_ct = get_content_type(apps, 'cpm_generic', 'indexpage') jury_member_page_ct = get_content_type(apps, 'results', 'jurymemberpage') collection_id = Collection.objects.filter(depth=1)[0] homepage = HomePage.objects.get(slug='home') juryindex_page = add_subpage(parent=homepage, model=IndexPage, content_type=index_page_ct, **_get_juryindex_kw()) for item in _get_data(): photo = Image(title=item['title'], collection=collection_id) with open(_get_photo_path(item['photo']), 'rb') as photo_file: photo.file.save(name=item['photo'], content=File(photo_file)) photo.save() add_subpage(parent=juryindex_page, model=JuryMemberPage, photo=photo, content_type=jury_member_page_ct, **_get_jurymember_kw(item))
def remove_jury_member_pages(apps, schema_editor): HomePage = apps.get_model('home.HomePage') Image = get_image_model(apps) Collection = apps.get_model('wagtailcore.Collection') IndexPage = apps.get_model('cpm_generic.IndexPage') JuryMemberPage = apps.get_model("results.JuryMemberPage") index_page_ct = get_content_type(apps, 'cpm_generic', 'indexpage') jury_member_page_ct = get_content_type(apps, 'results', 'jurymemberpage') collection_id = Collection.objects.filter(depth=1)[0] homepage = HomePage.objects.get(slug='home') juryindex_page = IndexPage.objects.get(slug=_get_juryindex_kw()['slug']) for item in _get_data(): photo = Image.objects.get(title=item['title'], collection=collection_id) photo.delete() remove_subpage(parent=juryindex_page, model=JuryMemberPage, content_type=jury_member_page_ct, **_get_jurymember_kw(item)) remove_subpage(parent=homepage, model=IndexPage, content_type=index_page_ct, **_get_juryindex_kw())
def add_jurymembers(apps, schema_editor): JuryMember = apps.get_model('cpm_data.JuryMember') SeasonJuryMember = apps.get_model('cpm_data.SeasonRelatedJuryMember') Image = get_image_model(apps) Collection = apps.get_model('wagtailcore.Collection') collection_id = Collection.objects.filter(depth=1)[0] season = _get_season(apps) for item in sorted(_get_data(), key=itemgetter('name_en'), reverse=True): photo = Image(title=item['name_en'], collection=collection_id) with open(_get_photo_path(item['photo']), 'rb') as photo_file: photo.file.save(name=item['photo'], content=File(photo_file)) photo.save() jury_member = JuryMember( name_en=item['name_en'], name_be=item['name_be'], name_ru=item['name_ru'], info_en=item['info_en'], info_be=item['info_be'], info_ru=item['info_ru'], country=item['country'], photo=photo ) jury_member.save() SeasonJuryMember(season=season, jury_member=jury_member).save()
def get_film_frame(apps, item): Image = get_image_model(apps) Collection = apps.get_model('wagtailcore.Collection') collection_id = Collection.objects.filter(depth=1)[0] title = slugify(item['film_title_en']) frame = Image(title=title, collection=collection_id) photo_file = os.path.join(DIR_0017, item['frame']) frame.file.save(name=title + os.extsep + '.jpg', content=File(open(photo_file, 'rb'))) return frame
def get_parner_image(apps, item): Image = get_image_model(apps) Collection = apps.get_model('wagtailcore.Collection') collection_id = Collection.objects.filter(depth=1)[0] title = slugify(item['name_en']) frame = Image(title=title, collection=collection_id) photo_file = os.path.join(DIR_0017, item['image']) frame.file.save( name=title + os.extsep + '.jpg', content=File(open(photo_file, 'rb')) ) return frame
def remove_partners_pages(apps, schema_editor): Image = get_image_model(apps) Collection = apps.get_model('wagtailcore.Collection') PartnerPage = apps.get_model("results.PartnerPage") ResultsRelatedPartner = apps.get_model('results.ResultsRelatedPartner') partner_page_ct = get_content_type(apps, 'results', 'partnerpage') collection_id = Collection.objects.filter(depth=1)[0] HomePage = apps.get_model('home.HomePage') homepage = HomePage.objects.get(slug='home') IndexPage = apps.get_model('cpm_generic.IndexPage') partnersindex_page = IndexPage.objects.get(slug='Partners') partners_data = get_partners_2012_data() results2012_page = get_results_page(apps) related_film_ids = chain.from_iterable( ResultsRelatedPartner.objects.filter( partner=PartnerPage.objects.filter(title=item['name_en']), page=results2012_page, ).values_list('id', flat=True) for item in partners_data ) ResultsRelatedPartner.objects.filter(id__in=related_film_ids).delete() for item in partners_data: title = slugify(item['name_en']) photo = Image.objects.get(title=title, collection=collection_id) photo.delete() remove_subpage( parent=partnersindex_page, model=PartnerPage, content_type=partner_page_ct, **_get_partner_kw(item) ) index_page_ct = get_content_type(apps, 'cpm_generic', 'indexpage') remove_subpage( homepage, IndexPage, content_type=index_page_ct, slug='Partners', )
def remove_films_pages(apps, schema_editor): Image = get_image_model(apps) Collection = apps.get_model('wagtailcore.Collection') FilmPage = apps.get_model("results.FilmPage") ResultsRelatedWinner = apps.get_model('results.ResultsRelatedWinner') film_page_ct = get_content_type(apps, 'results', 'filmpage') collection_id = Collection.objects.filter(depth=1)[0] HomePage = apps.get_model('home.HomePage') homepage = HomePage.objects.get(slug='home') IndexPage = apps.get_model('cpm_generic.IndexPage') filmsindex_page = IndexPage.objects.get(slug='films') films2012_data = get_films_2012_data() results2012_page = get_results_page(apps) related_film_ids = chain.from_iterable( ResultsRelatedWinner.objects.filter( film=FilmPage.objects.filter(title=item['film_title_en']), page=results2012_page, ).values_list('id', flat=True) for item in films2012_data) ResultsRelatedWinner.objects.filter(id__in=related_film_ids).delete() for item in films2012_data: title = slugify(item['film_title_en']) photo = Image.objects.get(title=title, collection=collection_id) photo.delete() remove_subpage(parent=filmsindex_page, model=FilmPage, content_type=film_page_ct, **_get_film_kw(item)) index_page_ct = get_content_type(apps, 'cpm_generic', 'indexpage') remove_subpage( homepage, IndexPage, content_type=index_page_ct, slug='films', )
def add_films_2017(apps, schema_editor): Film = apps.get_model('cpm_data.Film') Image = get_image_model(apps) Collection = apps.get_model('wagtailcore.Collection') collection_id = Collection.objects.filter(depth=1)[0] for film_data in _get_data(): if Film.objects.filter(title_en=film_data['title_en']).exists(): continue frame = Image(title=film_data['title_en'], collection=collection_id) with open(os.path.join(DATA_DIR, film_data['frame']), 'rb') as frame_f: frame.file.save(name=film_data['frame'], content=File(frame_f)) frame.save() film_data = film_data.copy() film_data.pop('frame') Film(frame=frame, **film_data).save()
def add_jurymembers(apps, schema_editor): JuryMember = apps.get_model('cpm_data.JuryMember') Image = get_image_model(apps) Collection = apps.get_model('wagtailcore.Collection') collection_id = Collection.objects.filter(depth=1)[0] for item in _get_data(): photo = Image(title=item['name_en'], collection=collection_id) with open(_get_photo_path(item['photo']), 'rb') as photo_file: photo.file.save(name=item['photo'], content=File(photo_file)) photo.save() JuryMember( name_en=item['name_en'], name_be=item['name_be'], name_ru=item['name_ru'], info_en=item['info_en'], info_be=item['info_be'], info_ru=item['info_ru'], country=item['country'], photo=photo ).save()
def add_jury_member_pages(apps, schema_editor): Image = get_image_model(apps) IndexPage = apps.get_model('cpm_generic.IndexPage') JuryMemberPage = apps.get_model("results.JuryMemberPage") Collection = apps.get_model('wagtailcore.Collection') jury_member_page_ct = get_content_type(apps, 'results', 'jurymemberpage') collection_id = Collection.objects.filter(depth=1)[0] juryindex_page = IndexPage.objects.get(slug='jury') for item in get_jury_data(): photo = Image(title=item['title'], collection=collection_id) photo_file = os.path.join(MIGRATION_DIR, item['photo']) photo.file.save( name=item['title'] + os.extsep + item['photo_ext'], content=File(open(photo_file, 'rb')) ) photo.save() slug = slugify(item['title']) add_subpage( parent=juryindex_page, model=JuryMemberPage, title=item['title'], slug=slug, name_en=item['name_en'], name_be=item['name_be'], name_ru=item['name_ru'], info_en=item['info_en'], info_be=item['info_be'], info_ru=item['info_ru'], country=item['country'], photo=photo, content_type=jury_member_page_ct, )