Skip to content

Commit

Permalink
Tag bottone rosso, aggiunto campo img_logo
Browse files Browse the repository at this point in the history
  • Loading branch information
Burlesco70 committed Nov 9, 2020
1 parent 3e05814 commit 03446e8
Show file tree
Hide file tree
Showing 139 changed files with 3,875 additions and 16 deletions.
1 change: 1 addition & 0 deletions Flask/Flask04/burlesco70/webapp/project/models/corsi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Binary file not shown.
4 changes: 1 addition & 3 deletions Flask/Flask05/burlesco70/webapp/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

CREATE_ALL = True

#db.metadata.clear()

if CREATE_ALL:
# Create entities
db.create_all()
Expand Down Expand Up @@ -49,6 +47,7 @@
"Andrea Guzzo",
"Intermedio",
"Corso in cinque serate del microframework Flask",
"immagine_flask"
)
corsoFlask.tags = [t1, t2, t4, t5]

Expand Down Expand Up @@ -147,7 +146,6 @@
for serata in list_serate:
print(f"Serata: {serata.id}, {serata.nome}, in data: {serata.data}")


# Get a serate by serate name
list_impostare = Serata.query.filter(Serata.nome.like("%impostare%")).all()
print(f"\nSerate da impostare:")
Expand Down
1 change: 1 addition & 0 deletions Flask/Flask05/burlesco70/webapp/migrations/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Generic single-database configuration.
Binary file not shown.
45 changes: 45 additions & 0 deletions Flask/Flask05/burlesco70/webapp/migrations/alembic.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# A generic, single database configuration.

[alembic]
# template used to generate migration files
# file_template = %%(rev)s_%%(slug)s

# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false


# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARN
handlers = console
qualname =

[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine

[logger_alembic]
level = INFO
handlers =
qualname = alembic

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S
96 changes: 96 additions & 0 deletions Flask/Flask05/burlesco70/webapp/migrations/env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
from __future__ import with_statement

import logging
from logging.config import fileConfig

from sqlalchemy import engine_from_config
from sqlalchemy import pool

from alembic import context

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config

# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)
logger = logging.getLogger('alembic.env')

# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
from flask import current_app
config.set_main_option(
'sqlalchemy.url',
str(current_app.extensions['migrate'].db.engine.url).replace('%', '%%'))
target_metadata = current_app.extensions['migrate'].db.metadata

# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.


def run_migrations_offline():
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url, target_metadata=target_metadata, literal_binds=True
)

with context.begin_transaction():
context.run_migrations()


def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""

# this callback is used to prevent an auto-migration from being generated
# when there are no changes to the schema
# reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
def process_revision_directives(context, revision, directives):
if getattr(config.cmd_opts, 'autogenerate', False):
script = directives[0]
if script.upgrade_ops.is_empty():
directives[:] = []
logger.info('No changes in schema detected.')

connectable = engine_from_config(
config.get_section(config.config_ini_section),
prefix='sqlalchemy.',
poolclass=pool.NullPool,
)

with connectable.connect() as connection:
context.configure(
connection=connection,
target_metadata=target_metadata,
process_revision_directives=process_revision_directives,
**current_app.extensions['migrate'].configure_args
)

with context.begin_transaction():
context.run_migrations()


if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()
24 changes: 24 additions & 0 deletions Flask/Flask05/burlesco70/webapp/migrations/script.py.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""${message}

Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}

