def fix_series(): old_series = Series.objects.filter( created__lte=settings.NEW_SITE_CREATION_DATE) no_prior_revs = old_series.exclude( revisions__created__lte=settings.NEW_SITE_CREATION_DATE) print "%d series to fix..." % no_prior_revs.count() for series in no_prior_revs: print "Fixing series %s" % series old = VieuxBoisSeries.objects.get(pk=series.pk) # Create changeset changeset = Changeset(indexer=ANON_USER, approver=ANON_USER, state=states.APPROVED, change_type=CTYPES['series'], migrated=True, date_inferred=True) changeset.save() # Circumvent automatic field behavior. # all dates and times guaranteed to be valid mc = MigratoryChangeset.objects.get(id=changeset.id) mc.created = old.created mc.modified = old.modified mc.save() changeset = Changeset.objects.get(id=changeset.id) comment_text = COMMENT_TEXT + COMMENT_TEXT_FOR_ADD changeset.comments.create(commenter=ANON_USER, text=comment_text, old_state=states.APPROVED, new_state=states.APPROVED) comment = changeset.comments.all()[0] comment.created = changeset.created comment.save() revision = SeriesRevision(changeset=changeset, series=series, country=old.country, language=old.language, publisher=old.publisher, name=old.name, imprint=old.imprint, format=old.format, year_began=old.year_began, year_ended=old.year_ended, publication_notes=old.publication_notes, tracking_notes=old.tracking_notes, notes=old.notes, date_inferred=True) revision.save() # Circumvent automatic field behavior. mr = MigratorySeriesRevision.objects.get(id=revision.id) mr.created = changeset.created mr.modified = changeset.created mr.save()
def any_added_series_rev(any_adding_changeset, series_add_values): sr = SeriesRevision(changeset=any_adding_changeset, leading_article=True, **series_add_values) sr.save() return sr