Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Breadcrumbs #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions updog/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,37 @@
from updog.utils.output import error, info, warn, success
from updog import version as VERSION

def breadcrumb_items(base_directory, path):

base_parts = []
path_parts = []
current = '/'

if path:
items = [p for p in path.split('/') if p]
i = 0
for item in items:
i += 1
current += item + '/'
if i == len(items):
# Current directory
path_parts.append((item, None))
else:
# Parent directory of current
path_parts.append((item, current))

items = [p for p in base_directory.split('/') if p]
i = 0
for item in items:
i += 1
if i == len(items) and path_parts:
# Link to root directory
base_parts.append((item, '/'))
else:
# Unsharable item, parent of root directory
base_parts.append((item, None))

return base_parts + path_parts

def read_write_directory(directory):
if os.path.exists(directory):
Expand All @@ -22,7 +53,6 @@ def read_write_directory(directory):
else:
error('The specified directory does not exist')


def parse_arguments():
parser = argparse.ArgumentParser(prog='updog')
cwd = os.getcwd()
Expand All @@ -42,7 +72,6 @@ def parse_arguments():

return args


def main():
args = parse_arguments()

Expand Down Expand Up @@ -110,8 +139,13 @@ def home(path):
except PermissionError:
abort(403, 'Read Permission Denied: ' + requested_path)

return render_template('home.html', files=directory_files, back=back,
directory=requested_path, is_subdirectory=is_subdirectory, version=VERSION)
return render_template('home.html',
files=directory_files,
back=back,
directory=requested_path,
breadcrumb_path = breadcrumb_items(base_directory, path),
is_subdirectory=is_subdirectory,
version=VERSION)
else:
return redirect('/')

Expand Down
4 changes: 2 additions & 2 deletions updog/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</div>

<div class="heading_title_p">
<h2>Directory: {{ directory }}</h2>
<h2>Directory: {% for crumb in breadcrumb_path %}/{% if crumb[1] %}<a href="{{crumb[1]}}">{{crumb[0]}}</a>{% else %}{{ crumb[0] }}{% endif %}{% endfor %}</h2>
</div>
</header>

Expand Down Expand Up @@ -115,4 +115,4 @@ <h2>Directory: {{ directory }}</h2>
<script src="{{ url_for('static', filename='js/main.js') }}"></script>

</body>
</html>
</html>