Commits

dil...@echo.dil.pp.ru  committed b740576

Enable setting of comment screening/disabling and access level
when initially creating a post in LJ

  • Participants
  • Parent commits 2c24246

Comments (0)

Files changed (1)

File apps/livejournal/utils.py

 LJ_RPC = "http://www.livejournal.com/interface/xmlrpc"
 
 
-def create_args(local_post, remote_post=None):
+def create_args(local_post, remote_post=None, edit_mode=False):
     args = {
         "username" : settings.LJ_USERNAME,
         "password" : settings.LJ_PASSWORD,
             })
 
     if remote_post:
-        args.update({
-            'itemid': remote_post.lj_id,
-            'security': remote_post.access_level,
-            })
+        args.update({ 'security': remote_post.access_level, })
         args['props'].update({
             'opt_screening': remote_post.screen_comments,
             'opt_nocomments': remote_post.no_comments,
             })
 
+	# only valid when editing or deleting
+        if edit_mode:
+	    args.update({'itemid': remote_post.lj_id, })
+
     return args
 
 
 def lj_edit(local_post, remote_post):
     server = xmlrpclib.ServerProxy(LJ_RPC)
-    response = server.LJ.XMLRPC.editevent(create_args(local_post, remote_post))
+    response = server.LJ.XMLRPC.editevent(create_args(local_post, remote_post, True))
 
 
 def lj_create(local_post, remote_post):
     server = xmlrpclib.ServerProxy(LJ_RPC)
-    response = server.LJ.XMLRPC.postevent(create_args(local_post))
+    response = server.LJ.XMLRPC.postevent(create_args(local_post, remote_post, False ))
 
     remote_post.lj_id = response.get('itemid')
     # it will be saved as we was called at pre_save
 def lj_delete(instance, **kwargs):
     if instance.need_crosspost:
         server = xmlrpclib.ServerProxy(LJ_RPC)
-        response = server.LJ.XMLRPC.editevent(create_args(None, instance))
+        response = server.LJ.XMLRPC.editevent(create_args(None, instance, True))
 
 
 def lj_crosspost(instance, **kwargs):