def create_startup():
    user_id = getUserID('me')
    try:
        new_startup = startup.create_startup(user_id, request.get_json())
        return jsonify(startup.get_basic_startup(new_startup, getUserID('me')))
    except Exception as e:
        return jsonify({'error': str(e)}), HTTP_400_BAD_REQUEST
def create_startup():
    user_id = getUserID('me')
    try:
        new_startup = startup.create_startup(user_id, request.get_json())
        return jsonify(startup.get_basic_startup(new_startup, getUserID('me')))
    except Exception as e:
        return jsonify({'error': str(e)}), HTTP_400_BAD_REQUEST
def endorse_entity(entity_id, entity_type):
    entity_id = getUserID(entity_id)
    user_id = getUserID('me')

    if entity_id == user_id:
        raise Exception('Cannot endorse self')

    entity_endorsements = get_or_create(entity_id, entity_type)
    user_endorsements = get_or_create(user_id, 'user')

    add_or_pass(entity_endorsements['endorsers'], {'_id': user_id, 'entityType': 'user'})
    add_or_pass(user_endorsements['endorsees'], {'_id': entity_id, 'entityType': entity_type})

    entity_endorsements.save()
    user_endorsements.save()
    return user_endorsements['endorsees']
def get_invites():
    '''
    Gets all the invites for the currently logged on user
    '''
    user_id = user.getUserID('me')
    entries = invite.find_multiple_invites({'producerObjectId': user_id})
    invite_attributes_list = [invite.get_invite_attributes(entry) for entry in entries]
    return jsonify(error=None, invites=invite_attributes_list)
Example #5
0
def get_basic_startup(startup_object, current_user_id=None):
    fields = list(Startup.basic_info_fields)
    current_user_id = current_user_id if current_user_id else user.getUserID('me')
    owner = {'isOwner': is_owner(current_user_id, startup_object)}
    output = utils.jsonFields(startup_object, fields, response=False, extra=owner)
    #append the string names for the markets to the basic info
    output['markets'] = [str(market['name']) for market in get_markets_from_id(startup_object['markets'])]
    return output
Example #6
0
def delete_image(imageid):
    entry = find_image_by_id(imageid)
    if entry is None:
        return '', HTTP_404_NOT_FOUND

    if str(entry['owner']) != str(getUserID('me')):  # TODO: Add admin override
        return '', HTTP_401_UNAUTHORIZED

    entry.delete()
    return '', HTTP_200_OK
def get_basic_startup(startup_id):
    startup_object = startup.find_startup_by_id(startup_id)

    if startup_object is None:
        return jsonify({'error': 'Not found'}), HTTP_404_NOT_FOUND

    try:
        return jsonify(startup.get_basic_startup(startup_object, getUserID('me')))
    except Exception as e:
        return jsonify({'error': str(e)}), HTTP_400_BAD_REQUEST
def not_owned(startup_object):
    user_id = getUserID('me')

    if startup_object is None:
        return jsonify({'error': 'Not found'}), HTTP_404_NOT_FOUND

    if not startup.is_owner(user_id, startup_object):
        return '{}', HTTP_401_NOT_AUTHORIZED

    return None
def not_owned(startup_object):
    user_id = getUserID('me')

    if startup_object is None:
        return jsonify({'error': 'Not found'}), HTTP_404_NOT_FOUND

    if not startup.is_owner(user_id, startup_object):
        return '{}', HTTP_401_NOT_AUTHORIZED

    return None
Example #10
0
def get_invites():
    '''
    Gets all the invites for the currently logged on user
    '''
    user_id = user.getUserID('me')
    entries = invite.find_multiple_invites({'producerObjectId': user_id})
    invite_attributes_list = [
        invite.get_invite_attributes(entry) for entry in entries
    ]
    return jsonify(error=None, invites=invite_attributes_list)
def delete_image(imageid):
    entry = find_image_by_id(imageid)
    if entry is None:
        return '', HTTP_404_NOT_FOUND

    if str(entry['owner']) != str(getUserID('me')):  # TODO: Add admin override
        return '', HTTP_401_UNAUTHORIZED

    entry.delete()
    return '', HTTP_200_OK
def get_or_create(entity_id, entity_type):
    entity_id = getUserID(entity_id) if entity_id == 'me' else entity_id
    entity_endorsements = coll.Endorsement.find_one({'_id': entity_id})
    if not entity_endorsements:
        if find_entity_by_type(entity_id, entity_type):
            entity_endorsements = coll.Endorsement()
            entity_endorsements['_id'] = entity_id
            entity_endorsements['entityType'] = entity_type
        else:
            raise Exception('%s does not exist' % entity_type)
    return entity_endorsements
def get_details(startup_id):
    startup_object = startup.find_startup_by_id(startup_id)
    user_id = getUserID('me')

    if startup_object is None:
        return jsonify({'error': 'Not found'}), HTTP_404_NOT_FOUND

    try:
        return jsonify(startup.get_details(startup_object, user_id))
    except Exception as e:
        return jsonify({'error': str(e)}), HTTP_400_BAD_REQUEST