"""
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}

# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}
branch_labels = ${repr(branch_labels)}
depends_on = ${repr(depends_on)}


def upgrade():
${upgrades if upgrades else "pass"}


def downgrade():
${downgrades if downgrades else "pass"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""prima ver
Revision ID: 60bb41479000
Revises:
Create Date: 2020-11-09 21:04:07.614174
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '60bb41479000'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('corso',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('nome', sa.String(length=100), nullable=False),
sa.Column('insegnante', sa.String(length=100), nullable=True),
sa.Column('livello', sa.String(length=100), nullable=True),
sa.Column('descrizione', sa.String(length=255), nullable=True),
sa.Column('logo_img', sa.String(length=100), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('nome')
)
op.create_table('tag',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name')
)
op.create_table('corso_tags',
sa.Column('corso_id', sa.Integer(), nullable=False),
sa.Column('tag_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['corso_id'], ['corso.id'], ),
sa.ForeignKeyConstraint(['tag_id'], ['tag.id'], ),
sa.PrimaryKeyConstraint('corso_id', 'tag_id')
)
op.create_table('serata',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('nome', sa.String(length=255), nullable=False),
sa.Column('descrizione', sa.String(length=255), nullable=False),
sa.Column('data', sa.DateTime(), nullable=False),
sa.Column('link_partecipazione', sa.String(length=255), nullable=True),
sa.Column('link_registrazione', sa.String(length=255), nullable=True),
sa.Column('corso_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['corso_id'], ['corso.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('id', 'data', name='contraint_serata')
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('serata')
op.drop_table('corso_tags')
op.drop_table('tag')
op.drop_table('corso')
# ### end Alembic commands ###
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
10 changes: 6 additions & 4 deletions Flask/Flask05/burlesco70/webapp/project/corsi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class Corso(db.Model):
id = db.Column(db.Integer(), primary_key=True)
nome = db.Column(db.String(100), unique=True, nullable=False)
insegnante = db.Column(db.String(100))
# Il numero delle lezioni è un attributo calcolabile
# lezioni = db.Column(db.Integer())
livello = db.Column(db.String(100))
descrizione = db.Column(db.String(255))
# Immagine logo da cartella static, se presente
logo_img = db.Column(db.String(100))

# Relazione 1:n; ordinamento serate per data
serate = db.relationship(
Expand All @@ -38,23 +38,25 @@ class Corso(db.Model):
)

# Costruttore
def __init__(self, nome, insegnante, livello, descrizione):
def __init__(self, nome, insegnante, livello, descrizione, logo_img=""):
self.nome = nome
self.insegnante = insegnante
self.livello = livello
self.descrizione = descrizione
self.logo_img = logo_img
# self.serate = serate
# self.tags = tags

# Visualize object corso informations
def __repr__(self):
return "\n{}: {} è tenuto da {}. Livello {}. Id {}. Tags {}".format(
return "\n{}: {} è tenuto da {}. Livello {}. Id {}. Tags {}. Logo {}".format(
self.nome,
self.descrizione,
self.insegnante,
self.livello,
self.id,
self.tags,
self.logo_img,
)


1 change: 0 additions & 1 deletion Flask/Flask05/burlesco70/webapp/project/corsi/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ def create():
def dettaglio_corso(corso_id):

# Gestione aggiunta serate

form = SerataForm()
if form.validate_on_submit():

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ <h1>Aggiungi serata per {{ corso.nome }}</h1>
outputFormat: 'dd/MM/yyyy',
});
});
</script>
</script>

<div class="form-group">
<input type="text" class="form-control" id="nome" name="nome"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% extends "base.html" %} {% block content %}
{% extends "base.html" %}
{% block content %}

<!-- Messaggi flash -->
<div class="container">
Expand All @@ -11,7 +12,7 @@
{% endif %}
{% endwith %}
{# End Flashed messages #}
</div>
</div>


<div class="container text-center">
Expand Down Expand Up @@ -48,13 +49,11 @@ <h5 class="card-title">{{ c.nome }}</h5>
</div>
</div>
</div>

<br>
{% endfor %}
</div>
</div>





{% endblock %}
Binary file modified Flask/Flask05/burlesco70/webapp/project/data.sqlite
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion Flask/Flask05/burlesco70/webapp/project/tags/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
'''
@tags_blueprint.route("/", methods=('GET', 'POST'))
def tags():
# Ordinamento alfabetico ascendente per titolo
# Ordinamento alfabetico ascendente per "name"
lista_tags = Tag.query.order_by(asc(Tag.name)).all()
'''
Crea nuovo tag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h1 class="display-1">
<div>
<span class="badge badge-secondary">{{t.name}}</span>
<a class="btn btn-primary pull-right" href="{{ url_for('tags.edit_tag', id=t.id) }}">Edit</a>
<a class="btn btn-primary pull-right" href="{{ url_for('tags.tag_delete', id=t.id) }}">Cancella</a>
<a class="btn btn-danger pull-right" href="{{ url_for('tags.tag_delete', id=t.id) }}">Cancella</a>
</div>
{% endfor %}
</h1>
Expand Down
Binary file added Flask/Flask05/maurici/ModelloDB.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 03446e8

Please sign in to comment.