示例#1
0
def event(id):
    """Public event page."""
    event = Event.fetch_or_404(id)
    this_url = url_for('event', id=event.id)

    if event.facebook_id and current_user.is_authenticated():
        try:
            api = facebook.create_api()
            data = api.get(path='/' + event.facebook_id + '/invited')['data']

            for friend in data:
                contact = current_user.find_facebook_contact(friend['id'])
                if not contact:
                    with db.transaction as session:
                        contact = FacebookContact()
                        contact.user = current_user
                        contact.facebook_id = friend['id']
                        contact.name = friend['name']
                        session.add(contact)
                with db.transaction:
                    event.set_attendance(contact, Attendance.types_mapping[friend['rsvp_status']])

        except (facebook.ConnectionError, facebook.OAuthError):
            return redirect(facebook.create_authorize_url(
                action_url=this_url,
                error_url=this_url
            ))

    if event.google_id and current_user.is_authenticated():
        try:
            api = google.create_api(google.CalendarClient)
            entry = api.GetEventEntry(event.google_id)

            for participant in entry.who:
                contact = current_user.find_email_contact(participant.email)
                if not contact:
                    continue
                with db.transaction:
                    if not participant.attendee_status and participant.rel == 'http://schemas.google.com/g/2005#event.organizer':
                        event.set_attendance(contact, 'going')
                    else:
                        event.set_attendance(contact, Attendance.types_mapping[participant.attendee_status.value])

        except (google.ConnectionError, google.UnauthorizedError) as e:
            return redirect(google.create_authorize_url(
                action_url=this_url,
                error_url=this_url,
                scope='https://www.google.com/calendar/feeds/ https://www.google.com/m8/feeds/'
            ))

    return render_template('event.html', event=event)
示例#2
0
def import_facebook_friends():
    try:
        api = facebook.create_api()
        me = api.get('me')

        friends = api.get('me/friends')['data']
        friends.append(me)

        for friend in friends:
            with db.transaction as session:
                contact = current_user.find_facebook_contact(friend['id'])
                if not contact:
                    contact = FacebookContact()
                    contact.name = friend['name']
                    contact.facebook_id = friend['id']
                    contact.user = current_user
                    contact.belongs_to_user = friend['id'] == me['id']
                    session.add(contact)
                else:
                    contact.name = friend['name']

        return redirect(url_for('contacts'))

    except (facebook.ConnectionError, facebook.OAuthError):
        return redirect(
            facebook.create_authorize_url(
                action_url=url_for('import_facebook_friends'),
                error_url=url_for('contacts')))
示例#3
0
def import_facebook_friends():
    try:
        api = facebook.create_api()
        me = api.get('me')

        friends = api.get('me/friends')['data']
        friends.append(me)

        for friend in friends:
            with db.transaction as session:
                contact = current_user.find_facebook_contact(friend['id'])
                if not contact:
                    contact = FacebookContact()
                    contact.name = friend['name']
                    contact.facebook_id = friend['id']
                    contact.user = current_user
                    contact.belongs_to_user = friend['id'] == me['id']
                    session.add(contact)
                else:
                    contact.name = friend['name']

        return redirect(url_for('contacts'))

    except (facebook.ConnectionError, facebook.OAuthError):
        return redirect(facebook.create_authorize_url(
            action_url=url_for('import_facebook_friends'),
            error_url=url_for('contacts')
        ))