def add_question(startup_id):
    startup_object = startup.find_startup_by_id(startup_id)
    user_id = getUserID('me')

    if startup_object is None:
        return jsonify({'error': 'Not found'}), HTTP_404_NOT_FOUND

    try:
        startup.add_question(startup_object, request.get_json(), user_id)
        return '{}'
    except Exception as e:
        return jsonify({'error': str(e)}), HTTP_400_BAD_REQUEST
def upload_image():
    request_error = ''
    user_id = getUserID('me')
    file = request.files['file']
    if file and allowed_file(file.filename):
        try:
            image_blob = crop_image(Image(file=file)).make_blob()
            image_id = create_image(image_blob, user_id)
            return jsonify(error=None, imageID=str(image_id) + '.' + PROFILE_FORMAT)
        except Exception as e:
            request_error = str(e)
    return jsonify(error=request_error), HTTP_400_BAD_REQUEST
def post_wall(startup_id):
    startup_object = startup.find_startup_by_id(startup_id)

    user_id = getUserID('me')
    no = not_owned(startup_object)
    if not no is None:
        return no

    try:
        return jsonify(startup.post_wall(startup_object, request.get_json(), user_id))
    except Exception as e:
        return jsonify({'error': str(e)}), HTTP_400_BAD_REQUEST
def add_question(startup_id):
    startup_object = startup.find_startup_by_id(startup_id)
    user_id = getUserID('me')

    if startup_object is None:
        return jsonify({'error': 'Not found'}), HTTP_404_NOT_FOUND

    try:
        startup.add_question(startup_object, request.get_json(), user_id)
        return '{}'
    except Exception as e:
        return jsonify({'error': str(e)}), HTTP_400_BAD_REQUEST
Example #18
0
def upload_image():
    request_error = ''
    user_id = getUserID('me')
    file = request.files['file']
    if file and allowed_file(file.filename):
        try:
            image_blob = crop_image(Image(file=file)).make_blob()
            image_id = create_image(image_blob, user_id)
            return jsonify(error=None,
                           imageID=str(image_id) + '.' + PROFILE_FORMAT)
        except Exception as e:
            request_error = str(e)
    return jsonify(error=request_error), HTTP_400_BAD_REQUEST
def post_wall(startup_id):
    startup_object = startup.find_startup_by_id(startup_id)

    user_id = getUserID('me')
    no = not_owned(startup_object)
    if not no is None:
        return no

    try:
        return jsonify(
            startup.post_wall(startup_object, request.get_json(), user_id))
    except Exception as e:
        return jsonify({'error': str(e)}), HTTP_400_BAD_REQUEST
def upload_image_from_uri():
    user_id = getUserID('me')
    file_location = request.get_json().get('uri')

    # Consider Tornado's async retrival here
    try:
        image_info = urllib2.urlopen(file_location)
    except:
        return jsonify(error='Bad URI'), HTTP_400_BAD_REQUEST

    try:
        image_blob = crop_image(Image(file=image_info)).make_blob()
        image_id = create_image(image_blob, user_id)
        return jsonify(error=None, imageID=str(image_id) + '.' + PROFILE_FORMAT)
    except Exception as e:
        return jsonify(error=str(e)), HTTP_400_BAD_REQUEST
Example #21
0
def upload_image_from_uri():
    user_id = getUserID('me')
    file_location = request.get_json().get('uri')

    # Consider Tornado's async retrival here
    try:
        image_info = urllib2.urlopen(file_location)
    except:
        return jsonify(error='Bad URI'), HTTP_400_BAD_REQUEST

    try:
        image_blob = crop_image(Image(file=image_info)).make_blob()
        image_id = create_image(image_blob, user_id)
        return jsonify(error=None,
                       imageID=str(image_id) + '.' + PROFILE_FORMAT)
    except Exception as e:
        return jsonify(error=str(e)), HTTP_400_BAD_REQUEST
Example #22
0
def create_invites():
    '''
    Create <number> of invites for a target user
    (or by default the currently logged in user).
    '''

    try:
        user_id = user.getUserID('me')
        if request.get_json().get('user'):
            user_id = ObjectId(request.get_json().get('user'))

        number = int(request.get_json()['number'])

        output_invites = []
        for i in range(number):
            output_invite = invite.create_invite(user_id)
            output_invites.append(invite.get_invite_attributes(output_invite))
        return jsonify(error=None, invites=output_invites)
    except Exception as e:
        return jsonify(error=str(e))
def create_invites():
    '''
    Create <number> of invites for a target user
    (or by default the currently logged in user).
    '''

    try:
        user_id = user.getUserID('me')
        if request.get_json().get('user'):
            user_id = ObjectId(request.get_json().get('user'))

        number = int(request.get_json()['number'])

        output_invites = []
        for i in range(number):
            output_invite = invite.create_invite(user_id)
            output_invites.append(invite.get_invite_attributes(output_invite))
        return jsonify(error=None, invites=output_invites)
    except Exception as e:
        return jsonify(error=str(e))
def find_endorsements_by_id(entity_id):
    entity_id = getUserID(entity_id) if entity_id == 'me' else entity_id
    return coll.Endorsement.find_one({'_id': ObjectId(entity_id)})