Commits

Adam Knight committed 4c29fc4

Work on API

Comments (0)

Files changed (2)

sitepoet/metaweblog.py

 
 import urlparse
 from django.contrib.auth.models import User
-from sitepoet.models import Story
+from sitepoet.models import Story, Section
 from tagging.models import Tag
 from sitepoet.xmlrpc import public
 from django.conf import settings
-# import sitepoet.config
+from django.core.urlresolvers import reverse
 import xmlrpclib # import DateTime
 
 def authenticated(pos=1):
 def full_url(url):
 	return urlparse.urljoin(settings.SITE_URL, url)
 
-@public
-@authenticated()
-def blogger_getUsersBlogs(user, appkey):
-	"""
-	an array of <struct>'s containing the ID (blogid), name
-	(blogName), and URL (url) of each blog.
-	"""
-	return [{
-			'blogid': settings.SITE_ID,
-			# 'blogName': sitepoet.config.title,
-			'url': settings.SITE_URL
-			}]
-
-@public
-@authenticated()
-def metaWeblog_getCategories(user, blogid):
-	tags = Tag.objects.all()
-	return [tag for tag in tags]
-
 # example... this is what wordpress returns:
 # {'permaLink': 'http://gabbas.wordpress.com/2006/05/09/hello-world/',
 #  'description': 'Welcome to <a href="http://wordpress.com/">Wordpress.com</a>. This is your first post. Edit or delete it and start blogging!',
 		struct['dateCreated'] = format_date(post.date_published)
 	return struct
 
+def _update_post(post, struct):
+	if struct.get('dateCreated', None):
+		post.date_published = struct['dateCreated']
+	if struct.has_key('title'):
+		post.title = struct['title']
+	if struct.has_key('description'):
+		post.teaser = struct['description']
+	if struct.has_key('mt_text_more'):
+		post.content = struct['mt_text_more']
+	if struct.has_key('mt_tags'):
+		post.tags = struct['mt_tags']
+	elif struct.has_key('mt_keywords'):
+		post.tags = struct('mt_keywords')
+	if struct.has_key('mt_basename'):
+		post.slug = struct['mt_basename']
+
+''' Blogger API V1 '''
+
+@public
+@authenticated(pos=2)
+def blogger_newPost(user, appkey, blogid, content, publish):
+	pass
+
+@public
+@authenticated(pos=2)
+def blogger_editPost(user, appkey, postid, content, publish):
+	pass
+
+@public
+@authenticated()
+def blogger_getUsersBlogs(user, appkey):
+	"""
+	an array of <struct>'s containing the ID (blogid), name
+	(blogName), and URL (url) of each blog.
+	"""
+	print "entered"
+	sections = Section.objects.all()
+	print "got sections"
+	result = [{
+			'blogid': section.slug,
+			'blogName': section.name,
+			'url': settings.SITE_URL + reverse('story-archive', kwargs={'section':section.slug})
+			} for section in sections]
+	print "results:", result
+	return result
+
+@public
+@authenticated()
+def blogger_getUserInfo(user, appkey):
+	return {
+		'nickname':user.username,
+		'userid':user.id,
+		'url':settings.SITE_URL,
+		'email':user.email,
+		'lastname':user.last_name,
+		'firstname':user.first_name,
+		}
+
+@public
+@authenticated()
+def metaWeblog_getCategories(user, blogid):
+	tags = Tag.objects.all()
+	result = [{'description':tag.name} for tag in tags]
+	return result
+
 @public
 @authenticated()
 def metaWeblog_getPost(user, postid):
 @public
 @authenticated()
 def metaWeblog_getRecentPosts(user, blogid, num_posts):
-	posts = Story.objects.order_by('-date_published')[:int(num_posts)]
+	posts = Story.objects.filter(section__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):
-	body = struct['description']
-	# todo - parse out technorati tags
-	post = Story(title = struct['title'],
-				body = body,
-				author = user,
-				create_date = struct['dateCreated'],
-				status = publish,
-				tags = struct.get('mt_tags', None),
-	)
+	post = Story(status = (not publish))
+	post.user = user
+	_update_post(post, struct)
+	post.save()
+	post.sites = (blogid,)
 	post.save()
 	return post.id
 
 @authenticated()
 def metaWeblog_editPost(user, postid, struct, publish):
 	post = Story.objects.get(id=postid)
-	title = struct.get('title', None)
-	if title is not None:
-		post.title = title
-	body = struct.get('description', None)
-	if body is not None:
-		post.body = body
-		# todo - parse out technorati tags
-	if user:
-		post.author = user
-	post.status = publish
-	post.tags = struct.get('mt_tags', post.tags)
-	post.slug = struct.get('mt_basename', post.slug)
+	post.status = (not publish)
+	_update_post(post, struct)
 	post.save()
 	return True
 

sitepoet/xmlrpc.py

                 data, getattr(mod, '_dispatch', None)
             )
     except:
-        #traceback.print_exc()
+        traceback.print_last()
         # internal error, report as HTTP server error
         response = SimpleXMLRPCServer.xmlrpclib.dumps(
             SimpleXMLRPCServer.xmlrpclib.Fault(1, "%s:%s" % (