upda
This commit is contained in:
27
app.py
27
app.py
@@ -150,12 +150,16 @@ def logout():
|
||||
@admin_required
|
||||
def upload_content():
|
||||
if request.method == 'POST':
|
||||
target_type = request.form['target_type']
|
||||
target_id = int(request.form['target_id'])
|
||||
target_type = request.form.get('target_type')
|
||||
target_id = request.form.get('target_id')
|
||||
files = request.files.getlist('files')
|
||||
duration = int(request.form['duration'])
|
||||
return_url = request.form['return_url']
|
||||
media_type = request.form['media_type']
|
||||
return_url = request.form.get('return_url')
|
||||
media_type = request.form.get('media_type')
|
||||
|
||||
if not target_type or not target_id:
|
||||
flash('Please select a target type and target ID.', 'danger')
|
||||
return redirect(url_for('upload_content'))
|
||||
|
||||
for file in files:
|
||||
filename = secure_filename(file.filename)
|
||||
@@ -202,14 +206,27 @@ def upload_content():
|
||||
# Remove the original PDF file after processing
|
||||
os.remove(file_path)
|
||||
|
||||
# Handle video files
|
||||
elif media_type == 'video':
|
||||
# Add the video file to the playlist
|
||||
if target_type == 'group':
|
||||
group = Group.query.get_or_404(target_id)
|
||||
for player in group.players:
|
||||
new_content = Content(file_name=filename, duration=duration, player_id=player.id)
|
||||
db.session.add(new_content)
|
||||
elif target_type == 'player':
|
||||
new_content = Content(file_name=filename, duration=duration, player_id=target_id)
|
||||
db.session.add(new_content)
|
||||
|
||||
db.session.commit()
|
||||
return redirect(return_url)
|
||||
|
||||
# Handle GET request
|
||||
target_type = request.args.get('target_type')
|
||||
target_id = request.args.get('target_id')
|
||||
return_url = request.args.get('return_url', url_for('dashboard'))
|
||||
|
||||
players = [{'id': player.id, 'username': player.username} for player in Player.query.filter(~Player.groups.any()).all()]
|
||||
players = [{'id': player.id, 'username': player.username} for player in Player.query.all()]
|
||||
groups = [{'id': group.id, 'name': group.name} for group in Group.query.all()]
|
||||
|
||||
return render_template('upload_content.html', target_type=target_type, target_id=target_id, players=players, groups=groups, return_url=return_url)
|
||||
|
||||
Reference in New Issue
Block a user