예제 #1
0
파일: views.py 프로젝트: bopopescu/pd
def share_fb(request, **kwargs):

    if request.method == 'POST':
        photo_id = request.POST["photo_id"]
        comment = request.POST["comment"]

        if not re.match('^[0-9]+$', photo_id):
            raise Exception('Invalid input')

        photo = Photo.objects.select_related('album',
                                             'album__owner').get(id=photo_id)
        if not photo.can_view_photo(request.user):
            raise Exception('unauthorized')

        from account.graphapi import GraphAPI
        fb_user = request.user.get_profile().get_facebook_user()

        graph = GraphAPI(fb_user.access_token)

        photo.original_image.open()
        pd = photo.original_image.file

        graph.put_photo(pd.file)

        response_dict = {"success": True, "message": "Done"}

        return HttpResponse(simplejson.dumps(response_dict, cls=PDEncoder),
                            mimetype='application/javascript')
예제 #2
0
파일: views.py 프로젝트: braskin/pd
def share_fb(request, **kwargs):

    if request.method == 'POST':
        photo_id = request.POST["photo_id"];
        comment = request.POST["comment"];

        if not re.match('^[0-9]+$',photo_id):
            raise Exception('Invalid input')
   
        photo = Photo.objects.select_related('album','album__owner').get(id=photo_id)
        if not photo.can_view_photo(request.user):
            raise Exception('unauthorized')

        from account.graphapi import GraphAPI
        fb_user = request.user.get_profile().get_facebook_user()

        graph=GraphAPI(fb_user.access_token)

        photo.original_image.open()
        pd = photo.original_image.file

        graph.put_photo(pd.file)

        response_dict = { "success":True, "message": "Done" }
    
        return HttpResponse(simplejson.dumps(response_dict, cls=PDEncoder), mimetype='application/javascript')
예제 #3
0
파일: models.py 프로젝트: bopopescu/pd
    def get_name(self):
        if self.name is None:

            from account.graphapi import GraphAPI
            fb_api = GraphAPI(self.access_token)
            prof = fb_api.get_object("me")
            self.name = prof["name"]
            self.save()

        return self.name
예제 #4
0
파일: models.py 프로젝트: braskin/pd
    def get_name(self):
        if self.name is None:
            
            from account.graphapi import GraphAPI
            fb_api = GraphAPI(self.access_token)
            prof = fb_api.get_object("me")
            self.name = prof["name"]
            self.save()

        return self.name
예제 #5
0
파일: views.py 프로젝트: braskin/pd
def add_children(request, **kwargs):
    group, bridge = group_and_bridge(kwargs)
    ctx = group_context(group, bridge)

    signup = kwargs["signup"]

    child_formset = formset_factory(ChildForm)
    formset = child_formset(prefix="child")

    if request.method == "POST":
        formset = child_formset(request.POST, request.FILES, prefix="child")

        if formset.is_valid():
            forms_valid = True
            for form in formset.forms:
                if not form.is_valid():
                    forms_valid = False

            if forms_valid:
                for form in formset.forms:
                    form.save(request)

                if signup:
                    request.session["event"] = "Added Child During Registration"
                    return HttpResponseRedirect(reverse("new_home"))
                else:
                    request.session["event"] = "Added Child After Registration"
                    return HttpResponseRedirect(reverse("home"))

    fb_profile = None
    if signup:
        fb_user = request.user.get_profile().get_facebook_user()
        if fb_user is not None:
            from account.graphapi import GraphAPI

            fb_api = GraphAPI(fb_user.access_token)
            fb_profile = fb_api.get_object("me")

        else:
            tolog("NO FBUSER")

    ctx.update(
        {
            "profile": request.user.get_profile(),
            "fb_profile": fb_profile,
            "child_formset": formset,
            "signup": signup,
            "message": request.session.pop("message", None),
        }
    )

    if signup:
        return render_to_response("account/signup_add_children.html", RequestContext(request, ctx))
    else:
        return render_to_response("account/add_children.html", RequestContext(request, ctx))
