コード例 #1
0
ファイル: views.py プロジェクト: GeoRemindMe/GeoRemindMe_Web
def get_friends_facebook(request):
    """**Descripción**: Obtiene una lista con los contactos en gmail que
    el usuario puede seguir
    
    """
    if hasattr(request, 'facebook'):
        fb_client = request.facebook['client']
    else:
        from geoauth.clients.facebook import FacebookClient
        try:
            fb_client = FacebookClient(user=request.user)
        except:
            return None
    return fb_client.get_friends_to_follow()
コード例 #2
0
ファイル: views.py プロジェクト: shafiabdul/GeoRemindMe_Web
def get_friends_facebook(request):
    """**Descripción**: Obtiene una lista con los contactos en gmail que
    el usuario puede seguir
    
    """
    if hasattr(request, 'facebook'):
        fb_client = request.facebook['client']
    else:
        from geoauth.clients.facebook import FacebookClient
        try:
            fb_client = FacebookClient(user=request.user)
        except:
            return None
    return fb_client.get_friends_to_follow()
コード例 #3
0
def new_comment(sender, **kwargs):
    if hasattr(sender.instance, '_vis'):
        try:
            fb_client = FacebookClient(user=sender.user)
        except:
            return
        from os import environ
        params = {
            "name":
            sender.instance.name,
            "link":
            environ['HTTP_HOST'] + sender.instance.get_absolute_url(),
            "caption":
            "Sugerencia de " + sender.instance.user.username,
            "picture":
            environ['HTTP_HOST'] + "/user/" + sender.instance.user.username +
            "/picture/",
        }
        params = dict([k, v.encode('utf-8')] for k, v in params.items())
        if sender.instance._is_public():
            params["privacy"] = {'value': 'EVERYONE'}

        else:
            params["privacy"] = {'value': 'CUSTOM', 'friends': 'SELF'}
        post_id = fb_client.consumer.put_wall_post(sender.msg, params)
        from models import _FacebookPost
        fb_post = _FacebookPost(instance=str(sender.key()), post=post_id['id'])
        fb_post.put()
    else:
        return
コード例 #4
0
def new_suggestion(sender, **kwargs):
    try:
        fb_client = FacebookClient(user=sender.user)
    except:
        return
    params = {
        "name": "Ver detalles de la sugerencia",
        "link": __web_settings.WEB_APP + "suggestion/" + sender.slug,
        "caption": "Detalles del sitio (%(sitio)s), comentarios, etc." % {
            'sitio': sender.poi.name
        },
        #"caption": "Foto de %(sitio)s" % {'sitio':sender.poi.name},
        "picture": 'https://georemindme.appspot.com/user/georemindme/picture/',
    }
    if sender.description is not None:
        params["description"] = sender.description
    #Pasamos todos los valores a UTF-8
    params = dict([k, v.encode('utf-8')] for k, v in params.items())
    if sender._is_public():
        params["privacy"] = {'value': 'EVERYONE'}
    else:
        params["privacy"] = {'value': 'CUSTOM', 'friends': 'SELF'}
    try:
        if 'msg' in kwargs:
            post_id = fb_client.consumer.put_wall_post(kwargs['msg'], params)
        else:
            post_id = fb_client.consumer.put_wall_post(
                "%(sugerencia)s" % {'sugerencia': sender.name.encode('utf-8')},
                params)
        from models import _FacebookPost
        fb_post = _FacebookPost(instance=str(sender.key()), post=post_id['id'])
        fb_post.put()
    except:
        pass
コード例 #5
0
 def process_request(self, request):
     if 'signed_request' in request.REQUEST:
         data = parse_signed_request(request.REQUEST['signed_request'])
         if 'oauth_token' in data:
             request.facebook = {
                 'uid': data['user_id'],
                 'access_token': data['oauth_token'],
                 'client': FacebookClient(access_token=data['oauth_token'])
             }
     if not hasattr(request, 'facebook'):
         try:
             cookie = get_user_from_cookie(request.COOKIES)
             if cookie is not None:
                 request.facebook = {
                     'uid':
                     cookie['user_id'],
                     'access_token':
                     cookie['oauth_token'],
                     'client':
                     FacebookClient(access_token=cookie['oauth_token'])
                 }
         except:
             pass
     if not hasattr(request, 'facebook'):
         from facebookApp.watchers import disconnect_all
         disconnect_all()
     else:
         if request.user.is_authenticated():
             if request.facebook['client'].user is not None:
                 if request.facebook['client'].user.id != request.user.id:
                     # son usuarios distintos, cerramos la sesion del viejo usuario conectado
                     #request.session.delete()
                     from geouser.funcs import init_user_session
                     init_user_session(request,
                                       request.facebook['client'].user,
                                       remember=True,
                                       is_from_facebook=True)
                     from facebookApp.watchers import new_comment, new_vote, deleted_post
         else:
             if request.facebook['client'].user is not None:
                 # login desde facebook de un usuario conocido
                 from geouser.funcs import init_user_session
                 init_user_session(request,
                                   request.facebook['client'].user,
                                   remember=True,
                                   is_from_facebook=True)
                 from facebookApp.watchers import new_comment, new_vote, deleted_post
