Exemple #1
0
	def post(self):
		key = self.get_argument("key", None)
		if key:
			entry = models.Entry.get(key)
			entry.title = self.get_argument("title")
			entry.markdown = self.get_argument("markdown")
			entry.html = markdown.markdown(self.get_argument("markdown"))
		else:
			title = self.get_argument("title")
			slug = unicodedata.normalize("NFKD", title).encode(
				"ascii", "ignore")
			slug = re.sub(r"[^\w]+", " ", slug)
			slug = "-".join(slug.lower().strip().split())
			#name = "/".join(slug.lower().strip().split())
			if not slug: slug = "entry"
			while True:
				existing = db.Query(models.Entry).filter("slug =", slug).get()
				if not existing or str(existing.key()) == key:
					break
				slug += "-2"
			entry = models.Entry(
				key_name= "k/"+slug,
				origin = "blogzz",
				author=self.current_user,
				title=title,
				slug=slug,
				markdown=self.get_argument("markdown"),
				html=markdown.markdown(self.get_argument("markdown")),
			)
		entry.put()
		self.redirect("/entry/" + entry.slug)
Exemple #2
0
def import_buzzes(blog,posts,user):
	"""Eventually this has to evolve into a Class intead of a method"""
	for post in posts:
		title = post.title
		slug = unicodedata.normalize("NFKD", title).encode(
			"ascii", "ignore")
		slug = re.sub(r"[^\w]+", " ", slug)
		slug = "-".join(slug.lower().strip().split())
		#name = "/".join(slug.lower().strip().split())
		if not slug: slug = "entry"
		existing = db.Query(models.Entry).filter("slug =", slug).get()
		if not existing:
			dp,_,_ = post.published.partition('.')
			#du,_,_ = post.updated.partition('.')
			entry = models.Entry(
				key_name= "k/"+slug, #maybe we don't need a key_name since slug takes care of uniqueness
				origin = "buzz",
				blog = blog,
				author=user,
				title=title,
				slug=slug,
				markdown=post.content,
				html=markdown.markdown(post.content),
				
				published=datetime.datetime.strptime(dp,"%Y-%m-%dT%H:%M:%S")
				#updated=datetime.datetime.strptime(du,"%Y-%m-%dT%H:%M:%S")
			)
			entry.put()
			
			for attachment in post.attachments:
				logging.debug("%s, %s" % (attachment.preview, attachment.enclosure))
				attach = models.Attachment(
					entry = entry,
					type= attachment.type
				)
				if attachment.preview:
					attach.preview= attachment.preview.uri
				if attachment.enclosure:
					attach.enclosure= attachment.enclosure.uri
				'''if attachment.type == 'video':
					entry.type = 'video' '''
				
				attach.put()
			
			#entry.put()