Beispiel #1
1
    def test_get_list(self):
        user_a = User(id='42', name='Foo Bar')
        user_b = User.get_or_insert('43', name='Knuth Donald')
        user_c = User.get_or_insert('44', name='Lovelace Ada')
        user_a.friends.append(user_b.key)
        user_a.friends.append(user_c.key)
        user_a.put()

        rv = self.app.get('/api/friends?profile_id=42')
        self.assertEqual(rv.status, '200 OK')

        data = json.loads(rv.data)
        self.assertEqual(data['count'], 2)
        self.assertItemsEqual({'Knuth Donald', 'Lovelace Ada'},
                              {f['name'] for f in data['friends']})
Beispiel #2
0
    def post(self):
        new_email = self.request.get('email')
        new_account_enabled = True if self.request.get(
            'accountEnabled') == 'on' else False
        new_report_enabled = True if self.request.get(
            'reportEnabled') == 'on' else False
        new_is_admin = True if self.request.get('isAdmin') == 'on' else False
        new_description = self.request.get('description')

        auth_id = 'google:%s' % new_email

        data_user = User.get_by_id(auth_id)
        if data_user:
            params = {}
            params.update(ndb_user=data_user, error_message='account exist')
            self.render('account/account_management_new.html', **params)
            return

        else:
            user = User.get_or_insert(auth_id)
            if user:
                user.email = new_email
                user.account_enabled = new_account_enabled
                user.report_enabled = new_report_enabled
                user.is_admin = new_is_admin
                user.description = new_description

                user.put()

        self.redirect('/account_management')
Beispiel #3
0
def update_friendlists(user):
    graph = facebook.GraphAPI(user.token)
    profile = graph.get_object("me")
    friends = graph.get_connections("me", "friends")
    for friend in friends["data"]:
        entry = User.get_or_insert(friend["id"].decode("utf-8"), name=friend["name"].decode("utf-8"))
        entry.friends.append(user.key)
        entry.put()
Beispiel #4
0
def update_friendlists(user):
    graph = facebook.GraphAPI(user.token)
    profile = graph.get_object("me")
    friends = graph.get_connections("me", "friends")
    for friend in friends['data']:
        entry = User.get_or_insert(friend['id'].decode('utf-8'),
                                   name=friend['name'].decode('utf-8'))
        entry.friends.append(user.key)
        entry.put()
Beispiel #5
0
def add_user(profile, friends):
    user = User(
        id=profile['id'].decode('utf-8'),
        name=profile['name'].decode('utf-8')
    )

    for friend in friends['data']:
        entry = User.get_or_insert(
            friend['id'].decode('utf-8'),
            name=friend['name'].decode('utf-8')
        )
        user.friends.append(entry.key)
    user.put()