Example #1
0
def addMusicItem():
    
    user = getUser()
    composer_id = request.form['composer_id']
    musicItemData = json.loads(request.form['music_item'])
    
    composer = Composer.query.filter_by(id=composer_id, user_id=user.id).first()
    
    if not composer:
        response = jsonify(message="Couldn't find composer")
        response.status_code = 401
        return response
    
    musicItem = createMusicItem(user_id=user.id, name=musicItemData['name'], number=musicItemData['number'], key=musicItemData['key'], dateOfComposition=musicItemData['dateOfComposition'], dateAdded=musicItemData['dateAdded'], composer=composer)
  
    if 'file' in request.files:
        uploadFile = request.files['file']
        print "uploading a file"
        try:
            filepath = uploadFileToServer(uploadFile, musicItem)
            createMusicFile(musicItem, filepath)
            response = jsonify(message="Added music item %s"%musicItem.name)
            response.status_code = 200
        except Exception, e:
            response = jsonify(message="Failed to upload file %s"% str(e))
            response.status_code = 500
Example #2
0
def addComposer():
    user = getUser()
    composer = Composer(user_id=user.id, name=request.json['name'], dateOfBirth=request.json['dateOfBirth'], dateOfDeath=request.json['dateOfDeath'])
    db.session.add(composer)
    db.session.commit()
   
    response = jsonify(message="Added composer %s"%composer.name)
    response.status_code = 200
    return response
Example #3
0
def composerMusicItemsJSON(composer_id):
    user = getUser()
    composer = Composer.query.filter_by(id=composer_id, user_id=user.id).first()
    return jsonify(musicItems=[i.to_json() for i in composer.musicItems])
Example #4
0
def allComposersJSON():
    user = getUser()
    composers = Composer.query.filter_by(user_id=user.id).order_by(Composer.name).all()
    return jsonify(composers=[c.to_json() for c in composers])