def show_document(request, name): if not settings.LOCAL_INSTANCE: raise Http404 document = Document(name) if not document.exists(): raise Http404 return render_to_response( "document.html", { 'document': document }, context_instance=RequestContext(request), )
def create_post(post, data): post_url = get_post_url(post) if post_url == '/blog/2006/may/worried-sick.html': print "XXXXXXXXX" posted_on = parse_date(post["fields"]["posted_on"]) post_name = convert_to_document_name(post_url) post_title = post[u"fields"]["title"] document = Document(post_name) if not document.exists(): document.create( index_content = post[u'fields']["content"], format = "html", author = author, ) else: document.set_raw_index(post[u'fields']['content'], 'html') document.meta.author = author document.meta.title = post_title document.meta.url = post_url document.meta.type = "blog_post" document.meta.title_slug = post['fields']['title_slug'] document.meta.posted_on = post['fields']['posted_on'] for label_id in post['fields']['categories']: label_name = data["blog.category"][str(label_id)]["name_slug"] document.meta.setdefault("labels", []).append(label_name) gsettings.LOCAL_REPO_PATH.joinpath( "blogs/main/labels/%s.lst" % label_name ).open("a+").write("%s\n" % post_url) document.meta.save() blog_document(document, post_url, blog, posted_on)
def main(): d = collect_data() # read data from json file # create blog document = Document("blogs@main") if not document.exists(): document.create( index_content = "A blog by Amit Upadhyay", format = "html", author = author, ) else: document.set_raw_index("A blog by Amit Upadhyay", "html") document.meta.author = author document.meta.title = "Anything Else" document.meta.subtitle = "Nerdier than thou" document.meta.url = "/blog/" document.meta.type = "blog" document.meta.save() # create blog folder blog_folder = gsettings.LOCAL_REPO_PATH.joinpath("blogs/main") if not blog_folder.exists(): blog_folder.makedirs() labels_folder = gsettings.LOCAL_REPO_PATH.joinpath("blogs/main/labels") if not labels_folder.exists(): labels_folder.makedirs() for label_id, label_data in d["blog.category"].items(): create_label(label_id, label_data, d) for post in d[u"blog.post"]: create_post(post, d) print "imported", len(d["blog.post"]), "posts"
def create_label(blog, author, label_name, label_slug, label_description=None): if label_description is None: label_description = label_name # create label document document = Document( "blogs@%s@label@%s" % (blog, label_slug) ) if not document.exists(): document.create( index_content = label_name, format = "html", author = author, ) else: document.set_raw_index(label_name, "html") document.meta.author = author document.meta.title = label_name document.meta.description = label_descrption document.meta.slug = label_slug document.meta.type = "blog_label" document.meta.save()
def create_blog(blog, author, title, subtitle): document = Document("blogs@%" % blog) if not document.exists(): document.create( index_content = title, format = "html", author = author, ) else: document.set_raw_index(title, "html") document.meta.author = author document.meta.title = title document.meta.subtitle = subtitle document.meta.url = "/%s/" % blog document.meta.type = "blog" document.meta.save() # create blog folder blog_folder = gsettings.LOCAL_REPO_PATH.joinpath("blogs/%s" % blog) if not blog_folder.exists(): blog_folder.makedirs() labels_folder = gsettings.LOCAL_REPO_PATH.joinpath("blogs/%s/labels" % blog) if not labels_folder.exists(): labels_folder.makedirs()
def create_label(label_id, label_data, blog_data): # create label document document = Document( "blogs@main@label@%s" % label_data["name_slug"] ) if not document.exists(): document.create( index_content = label_data["name"], format = "html", author = author, ) else: document.set_raw_index(label_data["name"], "html") document.meta.author = author document.meta.title = label_data["name"] document.meta.description = label_data["descrption"] document.meta.slug = label_data["name_slug"] document.meta.type = "blog_label" document.meta.label_id = label_id document.meta.save()