예제 #6
0
def add_children(request, **kwargs):
    group, bridge = group_and_bridge(kwargs)
    ctx = group_context(group, bridge)

    signup = kwargs["signup"]

    child_formset = formset_factory(ChildForm)
    formset = child_formset(prefix="child")

    if request.method == "POST":
        formset = child_formset(request.POST, request.FILES, prefix="child")

        if formset.is_valid():
            forms_valid = True
            for form in formset.forms:
                if not form.is_valid():
                    forms_valid = False

            if forms_valid:
                for form in formset.forms:
                    form.save(request)

                if signup:
                    request.session[
                        "event"] = 'Added Child During Registration'
                    return HttpResponseRedirect(reverse("new_home"))
                else:
                    request.session["event"] = 'Added Child After Registration'
                    return HttpResponseRedirect(reverse("home"))

    fb_profile = None
    if signup:
        fb_user = request.user.get_profile().get_facebook_user()
        if fb_user is not None:
            from account.graphapi import GraphAPI
            fb_api = GraphAPI(fb_user.access_token)
            fb_profile = fb_api.get_object("me")

        else:
            tolog("NO FBUSER")

    ctx.update({
        "profile": request.user.get_profile(),
        "fb_profile": fb_profile,
        "child_formset": formset,
        "signup": signup,
        "message": request.session.pop("message", None),
    })

    if signup:
        return render_to_response("account/signup_add_children.html",
                                  RequestContext(request, ctx))
    else:
        return render_to_response("account/add_children.html",
                                  RequestContext(request, ctx))
예제 #7
0
파일: models.py 프로젝트: braskin/pd
def post_to_own_facebook(access_token, message_type, ctx, **kwargs):

    context = Context(ctx)

    from account.graphapi import GraphAPI

    api = GraphAPI(access_token)

    body_tmpl = Template(get_message_content("facebook", message_type, "body"))
    api.put_object("me", "feed", message=body_tmpl.render(context), **kwargs)
    return True
예제 #8
0
def post_to_own_facebook(access_token, message_type, ctx, **kwargs):

    context = Context(ctx)

    from account.graphapi import GraphAPI

    api = GraphAPI(access_token)

    body_tmpl = Template(get_message_content('facebook', message_type, 'body'))
    api.put_object("me", "feed", message=body_tmpl.render(context), **kwargs)
    return True
예제 #9
0
파일: views.py 프로젝트: braskin/pd
def run_fb_import(request):
    profile = request.user.get_profile()
    fb_user = profile.get_facebook_user()
    if fb_user is None:
        raise Exception('no fb user')
    
    from account.graphapi import GraphAPI

    fql= "SELECT uid, name, first_name, last_name, pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())"
    fb_api = GraphAPI(fb_user.access_token)
    friends = fb_api.fql(fql)

    app_user_friends = profile.run_getAppUsers_query()
    from profiles.models import FacebookUser
    friend_fb_users=FacebookUser.objects.filter(facebook_id__in=app_user_friends)
    fb_user_dict = {}
    for fuser in friend_fb_users:
        fb_user_dict[int(fuser.facebook_id)]=fuser.user

    from friends.models import ContactFB
    cn = 0    

    for f in friends:
        name = f["name"]
        id = f["uid"]
        fname = f["first_name"]
        lname = f["last_name"]

        if id in fb_user_dict:
            user = fb_user_dict[id]
        else:
            user = None

        try:
            obj = ContactFB.objects.get(owner=request.user, facebook_id = id)
            if obj.first_name != fname or obj.last_name != lname or obj.name != name:
                obj.first_name = fname
                obj.last_name = lname
                obj.name = name
                obj.save()
        except ContactFB.DoesNotExist:
            obj = ContactFB(
                owner = request.user,
                facebook_id = id,
                name = name,
                first_name=fname,
                last_name=lname,
                user = user
            ).save()
            cn = cn + 1

    return cn
