Skip to content

Commit

Permalink
Atualização do projeto
Browse files Browse the repository at this point in the history
* Python 3.8.5
* Pipenv
* Flask na ultima versão 1.1.2
* Atualização de todas as libs
* Compatibilização py3 e libs
* remove create_env.sh
* remove requirements.txt
  • Loading branch information
berlotto committed Feb 21, 2021
1 parent 051334d commit 7b7117f
Show file tree
Hide file tree
Showing 16 changed files with 537 additions and 129 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "/home/sergio/.virtualenvs/flask-app-template-b5GscEs_/bin/python"
}
25 changes: 25 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"

[packages]
flask = "*"
flask-admin = "*"
flask-bootstrap = "*"
flask-cache = "*"
flask-flatpages = "*"
flask-gravatar = "*"
flask-login = "*"
flask-mail = "*"
flask-pymongo = "*"
flask-restless = "*"
flask-sqlalchemy = "*"
flask-themes = "*"
flask-uploads = "*"
flask-wtf = "*"

[dev-packages]

[requires]
python_version = "3.8"
412 changes: 412 additions & 0 deletions Pipfile.lock

Large diffs are not rendered by default.

13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ Use this Flask app to initiate your project with less work. In this application
* **Flask-SQLAlchemy** - Adds SQLAlchemy support to Flask. Quick and easy.
* **Flask-PyMongo** - Add PyMongo Support MongoDB.
* **Flask-Themes** - Flask-Themes makes it easy for your application to support a wide range of appearances.
* **Flask-WTF** - Flask-Themes makes it easy for your application to support a wide range of appearances.
* **Flask-WTF** - Simple integration of Flask and WTForms, including CSRF, file upload, and reCAPTCHA.

## Requirements

gcc, make, Python 2.5+, python-pip, virtualenv
Python 3.8.5+, pipenv

## Instalation

Expand All @@ -29,18 +29,13 @@ First, clone this repository.
$ git clone http://github.com/berlotto/flask-app-template
$ cd flask-app-template

Create a virtualenv, and activate this:

$ virtualenv env
$ source env/bin/activate

After, install all necessary to run:

$ pip install -r requirements.txt
$ pipenv install

Than, run the application:

$ python run.py
$ pipenv run python run.py

To see your application, access this url in your browser:

Expand Down
8 changes: 4 additions & 4 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"""

from flask import Flask
from flask.ext.bootstrap import Bootstrap
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.pymongo import PyMongo
from flask.ext.login import LoginManager
from flask_bootstrap import Bootstrap
from flask_sqlalchemy import SQLAlchemy
from flask_pymongo import PyMongo
from flask_login import LoginManager

app = Flask(__name__)

Expand Down
11 changes: 4 additions & 7 deletions app/configuration.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
# -*- encoding: utf-8 -*-
"""
Python Aplication Template
Licence: GPLv3
"""

class Config(object):
"""
Configuration base, for all environments.
"""
DEBUG = False
TESTING = False
DATABASE_URI = 'sqlite:///application.db'
SQLALCHEMY_DATABASE_URI = 'sqlite:///application.db'
BOOTSTRAP_FONTAWESOME = True
SECRET_KEY = "MINHACHAVESECRETA"
CSRF_ENABLED = True
SQLALCHEMY_TRACK_MODIFICATIONS = True

#Get your reCaptche key on: https://www.google.com/recaptcha/admin/create
#RECAPTCHA_PUBLIC_KEY = "6LffFNwSAAAAAFcWVy__EnOCsNZcG2fVHFjTBvRP"
#RECAPTCHA_PRIVATE_KEY = "6LffFNwSAAAAAO7UURCGI7qQ811SOSZlgU69rvv7"

class ProductionConfig(Config):
DATABASE_URI = 'mysql://user@localhost/foo'
SQLALCHEMY_DATABASE_URI = 'mysql://user@localhost/foo'
SQLALCHEMY_TRACK_MODIFICATIONS = False

class DevelopmentConfig(Config):
DEBUG = True
Expand Down
15 changes: 5 additions & 10 deletions app/forms.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
# -*- encoding: utf-8 -*-
"""
Python Aplication Template
Licence: GPLv3
"""
from flask_wtf import FlaskForm
from wtforms import TextField, TextAreaField, DateTimeField, PasswordField
from wtforms.validators import Required

from flask.ext.wtf import Form, TextField, TextAreaField, DateTimeField, PasswordField
from flask.ext.wtf import Required

class ExampleForm(Form):
class ExampleForm(FlaskForm):
title = TextField(u'Título', validators = [Required()])
content = TextAreaField(u'Conteúdo')
date = DateTimeField(u'Data', format='%d/%m/%Y %H:%M')
#recaptcha = RecaptchaField(u'Recaptcha')

class LoginForm(Form):
class LoginForm(FlaskForm):
user = TextField(u'Usuário', validators = [Required()])
password = PasswordField(u'Senha', validators = [Required()])
8 changes: 1 addition & 7 deletions app/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# -*- encoding: utf-8 -*-
"""
Python Aplication Template
Licence: GPLv3
"""

from app import db

class ModelExample(db.Model):
Expand Down Expand Up @@ -31,7 +25,7 @@ def is_anonymous(self):
return False

def get_id(self):
return unicode(self.id)
return str(self.id)

def __repr__(self):
return '<User %r>' % (self.nickname)
83 changes: 59 additions & 24 deletions app/templates/base.html
Original file line number Diff line number Diff line change
@@ -1,36 +1,71 @@
{% extends "bootstrap_base.html" %}
{% extends "bootstrap/base.html" %}

{%block title%}Base{%endblock%}

{%block body_content%}
{% block navbar %}
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>

<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
{% endblock %}

<div class="container">
<div class="row">
<div class="span12">

<div class="navbar">
<div class="navbar-inner">
<a class="brand" href="#">MySiteName</a>
<ul class="nav">
<li class="active"><a href="/">Home</a></li>
<li><a href="/list">List</a></li>
<li><a href="/new">New</a></li>
</ul>
</div>
</div>
{%block content %}

<form class="form form-inline pull-right">
<input type="text" class="span2">
<button type="submit" class="btn">Submit</button>
</form>

</div>
</div>
<div class="container">

{% with messages = get_flashed_messages() %}
{% if messages %}
<div class="row">
<div class="span8 offset4">
<div class="col-md-4">
<ul>
{% for message in messages %}
<li>{{ message }} </li>
Expand Down
6 changes: 3 additions & 3 deletions app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

<h1>Index</h1>
<div class="row">
<div class="span4">
<div class="col-md-4">
<img src="http://placehold.it/360x200" class="img-polaroid">
</div>
<div class="span4">
<div class="col-md-4">
<img src="http://placehold.it/360x200" class="img-polaroid">
</div>
<div class="span4">
<div class="col-md-4">
<img src="http://placehold.it/360x200" class="img-polaroid">
</div>
</div>
Expand Down
10 changes: 5 additions & 5 deletions app/templates/login.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{% extends "base.html" %}
{% import "bootstrap_wtf.html" as wtf %}
{% import "bootstrap/wtf.html" as wtf %}

{%block title%}Login!{%endblock%}

{%block main_content%}

<h1>Login</h1>
<div class="row">
<div class="span12">
<div class="col-md-4 col-md-offset-4">

<form action="." method="post" name="loginform">
<form action="." method="post" class="form form-horizontal" name="loginform">
{{ wtf.form_errors(form,"only") }}

{{ form.hidden_tag() }}
{{ wtf.horizontal_field(form.user) }}<br>
{{ wtf.horizontal_field(form.password) }}
{{ wtf.form_field(form.user) }}<br>
{{ wtf.form_field(form.password) }}

<div class="form-actions">
<button name-"action_save" type="submit" class="btn btn-primary">Salvar</button>
Expand Down
2 changes: 1 addition & 1 deletion app/templates/new.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<h1>Novo</h1>
<div class="row">
<div class="span12">
<div class="col-sm">

<form action="/save/" method="post" name="exampleform">
{{ wtf.form_errors(form,"only") }}
Expand Down
25 changes: 11 additions & 14 deletions app/views.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
# -*- encoding: utf-8 -*-
"""
Python Aplication Template
Licence: GPLv3
"""

from flask import url_for, redirect, render_template, flash, g, session
from flask.ext.login import login_user, logout_user, current_user, login_required
from flask_login import login_user, logout_user, current_user, login_required
from app import app, lm
from forms import ExampleForm, LoginForm
from models import User
from app.forms import ExampleForm, LoginForm
from app.models import User


@app.route('/')
def index():
Expand All @@ -19,21 +14,23 @@ def index():
def posts():
return render_template('list.html')


@app.route('/new/')
@login_required
def new():
form = ExampleForm()
return render_template('new.html', form=form)


@app.route('/save/', methods = ['GET','POST'])
@login_required
def save():
form = ExampleForm()
if form.validate_on_submit():
print "salvando os dados:"
print form.title.data
print form.content.data
print form.date.data
print("salvando os dados:")
print(form.title.data)
print(form.content.data)
print(form.date.data)
flash('Dados salvos!')
return render_template('new.html', form=form)

Expand All @@ -53,7 +50,7 @@ def load_user(id):

@app.route('/login/', methods = ['GET', 'POST'])
def login():
if g.user is not None and g.user.is_authenticated():
if g.user is not None and g.user.is_authenticated:
return redirect(url_for('index'))
form = LoginForm()
if form.validate_on_submit():
Expand Down
14 changes: 0 additions & 14 deletions create_env.sh

This file was deleted.

25 changes: 0 additions & 25 deletions requirements.txt

This file was deleted.

Loading

0 comments on commit 7b7117f

Please sign in to comment.