コード例 #6
0
def deleted_post(sender, **kwargs):
    from models import _FacebookPost
    fb_post = _FacebookPost.all().filter('instance =', str(sender.key())).get()
    if fb_post is not None:
        fb_client = FacebookClient(user=sender.user)
        try:
            fb_client.consumer.delete_object(fb_post.post)
            fb_post.delete()
        except:
            pass
コード例 #7
0
def new_list(sender, **kwargs):
    from geolist.models import ListSuggestion, ListRequested
    try:
        fb_client = FacebookClient(user=sender.user)
    except:
        return
    params = {
        "name": sender.name,
        "link": __web_settings.WEB_APP + sender.get_absolute_url(),
        "caption": _(u"Detalles de la lista, comentarios, etc."),
        #"caption": "Foto de %(sitio)s" % {'sitio':sender.poi.name},
        "picture": 'https://georemindme.appspot.com/user/georemindme/picture/',
    }
    if sender.description is not None:
        params[
            "description"] = "This is a longer description of the attachment"
    params = dict([k, v.encode('utf-8')] for k, v in params.items())
    if sender._is_public():
        params["privacy"] = {'value': 'EVERYONE'}
    else:
        params["privacy"] = {'value': 'CUSTOM', 'friends': 'SELF'}
    if isinstance(sender, ListSuggestion):
        if 'msg' in kwargs:
            post_id = fb_client.consumer.put_wall_post(kwargs['msg'], params)
        else:
            post_id = fb_client.consumer.put_wall_post(
                "He creado una lista de sugerencias ", params)
    elif isinstance(sender, ListRequested):
        if 'msg' in kwargs:
            post_id = fb_client.consumer.put_wall_post(kwargs['msg'], params)
        else:
            post_id = fb_client.consumer.put_wall_post(
                "Necesito sugerencias, ¿me podéis ayudar?", params)
    else:
        return
    from models import _FacebookPost
    fb_post = _FacebookPost(instance=str(sender.key()), post=post_id['id'])
    fb_post.put()
コード例 #8
0
def new_vote(sender, **kwargs):
    from geovote.models import Comment
    from geoalert.models import Suggestion
    from os import environ
    if hasattr(sender.instance, '_vis'):
        try:
            fb_client = FacebookClient(user=sender.user)
        except:
            return
        if isinstance(sender.instance, Comment):
            params = {
                "link":
                environ['HTTP_HOST'] +
                sender.instance.instance.get_absolute_url(),
                "caption":
                sender.instance.user.username,
                #"picture": "http://georemindme.com/media/img/whatsup.png"
                "picture":
                environ['HTTP_HOST'] + "/user/" +
                sender.instance.instance.user.username + "/picture",
            }
            if isinstance(sender.instance.instance, Suggestion):
                params["name"] = sender.instance.instance.name
                message = "Me gusta el comentario: \"%(comentario)s\" de %(autor)s en la sugerencia:" % {
                    'comentario': sender.instance.msg,
                    'autor': sender.instance.user.username
                }
            else:
                params[
                    "name"] = "Ver lista de sugerencias: " + sender.instance.instance.name
                message = "Me gusta el comentario: \"%(comentario)s\" de %(autor)s" % {
                    'comentario': sender.instance.msg,
                    'autor': sender.instance.user.username
                }

        elif isinstance(sender.instance, Suggestion):
            message = "Me gusta la sugerencia de %(autor)s:" % {
                'autor': sender.instance.user.username
            }
            params = {
                "name":
                sender.instance.name,
                "link":
                environ['HTTP_HOST'] + sender.instance.get_absolute_url(),
                "caption":
                sender.instance.user.username,
                #"picture": "http://georemindme.com/media/img/whatsup.png"
                "picture":
                environ['HTTP_HOST'] + "/user/" +
                sender.instance.user.username + "/picture",
            }
        if hasattr(sender.instance, "description"):
            params['description'] = sender.instance.description
        # codificamos todo el diccionario de parametros, antes de añadir el parametro privacy
        params = dict([k, v.encode('utf-8')] for k, v in params.items())
        if sender.instance._is_public():
            params["privacy"] = {'value': 'EVERYONE'}
        else:
            params["privacy"] = {'value': 'CUSTOM', 'friends': 'SELF'}

        #~ raise Exception(params["picture"])
        post_id = fb_client.consumer.put_wall_post(message.encode('utf-8'),
                                                   params)
        from models import _FacebookPost
        fb_post = _FacebookPost(instance=str(sender.key()), post=post_id['id'])
        fb_post.put()
    else:
        return