Se modifico un poco el layout y la opcion de cambiar la categoria

This commit is contained in:
Daniel Cortes
2019-03-11 23:58:56 -03:00
parent cb89bf932d
commit f12fe5b46d
11 changed files with 90 additions and 50 deletions

5
.idea/codeStyles/codeStyleConfig.xml generated Normal file
View File

@@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>

View File

@@ -99,8 +99,9 @@ def upload_file():
@bp.route('/preview/<int:id>')
def preview_file(id):
file = File.query.get(id)
categories = Category.query.all()
if (file.private == 1 and g.user is not None) or (file.private == 0):
return render_template('files/preview.html', file=file)
return render_template('files/preview.html', file=file, categories=categories)
else:
return abort(404)
@@ -108,28 +109,45 @@ def preview_file(id):
@bp.route('/rename/<int:id>', methods=['POST'])
@admin_required
def rename_file(id):
if request.method == 'POST':
file = File.query.get(id)
file = File.query.get(id)
new_name = request.form['new_name'].lower()
extension = file.filename.rsplit('.', 1)[1].lower()
new_name = request.form['new_name'].lower()
extension = file.filename.rsplit('.', 1)[1].lower()
if "." in new_name and _get_extension(new_name):
new_name = new_name.rsplit('.', 1)[0] + '.' + extension
else:
new_name = new_name + '.' + extension
if "." in new_name and _get_extension(new_name):
new_name = new_name.rsplit('.', 1)[0] + '.' + extension
else:
new_name = new_name + '.' + extension
_rename_file(file, new_name)
_rename_file(file, new_name)
return redirect(url_for('files.preview_file', id=file.id))
return redirect(url_for('files.preview_file', id=file.id))
@bp.route('/recategorize/<int:id>', methods=['POST'])
@admin_required
def recategorize(id):
file = File.query.get(id)
if 'new_category' not in request.form:
flash('No category selected')
return redirect(request.url)
new_category = Category.query.get(request.form['new_category'])
if new_category is None:
flash('The category selected won\'t exists')
return redirect(request.url)
file.category_id = new_category.id
db.session.commit()
return redirect(url_for('files.preview_file', id=file.id))
@bp.route('/delete/<int:id>', methods=['POST'])
@admin_required
def delete_file(id):
if request.method == 'POST':
file = File.query.get(id)
_delete_file(file)
return redirect(url_for('index'))
else:
abort(404)
file = File.query.get(id)
_delete_file(file)
return redirect(url_for('index'))

View File

@@ -8,21 +8,17 @@ a {
text-decoration: none;
}
img {
display: block;
max-width: 100%;
max-height: 90%;
margin: 1rem auto 5rem auto;
img.preview {
display: block;
max-width: 100%;
max-height: 100%;
margin: 1rem auto 5rem auto;
}
h1, h2, h3, h4, h5, h6 {
color: var(--primary-color);
}
.flash {
color: #ff0000;
}
.navbar {
padding-top: 2rem;
padding-bottom: 1.8rem;
@@ -32,28 +28,24 @@ h1, h2, h3, h4, h5, h6 {
margin-bottom: 2rem;
}
.navbar > *{
font-size: 2rem;
}
.nav-link {
color: var(--secondary-color);
}
.button.button-primary,
button.button-primary,
input[type="submit"].button-primary,
input[type="reset"].button-primary,
.button.button-primary,
button.button-primary,
input[type="submit"].button-primary,
input[type="reset"].button-primary,
input[type="button"].button-primary {
background-color: var(--primary-color);
border-color: var(--primary-color);
}
.button.button-primary:hover,
.button.button-primary:hover,
button.button-primary:hover,
input[type="submit"].button-primary:hover,
input[type="reset"].button-primary:hover,
input[type="button"].button-primary:hover,
input[type="button"].button-primary:hover,
.button.button-primary:focus,
button.button-primary:focus,
input[type="submit"].button-primary:focus,
@@ -63,7 +55,7 @@ input[type="button"].button-primary:focus {
border-color: var(--secondary-color);
}
.grid{
.grid {
display: grid;
grid-template-columns: repeat(5, 1fr);
grid-gap: 3rem 1rem;

View File

@@ -3,7 +3,7 @@
{% block title %}about{% endblock %}
{% block content %}
<h3>About This</h3>
<h4>About This</h4>
<p>This page is a simple static file server mainly for things that i want to link in my main webpage. If for some reason, one of the files uploaded here belongs to you, and you dont want it here, send me a message and I will contact you.</p>
{% for message in get_flashed_messages() %}

View File

@@ -11,7 +11,7 @@
<body>
<nav class="navbar">
<div class="container">
<a href="{{ url_for('index') }}" class="nav-brand">/files</a>
<a href="{{ url_for('index') }}" class="h1 nav-brand">/files</a>
<a href="{{ url_for('categories.index') }}" class="nav-link">/categories</a>
<a href="{{ url_for('about') }}" class="nav-link">/about</a>

View File

@@ -1,9 +1,9 @@
{% extends 'base.html' %}
{% block title %}Categories{% endblock %}
{% block title %}categories/create{% endblock %}
{% block content %}
<h3>Create a new Category</h3>
<h3>Create category</h3>
<form method="post">
<label for="name">~/name</label>
<input type="text" class="u-full-width" name="name" id="name">

View File

@@ -1,8 +1,9 @@
{% extends 'base.html' %}
{% block title %}category{% endblock %}
{% block title %}categories{% endblock %}
{% block content %}
<h4>Categories</h4>
<div class="grid">
{% for category in categories %}
<a href="{{ url_for('categories.view', id=category.id) }}">{{ category.name }}</a>
@@ -10,4 +11,3 @@
</div>
{% endblock %}

View File

@@ -3,7 +3,7 @@
{% block title %}categories/view/{{ category.name }}{% endblock %}
{% block content %}
<h3>{{ category.name }}</h3>
<h4>{{ category.name }}</h4>
<div class="grid">
{% for file in files %}
<a href="{{ url_for('files.preview_file', id=file.id) }}">{{ file.filename }}</a>

View File

@@ -5,7 +5,9 @@
{% block content %}
<div class="grid">
{% for file in files %}
<a href="{{ url_for('files.preview_file', id=file.id) }}">{{ file.filename}}</a>
<div>
<a href="{{ url_for('files.preview_file', id=file.id) }}">{{ file.filename}}</a>
</div>
{% endfor %}
</div>
{% endblock %}

View File

@@ -9,16 +9,37 @@
{% endif %}
<div class="row">
<h3 class="u-pull-left"><a href="{{ url_for('files.uploaded_file', filename=file.filename) }}">{{ file.filename }}</a></h3>
<h4 class="u-pull-left">
<a href="{{ url_for('files.uploaded_file', filename=file.filename) }}">{{ file.filename }}</a>
</h4>
</div>
<img src="{{ url_for('files.uploaded_file', filename=file.filename) }}">
<img class="preview" src="{{ url_for('files.uploaded_file', filename=file.filename) }}">
{% if g.user %}
<form action="{{ url_for('files.rename_file', id=file.id) }}" method="post">
<label for="new_name">~/rename</label>
<input type="text" class="u-full-width" id="new_name" name="new_name" value="{{ file.filename }}">
<input type="submit" class="button-primary u-pull-right" value="rename">
<div class="row">
<label for="new_name">~/rename</label>
<div class="nine columns">
<input type="text" class="u-full-width" id="new_name" name="new_name" value="{{ file.filename }}">
</div>
<div class="two columns">
<input type="submit" class="button-primary" value="rename">
</div>
</div>
</form>
<form action="{{ url_for('files.recategorize', id=file.id) }}" method="post">
<label for="new_category">~/category</label>
<div class="nine columns">
<select class="u-full-width" name="new_category" id="new_category">
{% for category in categories %}
<option value="{{ category.id }}" {{ 'selected' if category.id == file.category_id }}>{{ category.name }}</option>
{% endfor %}
</select>
</div>
<div class="two columns">
<input type="submit" class="button-primary" value="change category">
</div>
</form>
{% endif %}

View File

@@ -3,6 +3,8 @@
{% block title %}upload{% endblock %}
{% block content %}
<h4>Upload</h4>
<form method="post" enctype="multipart/form-data">
<label for="file">~/file</label>
<input type="file" class="u-full-width" name="file" id="file">