1. belegnar
  2. byteflow

Commits

dobrych  committed e3d73c3

Bunch of compatibility improvements for xmlrpc blog api, supporting more features of WP & MT

  • Participants
  • Parent commits 4e245e9
  • Branches default

Comments (0)

Files changed (1)

File apps/xmlrpc/metaweblog.py

View file
 import os
 from datetime import datetime
 from time import strptime, mktime
-from xmlrpclib import Fault, Boolean
+from xmlrpclib import Fault, Boolean, DateTime
 
 from django.contrib.auth.models import User
 from django.contrib.sites.models import Site
 from blog.models import Post
 from xmlrpc.utils import signature
 from tagging.models import Tag
+from render import RENDER_METHODS
 
 
 def auth_user(username, password):
     return datetime.now()
 
 def tags(content):
-    tags = content.get('mt_keywords', content.get('categories'))
+    tags = content.get('mt_keywords')
     if isinstance(tags, list):
         return ' '.join(tags)
     return tags
 
 def post_struct(post):
-    return {'userid': post.author.username,
-            'pubDate': post.date.isoformat(),
+    return {'userid': post.author.pk,
+            'pubDate': DateTime(post.date),
+            'dateCreated': DateTime(post.date), #iso8601
+            'date_created_gmt': DateTime(post.date),
             'postid': str(post.id),
             'description': post.text,
             'title': post.name,
             'link': post.get_absolute_url(),
-            'permalink': post.get_absolute_url(),
+            'permaLink': post.get_absolute_url(),
+            'categories': [],
+            'post_status': "draft" if post.is_draft else "publish",
+            'wp_slug': post.slug,
+            'wp_author_id': post.author.pk,
+            'wp_author_display_name': post.author.username,
             'mt_allow_comments': int(post.enable_comments),
-            'mt_keywords': [tag_struct(tag) for tag in post.get_tag_objects()]}
+            'mt_keywords': ', '.join([t.name for t in post.get_tag_objects()]),
+            'mt_tags': ', '.join([t.name for t in post.get_tag_objects()]),
+            'mt_basename': post.slug,
+            'custom_fields': [],}
 
 
 def tag_struct(tag):
     ~~~~~~~~~~~~
     * a list.
     """
-    tags = Tag.objects.all()
-    return [tag_struct(tag) for tag in tags]
+    return [] # disable categories completely
 
 
 @signature(str, str, int, dict, bool)
                     render_method=settings.RENDER_METHOD)
 
         post.enable_comments = bool(content.get('mt_allow_comments', True))
-        post.tags = tags(content)
+        post.tags = content.get('mt_tags', content.get('mt_keywords'))
+        post.slug = content.get('mt_basename', content.get('wp_slug'))
         if 'mt_pingable' in content:
             pass # TODO
     except Exception, e:
         post.enable_comments = bool(content.get('mt_allow_comments', True))
         if 'mt_pingable' in content:
             pass # TODO
-        post.tags = tags(content)
+        post.tags = content.get('mt_tags', content.get('mt_keywords'))
+        post.slug = content.get('mt_basename', content.get('wp_slug'))
         post.save()
         return str(post.id)
     except Post.DoesNotExist:
     dated_path = datetime.now().strftime('%Y_%m_%d_') + os.path.basename(file_name)
     relative_path = os.path.join('upload', dated_path)
     target_path = os.path.abspath(os.path.join(settings.STATIC_ROOT, relative_path))
-    target_url = os.path.join(settings.STATIC_ROOT, relative_path)
+    target_url = os.path.join(settings.STATIC_URL, relative_path)
     open(target_path, 'w').write(file_data)
-    return target_url
+    return [os.path.basename(file_name), target_url, '']
+
+@signature(int, str, str)
+def mt_getPostCategories(postid, username, password):
+    """Dummy empty method. No categories in byteflow"""
+    return []
+
+@signature(int, str, str)
+def mt_getCategoryList(blogid, username, password):
+    """Dummy empty method. No categories in byteflow"""
+    return []
+
+@signature()
+def mt_supportedTextFilters():
+    """
+    Text filters aka markdown, plain html, etc support
+    """
+    return [{k:v} for k,v in RENDER_METHODS]
+
+
+#wp.getCategories