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>') @bp.route('/preview/<int:id>')
def preview_file(id): def preview_file(id):
file = File.query.get(id) file = File.query.get(id)
categories = Category.query.all()
if (file.private == 1 and g.user is not None) or (file.private == 0): 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: else:
return abort(404) return abort(404)
@@ -108,7 +109,6 @@ def preview_file(id):
@bp.route('/rename/<int:id>', methods=['POST']) @bp.route('/rename/<int:id>', methods=['POST'])
@admin_required @admin_required
def rename_file(id): 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() new_name = request.form['new_name'].lower()
@@ -124,12 +124,30 @@ def rename_file(id):
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']) @bp.route('/delete/<int:id>', methods=['POST'])
@admin_required @admin_required
def delete_file(id): def delete_file(id):
if request.method == 'POST':
file = File.query.get(id) file = File.query.get(id)
_delete_file(file) _delete_file(file)
return redirect(url_for('index')) return redirect(url_for('index'))
else:
abort(404)

View File

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

View File

@@ -3,7 +3,7 @@
{% block title %}about{% endblock %} {% block title %}about{% endblock %}
{% block content %} {% 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> <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() %} {% for message in get_flashed_messages() %}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -9,16 +9,37 @@
{% endif %} {% endif %}
<div class="row"> <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> </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 %} {% if g.user %}
<form action="{{ url_for('files.rename_file', id=file.id) }}" method="post"> <form action="{{ url_for('files.rename_file', id=file.id) }}" method="post">
<div class="row">
<label for="new_name">~/rename</label> <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 }}"> <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>
<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> </form>
{% endif %} {% endif %}

View File

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