def retry_facebook_invite(modeladmin, request, queryset):
    '''
    Retries sending the invite to the users wall
    '''
    invites = list(queryset)
    user_invites = defaultdict(list)
    for invite in invites:
        user_invites[invite.user].append(invite)

    for user, invites in user_invites.items():
        profile = get_profile(user)
        graph = profile.get_offline_graph()
        if not graph:
            error_message = 'couldnt connect to the graph, user access token is %s' % profile.access_token
            messages.error(request, error_message)
            continue
        logger.info('got graph %s for user %s, retrying %s invites',
                    graph, user, len(invites))
        for invite in invites:
            invite_result = invite.resend(graph)
            message = 'User %s sent attempt to sent with id %s s6 is %s' % (
                user, invite_result.wallpost_id, not invite_result.error)
            if invite_result.error:
                message += ' got error %s' % invite_result.error_message
            messages.info(request, message)

        profile.update_invite_denormalizations()
        profile.save()
Example #2
0
 def profile_or_self(self):
     user_or_profile_model = get_model_for_attribute('facebook_id')
     user_model = get_user_model()
     if user_or_profile_model == user_model:
         return self
     else:
         return get_profile(self)
Example #3
0
def facebook_profile(open_graph_share):
    '''
    Nicely displayed version of the facebook user
    with user id and image and link to facebook :)
    '''
    user = open_graph_share.user
    profile = get_profile(user)
    facebook_id = profile.facebook_id
    facebook_url = 'http://www.facebook.com/%s/' % facebook_id
    link = '<p><a href="%s"><img src="http://graph.facebook.com/%s/picture/?type=large" width="100px" style="float:left"/>%s</a><br/></p>' % (
        facebook_url, facebook_id, facebook_id)
    return link
Example #4
0
 def remove(self, graph=None):
     if not self.share_id:
         raise ValueError('Can only delete shares which have an id')
     # see if the graph is enabled
     profile = get_profile(self.user)
     graph = graph or profile.get_offline_graph()
     response = None
     if graph:
         response = graph.delete(self.share_id)
         self.removed_at = datetime.now()
         self.save()
     return response
Example #5
0
def facebook_profile(open_graph_share):
    '''
    Nicely displayed version of the facebook user
    with user id and image and link to facebook :)
    '''
    user = open_graph_share.user
    profile = get_profile(user)
    facebook_id = profile.facebook_id
    facebook_url = 'http://www.facebook.com/%s/' % facebook_id
    link = '<p><a href="%s"><img src="http://graph.facebook.com/%s/picture/?type=large" width="100px" style="float:left"/>%s</a><br/></p>' % (
        facebook_url, facebook_id, facebook_id)
    return link
Example #6
0
def disconnect(request):
    '''
    Removes Facebook from the users profile
    And redirects to the specified next page
    '''
    if request.method == 'POST':
        messages.info(
            request, _("You have disconnected your Facebook profile."))
        profile = get_profile(request.user)
        profile.disconnect_facebook()
        profile.save()
    response = next_redirect(request)
    return response
