Exemplo n.º 1
0
 def get_featured(self):
     if self.ft_type == "Artist":
         artist = Artist()
         artist.load(self.ft_id)
         return artist
     elif self.ft_type == "Band":
         band = Band()
         band.load(self.ft_id)
         return band
     else:
         return "No"
Exemplo n.º 2
0
 def get_artist(self):
     if self.artist_type == "Artist":
         artist = Artist()
         artist.load(self.artist_id)
         return artist
     elif self.artist_type == "Band":
         band = Band()
         band.load(self.artist_id)
         return band
     else:
         return "unknown"
Exemplo n.º 3
0
def upload_api_handler():
    usr = auth()

    data = parse_req_body(['name', 'author', 'mtype', 'introduction', 'genre'])
    try:
        f = request.files['music_file']
    except:
        return fail(u'发布失败,请选择要上传的文件')

    music = Music()
    music.name = data['name']
    if not music.name: return fail(u'请填写音乐名称')
    music.author = data['author']
    music.type = data['mtype']
    music.username = usr.username
    music.introduction = data['introduction']

    music.file_path = './attachments/' + secure_filename(gen_random_string() +
                                                         f.filename[-70:])
    try:
        f.save(music.file_path)
    except:
        return fail(u'保存音乐文件失败,请重试')

    if data['author']:
        artist = Artist(data['author'])
        artist.load()
        artist.genre = data['genre']
    else:
        artist = Artist('')
        artist.load()
        artist.genre = ''

    artist.save()
    music.save()
    return succAndRedirect(u'成功发布', '/view/' + str(music.id))