Created
August 18, 2020 18:09
-
-
Save MariaCarolinass/7387a663e1f5e3ec88357654071252e1 to your computer and use it in GitHub Desktop.
Link nas categorias
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p>Categoria: <a href="category/{{ remove_accents(post.category) }}">{{ post.category }}</a></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask_wtf import FlaskForm | |
from wtforms import StringField, SelectField, TextField, TextAreaField, \ | |
DateField, PasswordField, RadioField, BooleanField, SubmitField | |
from wtforms.validators import ValidationError, DataRequired, Length, \ | |
Email, EqualTo, Regexp | |
from datetime import datetime | |
from flask_babel import _, lazy_gettext as _l | |
from app.models import User, Post, Software, Similar, \ | |
Comment, Report | |
import unicodedata | |
class PostForm(FlaskForm): | |
title = StringField(_l('Título: *'), validators=[DataRequired(), | |
Length(min=3)], render_kw={"placeholder": "Digite o título da Fonte de Dados Abertos"}) | |
tag = StringField(_l('Palavras-Chaves: *'), validators=[DataRequired()], | |
render_kw={"placeholder": "Digite as palavras-chaves da fonte"}) | |
category = SelectField(_l('Categoria: *'), validators=[DataRequired()], | |
choices=[('Corona Vírus','Corona Vírus'), ('Saúde', 'Saúde'), ('Educação', 'Educação'), | |
('Cinema', 'Cinema'), ('Música', 'Música'), ('Tecnologia', 'Tecnologia'), ('Ciência', 'Ciência'), | |
('Segurança Pública', 'Segurança Pública'), ('Meio Ambiente', 'Meio Ambiente'), ('Cultura', 'Cultura'), | |
('Países', 'Países'), ('IBGE', 'IBGE'), ('Clima', 'Clima'), ('Lazer', 'Lazer')], default=1) | |
officialLink = StringField(_l('Página Oficial: *'), validators=[DataRequired('URL verificada!'), | |
Regexp('^(http|https):\/\/[\w.\-]+(\.[\w.\-]+)+.*$', 0, | |
'URL inválida. Use https:// no início da URL')], | |
render_kw={"placeholder": "Digite a URL da fonte de dados abertos \ | |
(https://www.exemplo.com/)"}) | |
sphere = SelectField('Esfera: *', id="esfera", choices=[('Municipal', 'Municipal'), | |
('Estadual', 'Estadual'), ('Federal', 'Federal'), | |
('Internacional','Internacional')], validators=[DataRequired()]) | |
city = StringField(_l('Município:'), id="municipal", | |
render_kw={"placeholder": "Digite o município da fonte de dados abertos"}) | |
state = StringField(_l('Estado:'), id="estadual", | |
render_kw={"placeholder": "Digite o estato da fonte de dados abertos"}) | |
country = StringField(_l('País:'), id="internacional", | |
render_kw={"placeholder": "Digite o país da fonte de dados abertos"}) | |
description = TextAreaField(_l('Descrição: *'), validators=[DataRequired(), | |
Length(min=0, max=500)], render_kw={"rows": 6, "placeholder": "Digite uma breve descrição sobre a Fonte de Dados Abertos"}) | |
submit = SubmitField(_l('Registrar')) | |
def remove_accents(category): | |
try: | |
category = unicode(category, 'utf-8') | |
except NameError: # unicode is a default on python 3 | |
pass | |
category = unicodedata.normalize('NFD', category)\ | |
.encode('ascii', 'ignore')\ | |
.decode("utf-8") | |
return str(category) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment