Exemplo n.º 1
0
def music_add():
    form = MusicForm()
    set_music_choices(form)
    if form.validate_on_submit():
        music = Music()
        set_music_attribs(form, music, True)
        cover_fs = request.files.get(form.music_cover.name)
        audio_fs = request.files.get(form.music_audio.name)
        lrc_fs = request.files.get(form.music_lrc.name)
        subfolder = 'musics' + '/' + music.uuid
        music.coverfile = musicCoversSet.save(cover_fs,
                                              folder=subfolder,
                                              name=cover_fs.filename)
        music.audiofile = musicAudiosSet.save(audio_fs,
                                              folder=subfolder,
                                              name=audio_fs.filename)
        music.lrcfile = musicLrcsSet.save(lrc_fs,
                                          folder=subfolder,
                                          name=lrc_fs.filename)
        db.session.add(music)
        # 记录操作日志
        operateLog = AdminOperatelog(admin_id=session.get("admin_id"),
                                     ip=request.remote_addr,
                                     operations='添加一条音乐')
        db.session.add(operateLog)
        db.session.commit()
        flash(message='音乐添加成功!', category='ok')
        return redirect(url_for('admin.music_list', page=1))
    return render_template('admin/music_add.html', form=form)
Exemplo n.º 2
0
def movie_change(id):
    form = MovieForm()
    movietags = MovieTag.query.all()
    form.movie_tag.choices = [(item.id, item.name) for item in movietags]
    form.movie_cover.validators = [form.movie_cover.validators[1]]
    form.movie_video.validators = [form.movie_video.validators[1]]
    movie = Movie.query.get_or_404(id)
    if request.method == "GET":
        form.movie_title.data = movie.title
        form.movie_privacy.data = movie.privacy
        form.movie_recmmed.data = movie.recommed
        form.movie_tag.data = movie.tag_id
        form.movie_length.data = movie.length
        form.movie_star.data = movie.starlevel
        form.movie_area.data = movie.area
    if form.validate_on_submit():
        set_movie_attrs(form, movie, False)
        subfolder = 'movies' + '/' + movie.uuid
        cover_fs = form.movie_cover.data
        if cover_fs:
            cover_path = movieCoversSet.path(filename=movie.cover)
            if os.path.isfile(cover_path):
                os.remove(cover_path)
            movie.cover = musicCoversSet.save(cover_fs, folder=subfolder, name=cover_fs.filename)
        video_fs = form.movie_video.data
        if video_fs:
            video_path = movieVideosSet.path(filename=movie.videofile)
            if os.path.isfile(video_path):
                os.remove(video_path)
            movie.videofile = movieVideosSet.save(video_fs, folder=subfolder, name=video_fs.filename)
        db.session.add(movie)
        db.session.commit()
        flash(message='电影修改成功!', category='ok')
        return redirect(url_for('admin.movie_list', page=1))
    return render_template('admin/movie_change.html', movie=movie, form=form)
Exemplo n.º 3
0
def music_change(id):
    form = MusicForm()
    set_music_choices(form)
    form.music_cover.validators = [form.music_cover.validators[1]]
    form.music_audio.validators = [form.music_audio.validators[1]]
    form.music_lrc.validators = [form.music_lrc.validators[1]]
    music = Music.query.get_or_404(id)
    if request.method == "GET":
        form.music_title.data = music.title
        form.music_singer.data = music.singer
        form.music_singer.data = music.singer
        form.music_privacy.data = music.privacy
        form.music_recmmed.data = music.recommed
        form.music_lang.data = music.lang_id
        form.music_style.data = music.style_id
        form.music_theme.data = music.theme_id
        form.music_emotion.data = music.emotion_id
        form.music_scene.data = music.scene_id
    if form.validate_on_submit():
        set_music_attribs(form, music, False)
        subfolder = 'musics' + '/' + music.uuid
        cover_fs = form.music_cover.data
        if cover_fs:
            cover_path = musicCoversSet.path(filename=music.coverfile)
            if os.path.isfile(cover_path):
                os.remove(cover_path)
            music.coverfile = musicCoversSet.save(cover_fs,
                                                  folder=subfolder,
                                                  name=cover_fs.filename)
        audio_fs = form.music_audio.data
        if audio_fs:
            audio_path = musicAudiosSet.path(filename=music.audiofile)
            if os.path.isfile(audio_path):
                os.remove(audio_path)
            music.audiofile = musicAudiosSet.save(audio_fs,
                                                  folder=subfolder,
                                                  name=audio_fs.filename)
        lrc_fs = form.music_lrc.data
        if lrc_fs:
            lrc_path = musicLrcsSet.path(filename=music.lrcfile)
            if os.path.isfile(lrc_path):
                os.remove(lrc_path)
            music.lrcfile = musicLrcsSet.save(lrc_fs,
                                              folder=subfolder,
                                              name=lrc_fs.filename)
        db.session.add(music)
        db.session.commit()
        flash(message='音乐修改成功!', category='ok')
        return redirect(url_for('admin.music_list', page=1))
    return render_template('admin/music_change.html', music=music, form=form)