summaryrefslogtreecommitdiff
path: root/app/posts/importer.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/posts/importer.py')
-rw-r--r--app/posts/importer.py107
1 files changed, 107 insertions, 0 deletions
diff --git a/app/posts/importer.py b/app/posts/importer.py
new file mode 100644
index 0000000..7ed4782
--- /dev/null
+++ b/app/posts/importer.py
@@ -0,0 +1,107 @@
+for e in essaysold:
+ if e.featured_image:
+ feat = e.featured_image
+ else:
+ feat = None
+ if e.meta_description:
+ meta = e.meta_description
+ else:
+ meta = "need meta"
+ new, created = Post.objects.get_or_create(
+ old_id=e.pk,
+ post_type=2,
+ title=e.title,
+ subtitle=e.sub_title,
+ dek=e.dek,
+ slug=e.slug,
+ prologue_markdown=e.preamble,
+ body_markdown=e.body_markdown,
+ pub_date=e.pub_date,
+ enable_comments=e.enable_comments,
+ status=e.status,
+ meta_description=meta,
+ originally_published_by=e.originally_published_by,
+ originally_published_by_url=e.originally_published_by_url,
+ featured_image=feat,
+ has_video=e.has_video,
+ epilogue_markdown=e.afterword,
+ )
+ print(created)
+
+
+
+# migrate jrnl to posts
+for e in Entry.objects.all():
+ if e.meta_description:
+ meta_description = e.meta_description
+ else:
+ meta_description = "needs"
+ if e.image:
+ old_image = e.image
+ else:
+ old_image = None
+ p, created = Post.objects.get_or_create(
+ old_id=e.pk,
+ title = e.title,
+ short_title = '',
+ subtitle = e.subtitle,
+ slug = e.slug,
+ body_markdown = e.body_markdown,
+ body_html = e.body_html,
+ dek = e.dek,
+ meta_description = meta_description,
+ pub_date = e.pub_date,
+ enable_comments = e.enable_comments,
+ status = e.status,
+ featured_image = e.featured_image,
+ post_type = PostType.JRNL,
+ template_name = e.template_name,
+ has_video = e.has_video,
+ point = e.point,
+ location = e.location,
+ old_image=old_image
+ )
+ for b in e.books.all():
+ c = Book.objects.get(
+ slug=b.slug,
+ title=b.title,
+ )
+ p.books.add(c)
+ for f in e.field_notes.all():
+ c = Post.objects.get(
+ slug=f.slug,
+ title=f.title,
+ )
+ p.field_notes.add(c)
+ p.save()
+
+#Then after they're all in there:
+ctype = ContentType.objects.get(app_label='posts',model='post')
+oldctype = ContentType.objects.get(app_label='jrnl',model='entry')
+for e in Entry.objects.all():
+ p = Post.objects.get(title=e.title,old_id=e.id)
+ if e.related:
+ for t in e.related.all():
+ if t.model_name == oldctype:
+ tp = ctype
+ else:
+ tp = t.model_name
+ c = RelatedPost.objects.get(
+ model_name=tp,
+ title=t.title,
+ slug=t.slug,
+ pub_date=t.pub_date
+ )
+ p.related.add(c)
+ p.save()
+
+# Then to port comments:
+ctype = ContentType.objects.get(app_label='posts',model='post')
+oldctype = ContentType.objects.get(app_label='jrnl',model='entry')
+for c in Comment.objects.filter(content_type=oldctype):
+ e = Entry.objects.get(pk=c.object_pk)
+ p = Post.objects.get(title=e.title,old_id=e.id)
+ c.object_pk = p.pk
+ c.content_type = ctype
+ print("%s --> %s" %(c.content_object,p))
+ c.save()