Example #7
0
def disconnect(request):
    '''
    Removes Facebook from the users profile
    And redirects to the specified next page
    '''
    if request.method == 'POST':
        messages.info(request,
                      _("You have disconnected your Facebook profile."))
        profile = get_profile(request.user)
        profile.disconnect_facebook()
        profile.save()
    response = next_redirect(request)
    return response
    def profile_authenticate(self, facebook_id=None, facebook_email=None):
        '''
        Authenticate the facebook user by id OR facebook_email
        We filter using an OR to allow existing members to connect with
        their facebook ID using email.

        :param facebook_id:
            Optional string representing the facebook id

        :param facebook_email:
            Optional string with the facebook email

        :return: The signed in :class:`User`.
        '''
        if facebook_id or facebook_email:
            profile_class = get_profile_model()
            profile_query = profile_class.objects.all().order_by('user')
            profile_query = profile_query.select_related('user')
            profile = None

            # filter on email or facebook id, two queries for better
            # queryplan with large data sets
            if facebook_id:
                profiles = profile_query.filter(facebook_id=facebook_id)[:1]
                profile = profiles[0] if profiles else None
            if profile is None and facebook_email:
                try:
                    profiles = profile_query.filter(
                        user__email__iexact=facebook_email)[:1]
                    profile = profiles[0] if profiles else None
                except DatabaseError:
                    try:
                        user = get_user_model(
                        ).objects.get(email=facebook_email)
                    except get_user_model().DoesNotExist:
                        user = None
                    profile = get_profile(user) if user else None

            if profile:
                # populate the profile cache while we're getting it anyway
                user = profile.user
                user._profile = profile
                if facebook_settings.FACEBOOK_FORCE_PROFILE_UPDATE_ON_LOGIN:
                    user.fb_update_required = True
                return user
    def profile_authenticate(self, facebook_id=None, facebook_email=None):
        '''
        Authenticate the facebook user by id OR facebook_email
        We filter using an OR to allow existing members to connect with
        their facebook ID using email.

        :param facebook_id:
            Optional string representing the facebook id

        :param facebook_email:
            Optional string with the facebook email

        :return: The signed in :class:`User`.
        '''
        if facebook_id or facebook_email:
            profile_class = get_profile_model()
            profile_query = profile_class.objects.all().order_by('user')
            profile_query = profile_query.select_related('user')
            profile = None

            # filter on email or facebook id, two queries for better
            # queryplan with large data sets
            if facebook_id:
                profiles = profile_query.filter(facebook_id=facebook_id)[:1]
                profile = profiles[0] if profiles else None
            if profile is None and facebook_email:
                try:
                    profiles = profile_query.filter(
                        user__email__iexact=facebook_email)[:1]
                    profile = profiles[0] if profiles else None
                except DatabaseError:
                    try:
                        user = get_user_model(
                        ).objects.get(email=facebook_email)
                    except get_user_model().DoesNotExist:
                        user = None
                    profile = get_profile(user) if user else None

            if profile:
                # populate the profile cache while we're getting it anyway
                user = profile.user
                user._profile = profile
                if facebook_settings.FACEBOOK_FORCE_PROFILE_UPDATE_ON_LOGIN:
                    user.fb_update_required = True
                return user
Example #10
0
    def update(self, data, graph=None):
        '''
        Update the share with the given data
        '''
        result = None
        profile = get_profile(self.user)
        graph = graph or profile.get_offline_graph()

        # update the share dict so a retry will do the right thing
        # just in case we fail the first time
        shared = self.update_share_dict(data)
        self.save()

        # broadcast the change to facebook
        if self.share_id:
            result = graph.set(self.share_id, **shared)

        return result
Example #11
0
    def update(self, data, graph=None):
        '''
        Update the share with the given data
        '''
        result = None
        profile = get_profile(self.user)
        graph = graph or profile.get_offline_graph()

        # update the share dict so a retry will do the right thing
        # just in case we fail the first time
        shared = self.update_share_dict(data)
        self.save()

        # broadcast the change to facebook
        if self.share_id:
            result = graph.set(self.share_id, **shared)

        return result
Example #12
0
 def check_django_facebook_user(self, request, facebook_id, access_token):
     try:
         current_user = get_profile(request.user)
     except:
         current_facebook_id = None
     else:
         current_facebook_id = current_user.facebook_id
     if not current_facebook_id or current_facebook_id != facebook_id:
         logout(request)
         # clear possible caches
         if hasattr(request, 'facebook'):
             del request.facebook
         if request.session.get('graph', None):
             del request.session['graph']
     else:
         # save last access_token to make sure we always have the most
         # recent one
         current_user.access_token = access_token
         current_user.save()
 def check_django_facebook_user(self, request, facebook_id, access_token):
     try:
         current_user = get_profile(request.user)
     except:
         current_facebook_id = None
     else:
         current_facebook_id = current_user.facebook_id
     if not current_facebook_id or current_facebook_id != facebook_id:
         logout(request)
         # clear possible caches
         if hasattr(request, 'facebook'):
             del request.facebook
         if request.session.get('graph', None):
             del request.session['graph']
     else:
         # save last access_token to make sure we always have the most
         # recent one
         current_user.access_token = access_token
         current_user.save()
Example #14
0
 def save(self, *args, **kwargs):
     if self.user and not self.facebook_user_id:
         profile = get_profile(self.user)
         self.facebook_user_id = get_user_attribute(
             self.user, profile, 'facebook_id')
     return BaseModel.save(self, *args, **kwargs)
Example #15
0
 def save(self, *args, **kwargs):
     if self.user and not self.facebook_user_id:
         profile = get_profile(self.user)
         self.facebook_user_id = get_user_attribute(
             self.user, profile, 'facebook_id')
     return BaseModel.save(self, *args, **kwargs)