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

Cria model forms dinâmicos para poder validar inputs de querystring #455

Merged
merged 16 commits into from Oct 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/templates/core/dataset-detail.html
Expand Up @@ -86,6 +86,9 @@ <h5>Filtros</h5>
<div class="input-field col s6">
<label class="active" for="{{ field.name }}">{{ field.label }}</label>
{{ field }}
{% if field.errors %}
<span class="filter-error">{{ field.errors.as_text }}</span>
{% endif %}
</div>
{% endfor %}
berinhard marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
7 changes: 4 additions & 3 deletions core/views.py
Expand Up @@ -153,10 +153,11 @@ def dataset_detail(request, slug, tablename=""):

DynamicForm = get_table_dynamic_form(table)
filter_form = DynamicForm(data=query)
if not filter_form.is_valid():
raise Exception(str(filter_form.errors))
if filter_form.is_valid():
query = {k: v for k, v in filter_form.cleaned_data.items() if v != ""}
else:
berinhard marked this conversation as resolved.
Show resolved Hide resolved
query = {}

query = {k: v for k, v in filter_form.cleaned_data.items() if v != ""}
all_data = TableModel.objects.composed_query(query, search_query, order_by)

if download_csv:
Expand Down
7 changes: 6 additions & 1 deletion static/css/base.css
Expand Up @@ -191,4 +191,9 @@ a {

.error-container p{
font-size: 1.4rem;
}
}

.filter-error {
color: #ee6e73;
font-size: 1rem;
}