Exemplo n.º 1
0
def create_delete_meeting_request():
    data = request.json
    meeting_spec_key = data['meeting_spec_key']
    meeting_request_key = data['meeting_request_key']
    user = get_user(data['email'])

    if meeting_request_key == '':
        meeting_spec = MeetingSpec.query.filter(
            MeetingSpec.id == meeting_spec_key).first()
        if not meeting_spec:
            return 400
        meeting_request = query_meeting_request(meeting_spec, user)

        if not meeting_request:
            meeting_request = MeetingRequest(meeting_spec=meeting_spec,
                                             user=user)
            db.session.add(meeting_request)
            db.session.commit()

        return jsonify({'key': meeting_request.id})
    else:
        meeting_request = MeetingRequest.query.filter(
            MeetingRequest.id == meeting_request_key).one()
        db.session.delete(meeting_request)
        db.session.commit()
        return jsonify({'key': ''})
Exemplo n.º 2
0
def preferences_api():
    user = get_user(request.args.get('email'))
    if not user:
        return json.dumps([])

    subscriptions = merge_subscriptions_with_preferences(user)
    subscriptions = filter_subscriptions_by_user_data(subscriptions, user)

    return json.dumps(subscriptions)
Exemplo n.º 3
0
def get_meeting_request(meeting_spec_key):
    user = get_user(request.args.get('email'))
    meeting_spec = MeetingSpec.query.filter(
        MeetingSpec.id == int(meeting_spec_key)).first()
    meeting_request = query_meeting_request(meeting_spec, user)

    resp = jsonify({'key': meeting_request.id if meeting_request else ""})
    resp.status_code = 200
    return resp
Exemplo n.º 4
0
def get_meeting_request(meeting_spec_key):
    user = get_user(request.args.get('email'))
    meeting_spec = ndb.Key(urlsafe=meeting_spec_key)
    meeting_request = query_meeting_request(meeting_spec, user)

    resp = jsonify(
        {'key': meeting_request.key.urlsafe() if meeting_request else ""})
    resp.status_code = 200
    return resp
Exemplo n.º 5
0
def user_api():
    user = get_user(request.args.get('email'))
    if not user:
        return json.dumps({})

    return json.dumps({
        'first_name': user.first_name,
        'last_name': user.last_name,
        'photo_url': user.photo_url,
        'metadata': user.metadata
    })
Exemplo n.º 6
0
def preferences_api():
    user = get_user(request.args.get('email'))
    if not user:
        resp = jsonify([])
        resp.status_code = 200
        return resp

    subscriptions = merge_subscriptions_with_preferences(user)
    subscriptions = filter_subscriptions_by_user_data(subscriptions, user)

    resp = jsonify(subscriptions)
    resp.status_code = 200
    return resp
Exemplo n.º 7
0
Arquivo: user.py Projeto: twof/beans
def user_api():
    user = get_user(request.args.get('email'))

    if not user:
        resp = jsonify({})
        resp.status_code = 200
        return resp

    resp = jsonify({
        'first_name': user.first_name,
        'last_name': user.last_name,
        'photo_url': user.photo_url,
        'metadata': user.meta_data
    })
    resp.status_code = 200
    return resp
Exemplo n.º 8
0
def preferences_api_post(subscription):
    data = request.json
    user = get_user()
    if not user:
        return '400'

    subscription_key = ndb.Key(urlsafe=subscription)
    form_selection = {}
    for key, value in data.items():
        form_selection[ndb.Key(urlsafe=key)] = value

    removed = remove_preferences(user, form_selection, subscription_key)
    logging.info('Removed')
    logging.info(removed)

    added = add_preferences(user, form_selection, subscription_key)
    logging.info('Added')
    logging.info(added)

    return 'OK'
Exemplo n.º 9
0
def preferences_api_post(subscription_id: int) -> str:
    data = request.json
    user = get_user(data.get('email'))
    del data['email']
    if not user:
        return '400'

    form_selection = {}
    for key, value in data.items():
        # Convert key (a table id) to an int
        form_selection[int(key)] = value

    removed = remove_preferences(user, form_selection, subscription_id)
    logging.info('Removed')
    logging.info(removed)

    added = add_preferences(user, form_selection, subscription_id)
    logging.info('Added')
    logging.info(added)

    return 'OK'
Exemplo n.º 10
0
def create_delete_meeting_request():
    user = get_user()
    data = request.json
    meeting_spec_key = data['meeting_spec_key']
    meeting_request_key = data['meeting_request_key']

    if meeting_request_key == '':
        meeting_spec = ndb.Key(urlsafe=meeting_spec_key)
        if not meeting_spec:
            return 400
        meeting_request = query_meeting_request(meeting_spec, user)

        if not meeting_request:
            meeting_request = MeetingRequest(meeting_spec=meeting_spec, user=user.key)
            meeting_request.put()

        return json.dumps({'key': meeting_request.key.urlsafe()})
    else:
        meeting_request = ndb.Key(urlsafe=meeting_request_key)
        meeting_request.delete()
        return json.dumps({'key': ''})
Exemplo n.º 11
0
def get_meeting_request(meeting_spec_key):
    user = get_user()
    meeting_spec = ndb.Key(urlsafe=meeting_spec_key)
    meeting_request = query_meeting_request(meeting_spec, user)

    return json.dumps({'key': meeting_request.key.urlsafe() if meeting_request else ""})