[Web Interface] Fixed some stuff which I broke

This commit is contained in:
Fabian Würfl 2018-05-21 13:56:03 +02:00
parent adfdb6f06c
commit ef32c010af
3 changed files with 38 additions and 30 deletions

View File

@ -128,11 +128,12 @@ def index():
current_music = None
return render_template('index.html',
current_music=current_music,
user=var.user,
playlist=var.playlist,
all_files=files,
music_library=music_library)
current_music=current_music,
music_library=music_library,
os=os,
playlist=var.playlist,
user=var.user)
@web.route('/upload', methods=["POST"])

View File

@ -1,7 +1,7 @@
{% macro dirlisting(dir, path='') -%}
<ul>
{% for subdirname, subdirobj in dir.get_subdirs().items() %}
{%- set subdirpath = path + subdirname + '/' %}
{%- set subdirpath = os.path.relpath(subdirobj.fullpath, music_library.fullpath) %}
<li class="directory">
<span>{{ subdirname }}/&nbsp;</span>
<form method="post" class="directory form1">
@ -22,13 +22,14 @@
{%- set files = dir.get_files() %}
{%- if files %}
{% for file in files %}
{% set filepath = os.path.relpath(os.path.join(dir.fullpath, file), music_library.fullpath) %}
<li class="file">
<form method="post" class="file file_add">
<input type="text" value="{{ subdirpath }}{{ file }}" name="add_file" hidden>
<input type="text" value="{{ filepath }}" name="add_file" hidden>
<input type="submit" value="Add">
</form>
<form action="./download" method="get" class="file file_download">
<input type="text" value="{{ subdirpath }}{{ file }}" name="file" hidden>
<input type="text" value="{{ filepath }}" name="file" hidden>
<input type="submit" value="Download">
&nbsp;{{ file }}
</form>
@ -89,10 +90,14 @@
{% endfor %}
</ul>
<h2>Music library:</h2>
<form action="./download" method="get" class="directory">
<form action="./download" method="get" class="directory form1">
<input type="text" value="./" name="directory" hidden>
<input type="submit" value="Download entire music library">
</form>
<form method="post" class="directory form3">
<input type="text" value="./" name="add_folder_recursively" hidden>
<input type="submit" value="Add all tracks from music library (recursively)">
</form>
<br />
{{ dirlisting(music_library) }}

16
util.py
View File

@ -61,8 +61,10 @@ def zipdir(zippath, zipname_prefix=None):
return zipname
class Dir(object):
def __init__(self, name):
self.name = name
def __init__(self, path):
self.name = os.path.basename(path.strip('/'))
self.fullpath = path
print(self.name, self.fullpath)
self.subdirs = {}
self.files = []
@ -76,7 +78,7 @@ class Dir(object):
if subdir in self.subdirs:
self.subdirs[subdir].add_file(file)
else:
self.subdirs[subdir] = Dir(subdir)
self.subdirs[subdir] = Dir(os.path.join(self.fullpath, subdir))
self.subdirs[subdir].add_file(file)
else:
self.files.append(file)
@ -84,7 +86,7 @@ class Dir(object):
def get_subdirs(self, path=None):
subdirs = []
if path and path != '':
if path and path != '' and path != './':
subdir = path.split('/')[0]
if subdir in self.subdirs:
searchpath = '/'.join(path.split('/')[1::])
@ -97,7 +99,7 @@ class Dir(object):
def get_subdirs_recursively(self, path=None):
subdirs = []
if path and path != '':
if path and path != '' and path != './':
subdir = path.split('/')[0]
if subdir in self.subdirs:
searchpath = '/'.join(path.split('/')[1::])
@ -113,7 +115,7 @@ class Dir(object):
def get_files(self, path=None):
files = []
if path and path != '':
if path and path != '' and path != './':
subdir = path.split('/')[0]
if subdir in self.subdirs:
searchpath = '/'.join(path.split('/')[1::])
@ -125,7 +127,7 @@ class Dir(object):
def get_files_recursively(self, path=None):
files = []
if path and path != '':
if path and path != '' and path != './':
subdir = path.split('/')[0]
if subdir in self.subdirs:
searchpath = '/'.join(path.split('/')[1::])