예제 #10
0
파일: views.py 프로젝트: bopopescu/pd
def run_fb_import(request):
    profile = request.user.get_profile()
    fb_user = profile.get_facebook_user()
    if fb_user is None:
        raise Exception('no fb user')

    from account.graphapi import GraphAPI

    fql = "SELECT uid, name, first_name, last_name, pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())"
    fb_api = GraphAPI(fb_user.access_token)
    friends = fb_api.fql(fql)

    app_user_friends = profile.run_getAppUsers_query()
    from profiles.models import FacebookUser
    friend_fb_users = FacebookUser.objects.filter(
        facebook_id__in=app_user_friends)
    fb_user_dict = {}
    for fuser in friend_fb_users:
        fb_user_dict[int(fuser.facebook_id)] = fuser.user

    from friends.models import ContactFB
    cn = 0

    for f in friends:
        name = f["name"]
        id = f["uid"]
        fname = f["first_name"]
        lname = f["last_name"]

        if id in fb_user_dict:
            user = fb_user_dict[id]
        else:
            user = None

        try:
            obj = ContactFB.objects.get(owner=request.user, facebook_id=id)
            if obj.first_name != fname or obj.last_name != lname or obj.name != name:
                obj.first_name = fname
                obj.last_name = lname
                obj.name = name
                obj.save()
        except ContactFB.DoesNotExist:
            obj = ContactFB(owner=request.user,
                            facebook_id=id,
                            name=name,
                            first_name=fname,
                            last_name=lname,
                            user=user).save()
            cn = cn + 1

    return cn
예제 #11
0
def process_fb_auth(request):

    token = uid = fb_exists = name = None

    if request.session.has_key("fb_user"):
        if request.session["fb_user"].has_key("access_token"):
            token = str(request.session["fb_user"]["access_token"])
            uid = str(request.session["fb_user"]["uid"])

    if request.GET.has_key("session"):
        fb_user = simplejson.loads(request.GET["session"])
        request.session["fb_user"] = fb_user
        token = str(request.session["fb_user"]["access_token"])
        uid = str(request.session["fb_user"]["uid"])


#        name = str(request.session["fb_user"]["name"])

    fb_id_taken = None
    try:
        fb_id_taken = FacebookUser.objects.get(facebook_id=uid)
    except FacebookUser.DoesNotExist:
        pass

    if fb_id_taken is not None:
        if fb_id_taken.user == request.user:
            fb_exists = fb_id_taken
        else:
            raise FBID_Taken('Facebook ID already assigned')

    try:
        if fb_exists is None:
            fb_exists = FacebookUser.objects.get(user=request.user)
        if (token is not None) and (fb_exists.access_token != token):
            fb_exists.access_token = token
            fb_exists.facebook_id = uid
            fb_exists.save()

        return fb_exists
    except FacebookUser.DoesNotExist:
        fb_exists = False

    if (not fb_exists):
        from account.graphapi import GraphAPI
        fb_api = GraphAPI(token)
        prof = fb_api.get_object("me")

        fb_name = prof["name"]
        fb_user = create_fbuser(request.user, uid, token, name=fb_name)
        return fb_user
예제 #12
0
파일: views.py 프로젝트: braskin/pd
def process_fb_auth(request):

    token = uid = fb_exists = name = None

    if request.session.has_key("fb_user"):
        if request.session["fb_user"].has_key("access_token"):
            token = str(request.session["fb_user"]["access_token"])
            uid = str(request.session["fb_user"]["uid"])

    if request.GET.has_key("session"):
        fb_user = simplejson.loads(request.GET["session"])
        request.session["fb_user"] = fb_user
        token = str(request.session["fb_user"]["access_token"])
        uid = str(request.session["fb_user"]["uid"])

    #        name = str(request.session["fb_user"]["name"])

    fb_id_taken = None
    try:
        fb_id_taken = FacebookUser.objects.get(facebook_id=uid)
    except FacebookUser.DoesNotExist:
        pass

    if fb_id_taken is not None:
        if fb_id_taken.user == request.user:
            fb_exists = fb_id_taken
        else:
            raise FBID_Taken("Facebook ID already assigned")

    try:
        if fb_exists is None:
            fb_exists = FacebookUser.objects.get(user=request.user)
        if (token is not None) and (fb_exists.access_token != token):
            fb_exists.access_token = token
            fb_exists.facebook_id = uid
            fb_exists.save()

        return fb_exists
    except FacebookUser.DoesNotExist:
        fb_exists = False

    if not fb_exists:
        from account.graphapi import GraphAPI

        fb_api = GraphAPI(token)
        prof = fb_api.get_object("me")

        fb_name = prof["name"]
        fb_user = create_fbuser(request.user, uid, token, name=fb_name)
        return fb_user
