Merge pull request #5 from BafDyce/directory-listing-fixes
[Web Interface] Fixed some stuff which I broke
This commit is contained in:
		@@ -128,11 +128,12 @@ def index():
 | 
				
			|||||||
        current_music = None
 | 
					        current_music = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return render_template('index.html',
 | 
					    return render_template('index.html',
 | 
				
			||||||
                           current_music=current_music,
 | 
					 | 
				
			||||||
                           user=var.user,
 | 
					 | 
				
			||||||
                           playlist=var.playlist,
 | 
					 | 
				
			||||||
                            all_files=files,
 | 
					                            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"])
 | 
					@web.route('/upload', methods=["POST"])
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,7 @@
 | 
				
			|||||||
{% macro dirlisting(dir, path='') -%}
 | 
					{% macro dirlisting(dir, path='') -%}
 | 
				
			||||||
    <ul>
 | 
					    <ul>
 | 
				
			||||||
    {% for subdirname, subdirobj in dir.get_subdirs().items() %}
 | 
					    {% 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">
 | 
					        <li class="directory">
 | 
				
			||||||
            <span>{{ subdirname }}/ </span>
 | 
					            <span>{{ subdirname }}/ </span>
 | 
				
			||||||
            <form method="post" class="directory form1">
 | 
					            <form method="post" class="directory form1">
 | 
				
			||||||
@@ -22,13 +22,14 @@
 | 
				
			|||||||
    {%- set files = dir.get_files() %}
 | 
					    {%- set files = dir.get_files() %}
 | 
				
			||||||
    {%- if files %}
 | 
					    {%- if files %}
 | 
				
			||||||
        {% for file in files %}
 | 
					        {% for file in files %}
 | 
				
			||||||
 | 
					        {% set filepath = os.path.relpath(os.path.join(dir.fullpath, file), music_library.fullpath) %}
 | 
				
			||||||
        <li class="file">
 | 
					        <li class="file">
 | 
				
			||||||
            <form method="post" class="file file_add">
 | 
					            <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">
 | 
					                <input type="submit" value="Add">
 | 
				
			||||||
            </form>
 | 
					            </form>
 | 
				
			||||||
            <form action="./download" method="get"  class="file file_download">
 | 
					            <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">
 | 
					                <input type="submit" value="Download">
 | 
				
			||||||
                 {{ file }}
 | 
					                 {{ file }}
 | 
				
			||||||
            </form>
 | 
					            </form>
 | 
				
			||||||
@@ -89,10 +90,14 @@
 | 
				
			|||||||
        {% endfor %}
 | 
					        {% endfor %}
 | 
				
			||||||
    </ul>
 | 
					    </ul>
 | 
				
			||||||
    <h2>Music library:</h2>
 | 
					    <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="text" value="./" name="directory" hidden>
 | 
				
			||||||
        <input type="submit" value="Download entire music library">
 | 
					        <input type="submit" value="Download entire music library">
 | 
				
			||||||
    </form>
 | 
					    </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 />
 | 
					    <br />
 | 
				
			||||||
    {{ dirlisting(music_library) }}
 | 
					    {{ dirlisting(music_library) }}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										16
									
								
								util.py
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								util.py
									
									
									
									
									
								
							@@ -61,8 +61,10 @@ def zipdir(zippath, zipname_prefix=None):
 | 
				
			|||||||
    return zipname
 | 
					    return zipname
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Dir(object):
 | 
					class Dir(object):
 | 
				
			||||||
    def __init__(self, name):
 | 
					    def __init__(self, path):
 | 
				
			||||||
        self.name = name
 | 
					        self.name = os.path.basename(path.strip('/'))
 | 
				
			||||||
 | 
					        self.fullpath = path
 | 
				
			||||||
 | 
					        print(self.name, self.fullpath)
 | 
				
			||||||
        self.subdirs = {}
 | 
					        self.subdirs = {}
 | 
				
			||||||
        self.files = []
 | 
					        self.files = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -76,7 +78,7 @@ class Dir(object):
 | 
				
			|||||||
            if subdir in self.subdirs:
 | 
					            if subdir in self.subdirs:
 | 
				
			||||||
                self.subdirs[subdir].add_file(file)
 | 
					                self.subdirs[subdir].add_file(file)
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                self.subdirs[subdir] = Dir(subdir)
 | 
					                self.subdirs[subdir] = Dir(os.path.join(self.fullpath, subdir))
 | 
				
			||||||
                self.subdirs[subdir].add_file(file)
 | 
					                self.subdirs[subdir].add_file(file)
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            self.files.append(file)
 | 
					            self.files.append(file)
 | 
				
			||||||
@@ -84,7 +86,7 @@ class Dir(object):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def get_subdirs(self, path=None):
 | 
					    def get_subdirs(self, path=None):
 | 
				
			||||||
        subdirs = []
 | 
					        subdirs = []
 | 
				
			||||||
        if path and path != '':
 | 
					        if path and path != '' and path != './':
 | 
				
			||||||
            subdir = path.split('/')[0]
 | 
					            subdir = path.split('/')[0]
 | 
				
			||||||
            if subdir in self.subdirs:
 | 
					            if subdir in self.subdirs:
 | 
				
			||||||
                searchpath = '/'.join(path.split('/')[1::])
 | 
					                searchpath = '/'.join(path.split('/')[1::])
 | 
				
			||||||
@@ -97,7 +99,7 @@ class Dir(object):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def get_subdirs_recursively(self, path=None):
 | 
					    def get_subdirs_recursively(self, path=None):
 | 
				
			||||||
        subdirs = []
 | 
					        subdirs = []
 | 
				
			||||||
        if path and path != '':
 | 
					        if path and path != '' and path != './':
 | 
				
			||||||
            subdir = path.split('/')[0]
 | 
					            subdir = path.split('/')[0]
 | 
				
			||||||
            if subdir in self.subdirs:
 | 
					            if subdir in self.subdirs:
 | 
				
			||||||
                searchpath = '/'.join(path.split('/')[1::])
 | 
					                searchpath = '/'.join(path.split('/')[1::])
 | 
				
			||||||
@@ -113,7 +115,7 @@ class Dir(object):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def get_files(self, path=None):
 | 
					    def get_files(self, path=None):
 | 
				
			||||||
        files = []
 | 
					        files = []
 | 
				
			||||||
        if path and path != '':
 | 
					        if path and path != '' and path != './':
 | 
				
			||||||
            subdir = path.split('/')[0]
 | 
					            subdir = path.split('/')[0]
 | 
				
			||||||
            if subdir in self.subdirs:
 | 
					            if subdir in self.subdirs:
 | 
				
			||||||
                searchpath = '/'.join(path.split('/')[1::])
 | 
					                searchpath = '/'.join(path.split('/')[1::])
 | 
				
			||||||
@@ -125,7 +127,7 @@ class Dir(object):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def get_files_recursively(self, path=None):
 | 
					    def get_files_recursively(self, path=None):
 | 
				
			||||||
        files = []
 | 
					        files = []
 | 
				
			||||||
        if path and path != '':
 | 
					        if path and path != '' and path != './':
 | 
				
			||||||
            subdir = path.split('/')[0]
 | 
					            subdir = path.split('/')[0]
 | 
				
			||||||
            if subdir in self.subdirs:
 | 
					            if subdir in self.subdirs:
 | 
				
			||||||
                searchpath = '/'.join(path.split('/')[1::])
 | 
					                searchpath = '/'.join(path.split('/')[1::])
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user