|
17 | 17 | from werkzeug.utils import redirect |
18 | 18 | import threading |
19 | 19 | import subprocess |
| 20 | +from werkzeug import exceptions |
| 21 | +from flask_wtf.file import FileRequired |
20 | 22 |
|
21 | 23 |
|
22 | 24 | generate_status = { |
@@ -44,10 +46,64 @@ def list_videos(): |
44 | 46 | ) |
45 | 47 |
|
46 | 48 |
|
| 49 | +@thegateway_blueprint.route("/thegateway/videos/<movie_id>/edit", methods=["GET", "POST"]) |
| 50 | +@oidc.require_login |
| 51 | +def edit_video(movie_id): |
| 52 | + form = VideoForm() |
| 53 | + form.upload.label.text = "Edit Video" |
| 54 | + |
| 55 | + movie = Videos.query.filter_by(id=movie_id).first() |
| 56 | + if not movie: |
| 57 | + return exceptions.NotFound() |
| 58 | + |
| 59 | + if form.validate_on_submit(): |
| 60 | + thumbnail_data = None |
| 61 | + video_data = None |
| 62 | + if form.video.data: |
| 63 | + video_data = form.video.data.read() |
| 64 | + if validate_mobiclip(video_data): |
| 65 | + length = get_mobiclip_length(video_data) |
| 66 | + movie.length = length |
| 67 | + else: |
| 68 | + flash("Invalid movie") |
| 69 | + return render_template("video_action.html", form=form, action="Edit") |
| 70 | + |
| 71 | + if form.thumbnail.data: |
| 72 | + thumbnail_data = form.thumbnail.data.read() |
| 73 | + |
| 74 | + save_video_data(movie.id, thumbnail_data, video_data) |
| 75 | + |
| 76 | + movie.name_japanese = form.title_jpn.data |
| 77 | + movie.name_english = form.title_en.data |
| 78 | + movie.name_german = form.title_de.data |
| 79 | + movie.name_french = form.title_fr.data |
| 80 | + movie.name_spanish = form.title_es.data |
| 81 | + movie.name_italian = form.title_it.data |
| 82 | + movie.name_dutch = form.title_dutch.data |
| 83 | + movie.video_type = form.video_type.data |
| 84 | + db.session.commit() |
| 85 | + |
| 86 | + return redirect(url_for("thegateway.list_videos")) |
| 87 | + else: |
| 88 | + form.title_jpn.data = movie.name_japanese |
| 89 | + form.title_en.data = movie.name_english |
| 90 | + form.title_de.data = movie.name_german |
| 91 | + form.title_fr.data = movie.name_french |
| 92 | + form.title_es.data = movie.name_spanish |
| 93 | + form.title_it.data = movie.name_italian |
| 94 | + form.title_dutch.data = movie.name_dutch |
| 95 | + form.video_type.data = movie.video_type |
| 96 | + |
| 97 | + return render_template("video_action.html", form=form, action="Edit") |
| 98 | + |
| 99 | + |
47 | 100 | @thegateway_blueprint.route("/thegateway/videos/add", methods=["GET", "POST"]) |
48 | 101 | @oidc.require_login |
49 | 102 | def add_video(): |
50 | 103 | form = VideoForm() |
| 104 | + form.video_type.validators = [FileRequired()] |
| 105 | + form.thumbnail.validators = [FileRequired()] |
| 106 | + |
51 | 107 | if form.validate_on_submit(): |
52 | 108 | video = form.video.data |
53 | 109 | thumbnail = form.thumbnail.data |
@@ -82,7 +138,7 @@ def add_video(): |
82 | 138 | else: |
83 | 139 | flash("Error uploading video!") |
84 | 140 |
|
85 | | - return render_template("video_add.html", form=form) |
| 141 | + return render_template("video_action.html", form=form, action="Add") |
86 | 142 |
|
87 | 143 |
|
88 | 144 | @thegateway_blueprint.route("/thegateway/movies/<movie_id>/thumbnail.jpg") |
|
0 commit comments