# -*- coding: utf-8 -*-

import requests
from django.conf import settings
from social_publisher import vk
from . import base


class VKImageToWallBackend(base.BaseBackend):
    name = 'vk_image_to_wall'
    auth_provider = 'vk-oauth'

    def get_api(self, social_user):
        return vk.API(access_token=social_user.extra_data.get('access_token'),
                      app_id=settings.VK_APP_ID, scope=['photos', 'wall'])

    def get_api_publisher(self, social_user):
        """
            files: {'file0':<file>}
            message: 'mess'
        """

        def _post(**kwargs):
            api = self.get_api(social_user)
            server_data = api.photos.getWallUploadServer()
            upload_data = requests.post(server_data['upload_url'],
                                        files=kwargs['files']).json()

            photos_data = api.photos.saveWallPhoto(**upload_data)
            kwargs['attachments'] = 'photo{owner_id}_{id}'.format(**photos_data[0])
            response = api.wall.post(**kwargs)

            server_data.update(response)
            return server_data

        return _post

@@ -132,19 +132,8 @@
 s VK
-ImageToWall
 Back
@@ -173,22 +173,8 @@
  'vk
-_image_to_wall
 '%0A  
@@ -318,16 +318,16 @@
 oken'),%0A
-
         
@@ -394,16 +394,605 @@
 all'%5D)%0A%0A
+    def get_api_publisher(self, social_user):%0A        %22%22%22%0A            owner_id - VK user or group%0A            from_group - 1 by group, 0 by user%0A            message - text%0A            attachments - comma separated links or VK resources ID's%0A            and other https://vk.com/dev.php?method=wall.post%0A        %22%22%22%0A%0A        def _post(**kwargs):%0A            api = self.get_api(social_user)%0A            response = api.wall.post(**kwargs)%0A            return response%0A%0A        return _post%0A%0A%0Aclass VKImageToWallBackend(VKBackend):%0A    name = 'vk_image_to_wall'%0A    auth_provider = 'vk-oauth'%0A%0A
     def 

add simple vk to wall backend