Adam Knight avatar Adam Knight committed 8d02e90

More work on the API

Comments (0)

Files changed (1)

sitepoet/metaweblog.py

 
 import urlparse
 from django.contrib.auth.models import User
-from sitepoet.models import Story, Section
+from sitepoet.models import *
 from tagging.models import Tag
+from tagging.utils import parse_tag_input
 from sitepoet.xmlrpc import public
 from django.conf import settings
 from django.core.urlresolvers import reverse
 		# 'mt_excerpt': post.teaser,
 		'mt_text_more': post.content,
 		# 'mt_allow_comments': 1,
-		# 'mt_allow_pings': 1}
+		# 'mt_allow_pings': 1
+		'mt_convert_breaks': str(post.content_format), #Sadly, we have to use one format for both components.
 		}
 	if post.date_published:
 		struct['dateCreated'] = format_date(post.date_published)
+	
+	return struct
+
+def tag_struct(tag):
+	struct = {
+		'categoryId': tag.id,
+		'categoryName': tag.name,
+	}
 	return struct
 
 def _update_post(post, struct):
 	pass
 
 @public
+@authenticated(pos=2)
+def blogger_deletePost(user, appkey, postid, publish):
+	post = Story.objects.get(id=postid)
+	post.delete()
+	return True
+
+@public
 @authenticated()
 def blogger_getUsersBlogs(user, appkey):
 	"""
 @public
 @authenticated()
 def metaWeblog_getRecentPosts(user, blogid, num_posts):
-	posts = Story.objects.filter(section__exact=blogid).order_by('-date_published')[:int(num_posts)]
+	posts = Story.objects.filter(section__name__exact=blogid).order_by('-date_published')[:int(num_posts)]
 	return [post_struct(post) for post in posts]
 
 @public
 @authenticated()
 def metaWeblog_newPost(user, blogid, struct, publish):
-	post = Story(status = (not publish))
+	post = Story(status = publish)
 	post.user = user
 	_update_post(post, struct)
-	post.save()
-	post.sites = (blogid,)
+	section = Section.objects.get(name__exact=blogid)
+	post.section = blogid
 	post.save()
 	return post.id
 
 @authenticated()
 def metaWeblog_editPost(user, postid, struct, publish):
 	post = Story.objects.get(id=postid)
-	post.status = (not publish)
+	post.status = publish
 	_update_post(post, struct)
 	post.save()
 	return True
 
-@public
-@authenticated(pos=2)
-def blogger_deletePost(user, appkey, postid, publish):
-	post = Story.objects.get(id=postid)
-	post.delete()
-	return True
-
 # http://qoli.de/blog/2007/nov/19/implementing-metaweblog-api/
 @public
 @authenticated()
 	attachment.save()
 
 	return {'url': attachment.get_content_url()}
+
+@public
+@authenticated()
+def mt_getPostCategories(user, postid):
+	post = Story.objects.get(id=int(postid))
+	if (post.tags):
+		tags = [tag_struct(t) for t in Tag.objects.filter(name__in=parse_tag_input(post.tags))]
+	else:
+		tags = []
+	return tags
+
+@public
+@authenticated()
+def mt_getCategoryList(user, blogid):
+	return [tag_struct(t) for t in Tag.objects.all()]
+
+@public
+def mt_supportedTextFilters():
+	return [{'label': f[1], 'key': str(f[0])} for f in CONTENT_FORMATTERS]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.