mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-05-06 05:01:48 +02:00
New tab upload
This commit is contained in:
parent
f51a02005c
commit
3fe668c1e1
6 changed files with 46 additions and 2 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -10,4 +10,5 @@ dist
|
|||
build
|
||||
.vscode
|
||||
.env
|
||||
.pytest_cache
|
||||
.pytest_cache
|
||||
.idea/
|
||||
|
|
|
@ -10,6 +10,8 @@ from wtforms.validators import (
|
|||
NumberRange,
|
||||
Optional,
|
||||
)
|
||||
from flask_wtf.file import FileField, FileAllowed, FileRequired
|
||||
|
||||
from flask_babel import lazy_gettext as _
|
||||
from flask import request
|
||||
from werkzeug.security import generate_password_hash
|
||||
|
@ -109,6 +111,12 @@ class EditProjectForm(FlaskForm):
|
|||
|
||||
return project
|
||||
|
||||
class UploadForm(FlaskForm):
|
||||
file = FileField('JSON', validators=[
|
||||
FileRequired(),
|
||||
FileAllowed(['json', 'JSON'], 'JSON only!')
|
||||
])
|
||||
|
||||
|
||||
class ProjectForm(EditProjectForm):
|
||||
id = StringField(_("Project identifier"), validators=[DataRequired()])
|
||||
|
|
|
@ -85,6 +85,16 @@
|
|||
|
||||
{% endmacro %}
|
||||
|
||||
{% macro upload_json(form) %}
|
||||
{% include "display_errors.html" %}
|
||||
{{ form.hidden_tag() }}
|
||||
{{ form.file }}
|
||||
{{ form.csrf_token() }}
|
||||
<div class="actions">
|
||||
<button class="btn btn-primary">{{ _("BlaBlaBla") }}</button>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro add_bill(form, edit=False, title=True) %}
|
||||
|
||||
<fieldset>
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
<li class="nav-item{% if current_view == 'settle_bill' %} active{% endif %}"><a class="nav-link" href="{{ url_for("main.settle_bill") }}">{{ _("Settle") }}</a></li>
|
||||
<li class="nav-item{% if current_view == 'statistics' %} active{% endif %}"><a class="nav-link" href="{{ url_for("main.statistics") }}">{{ _("Statistics") }}</a></li>
|
||||
<li class="nav-item{% if current_view == 'edit_project' %} active{% endif %}"><a class="nav-link" href="{{ url_for("main.edit_project") }}">{{ _("Settings") }}</a></li>
|
||||
<li class="nav-item{% if current_view == 'upload_json' %} active{% endif %}"><a class="nav-link" href="{{ url_for("main.upload_json") }}">{{ _("Upload") }}</a></li>
|
||||
{% endblock %}
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
|
10
ihatemoney/templates/upload_json.html
Normal file
10
ihatemoney/templates/upload_json.html
Normal file
|
@ -0,0 +1,10 @@
|
|||
{% extends "layout.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h2>{{ _("Upload JSON") }}</h2>
|
||||
<p>
|
||||
<form class="form-horizontal" method="post" enctype="multipart/form-data">
|
||||
{{ forms.upload_json(form) }}
|
||||
</form>
|
||||
</p>
|
||||
{% endblock %}
|
|
@ -43,7 +43,7 @@ from ihatemoney.forms import (
|
|||
ResetPasswordForm,
|
||||
ProjectForm,
|
||||
get_billform_for,
|
||||
)
|
||||
UploadForm)
|
||||
from ihatemoney.utils import (
|
||||
Redirect303,
|
||||
list_of_dicts2json,
|
||||
|
@ -391,6 +391,20 @@ def edit_project():
|
|||
)
|
||||
|
||||
|
||||
@main.route('/<project_id>/upload_json', methods=['GET', 'POST'])
|
||||
def upload_json():
|
||||
form = UploadForm()
|
||||
pid = g.project.id
|
||||
if form.validate_on_submit():
|
||||
filename = pid+"_uploaded_bills.json"
|
||||
form.file.data.save(filename)
|
||||
return redirect(url_for('upload'))
|
||||
os.remove(filename)
|
||||
return redirect(url_for('main.list_bills'))
|
||||
|
||||
return render_template('upload_json.html', form=form)
|
||||
|
||||
|
||||
@main.route("/<project_id>/delete")
|
||||
def delete_project():
|
||||
g.project.remove_project()
|
||||
|
|
Loading…
Reference in a new issue