コード例 #1
0
ファイル: merge_data.py プロジェクト: eddowding/foodtrade
def update_image(request):
    img_url = request.POST.get('img')
    img_url = img_url.replace("bigger", "normal")
    img_url = img_url.replace("/web_retina", "")
    up = UserProfile()
    try:
        user_details = up.get_profile_by_profile_img(img_url)
        bot_twitter = get_twitter_obj(settings.BOT_ACCESS_TOKEN,
                                      settings.BOT_ACCESS_TOKEN_SECRET)
        details = bot_twitter.show_user(screen_name=user_details['username'])
        image_desc = {'profile_img': details['profile_image_url']}
        up.update_profile_fields({"useruid": user_details['useruid']},
                                 image_desc)
        return HttpResponse(
            json.dumps({
                "status": "ok",
                "src": details['profile_image_url']
            }))

    except:
        try:
            user_details = up.get_profile_by_profile_banner_url(img_url)
            bot_twitter = get_twitter_obj(settings.BOT_ACCESS_TOKEN,
                                          settings.BOT_ACCESS_TOKEN_SECRET)
            details = bot_twitter.show_user(
                screen_name=user_details['username'])
            image_desc = {
                'profile_banner_url':
                details.get("profile_background_image_url_https", "")
            }

            up.update_profile_fields({"useruid": user_details['useruid']},
                                     image_desc)
            return HttpResponse(
                json.dumps({
                    "status":
                    "ok",
                    "src":
                    details.get("profile_background_image_url_https", "")
                }))
        except:
            pass

    return HttpResponse(
        json.dumps({
            "status": "error",
            "message": "No image was found"
        }))
コード例 #2
0
    def process_response(self, request, response):
        # Avoid unnecessary work
        try:
            if request.user.is_authenticated() and "/accounts/twitter/login/callback/" in request.path:
                social_account = SocialAccount.objects.get(user__id = request.user.id)
                extra_data = social_account.extra_data
                image_desc = {'profile_img': extra_data['profile_image_url']}
                up = UserProfile()                
                up.update_profile_fields({"useruid":request.user.id}, image_desc)
        except:
            pass


        if response.has_header('Access-Control-Allow-Origin'):
            return response
 
        response['Access-Control-Allow-Origin']  = XS_SHARING_ALLOWED_ORIGINS 
        response['Access-Control-Allow-Methods'] = ",".join( XS_SHARING_ALLOWED_METHODS )
        return response