예제 #13
0
파일: models.py 프로젝트: braskin/pd
    def run_getAppUsers_query(self):
        from account.graphapi import GraphAPI
        fb_user = self.get_facebook_user()

        fb_api = GraphAPI(fb_user.access_token)
        fql="SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=%s) AND is_app_user" % fb_user.facebook_id
        query_result = fb_api.fql(fql)
 
        friend_fbids = []
        
        for friend in query_result:
            friend_fbids.append(str(friend[u"uid"]))
           
        return friend_fbids
예제 #14
0
파일: models.py 프로젝트: bopopescu/pd
    def run_getAppUsers_query(self):
        from account.graphapi import GraphAPI
        fb_user = self.get_facebook_user()

        fb_api = GraphAPI(fb_user.access_token)
        fql = "SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=%s) AND is_app_user" % fb_user.facebook_id
        query_result = fb_api.fql(fql)

        friend_fbids = []

        for friend in query_result:
            friend_fbids.append(str(friend[u"uid"]))

        return friend_fbids
예제 #15
0
파일: pull_fb.py 프로젝트: braskin/pd
from mydebug import *
import urllib, simplejson


from profiles.models import *
from friends.models import *
from account.graphapi import GraphAPI

queued = FacebookUser.objects.filter(queue_for_pull=1)


for q in queued:
    quser = q.user
    print quser.get_profile().first_name
    fql= "SELECT uid, name, first_name, last_name, pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())"
    fb_api = GraphAPI(q.access_token)
    friends = fb_api.fql(fql)

    app_user_friends = quser.get_profile().run_getAppUsers_query()
    friend_fb_users=FacebookUser.objects.filter(facebook_id__in=app_user_friends)
    fb_user_dict = {}
    for fuser in friend_fb_users:
        fb_user_dict[fuser.facebook_id]=fuser.user
        

    cn = 0
    for f in friends:
        name = f["name"]
        id = f["uid"]
        fname = f["first_name"]
        lname = f["last_name"]
예제 #16
0
파일: pull_fb.py 프로젝트: bopopescu/pd
from django.contrib.auth.models import User
from django.db import connection
from mydebug import *
import urllib, simplejson

from profiles.models import *
from friends.models import *
from account.graphapi import GraphAPI

queued = FacebookUser.objects.filter(queue_for_pull=1)

for q in queued:
    quser = q.user
    print quser.get_profile().first_name
    fql = "SELECT uid, name, first_name, last_name, pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())"
    fb_api = GraphAPI(q.access_token)
    friends = fb_api.fql(fql)

    app_user_friends = quser.get_profile().run_getAppUsers_query()
    friend_fb_users = FacebookUser.objects.filter(
        facebook_id__in=app_user_friends)
    fb_user_dict = {}
    for fuser in friend_fb_users:
        fb_user_dict[fuser.facebook_id] = fuser.user

    cn = 0
    for f in friends:
        name = f["name"]
        id = f["uid"]
        fname = f["first_name"]
        lname = f["last_name"]
예제 #17
0
파일: models.py 프로젝트: braskin/pd
 def get_fb_contacts(self):
     from account.graphapi import GraphAPI
     fb_api = GraphAPI(self.access_token)
     res = fb_api.get_connections("me", "friends")
     friends = res["data"]
     return friends
예제 #18
0
파일: models.py 프로젝트: bopopescu/pd
 def get_fb_contacts(self):
     from account.graphapi import GraphAPI
     fb_api = GraphAPI(self.access_token)
     res = fb_api.get_connections("me", "friends")
     friends = res["data"]
     return friends