diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..7663589 --- /dev/null +++ b/.flake8 @@ -0,0 +1,14 @@ +[flake8] +extend-ignore = E501, E203 +exclude = + .git, + .github, + .pytest_cache, + .vscode, + __pycache__, + doc, + env, + tmp +per-file-ignores = + __init__.py: F401, E402 + migrations/*: F401, E402 \ No newline at end of file diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..a1b4ae0 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,12 @@ +name: Lint + +on: [push, pull_request] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + - uses: psf/black@stable + - uses: TrueBrain/actions-flake8@v1.4.1 \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..65d80a7 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,10 @@ +repos: + - repo: https://github.com/psf/black + rev: stable + hooks: + - id: black + language_version: python3.7 + - repo: https://gitlab.com/pycqa/flake8 + rev: 3.8.4 + hooks: + - id: flake8 \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 9385183..9c7b602 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,4 +15,6 @@ before_script: - psql -c 'create database gsevpt_tests;' -U postgres - psql -c 'create extension postgis;' -U postgres -d gsevpt_tests script: - - pytest + - pytest --cov=project +after_success: + — coveralls diff --git a/.vscode/settings.json b/.vscode/settings.json index de66823..7f35355 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,7 @@ { - "python.pythonPath": "/Users/daniel/Projects/gsevpt/env/bin/python3" + "python.pythonPath": "/Users/daniel/Projects/gsevpt/env/bin/python3", + "python.formatting.provider": "black", + "python.linting.enabled": true, + "python.linting.pylintEnabled": false, + "python.linting.flake8Enabled": true } \ No newline at end of file diff --git a/README.md b/README.md index e7a67c9..8b1b313 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -[](https://travis-ci.com/DanielGrams/gsevpt) - # Goslar Event Prototype +[](https://travis-ci.com/DanielGrams/gsevpt) [](https://coveralls.io/github/DanielGrams/gsevpt?branch=master) [](https://github.com/psf/black) + Website prototype using Python, Flask and Postgres running on Heroku. ## Automatic Deployment @@ -67,4 +67,4 @@ Create `.env` file in the root directory or pass as environment variables. ## Development -[Development](doc/development.md) \ No newline at end of file +[Development](doc/development.md) diff --git a/bootstrap.py b/bootstrap.py index c3bbcfc..b4ae769 100644 --- a/bootstrap.py +++ b/bootstrap.py @@ -1 +1 @@ -from project import app \ No newline at end of file +from project import app # noqa: F401 diff --git a/doc/development.md b/doc/development.md index c9834c0..01067bd 100644 --- a/doc/development.md +++ b/doc/development.md @@ -15,6 +15,12 @@ psql -c 'create extension postgis;' -d gsevpt_tests -U postgres pytest ``` +With coverage: + +```sh +pytest --cov-report=html --cov=project +``` + ## Database ### Create new revision diff --git a/manage.py b/manage.py index 7d0d73c..9413b63 100644 --- a/manage.py +++ b/manage.py @@ -1,11 +1,11 @@ -from flask_script import Manager, Command +from flask_script import Manager from flask_migrate import Migrate, MigrateCommand from project import app, db migrate = Migrate(app, db) manager = Manager(app) -manager.add_command('db', MigrateCommand) +manager.add_command("db", MigrateCommand) -if __name__ == '__main__': - manager.run() \ No newline at end of file +if __name__ == "__main__": + manager.run() diff --git a/migrations/env.py b/migrations/env.py index 9452179..b896f2c 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -15,17 +15,19 @@ 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') +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 + "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: @@ -46,9 +48,7 @@ def run_migrations_offline(): """ url = config.get_main_option("sqlalchemy.url") - context.configure( - url=url, target_metadata=target_metadata, literal_binds=True - ) + context.configure(url=url, target_metadata=target_metadata, literal_binds=True) with context.begin_transaction(): context.run_migrations() @@ -66,15 +66,15 @@ def run_migrations_online(): # 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): + if getattr(config.cmd_opts, "autogenerate", False): script = directives[0] if script.upgrade_ops.is_empty(): directives[:] = [] - logger.info('No changes in schema detected.') + logger.info("No changes in schema detected.") connectable = engine_from_config( config.get_section(config.config_ini_section), - prefix='sqlalchemy.', + prefix="sqlalchemy.", poolclass=pool.NullPool, ) @@ -83,7 +83,7 @@ def run_migrations_online(): connection=connection, target_metadata=target_metadata, process_revision_directives=process_revision_directives, - **current_app.extensions['migrate'].configure_args + **current_app.extensions["migrate"].configure_args ) with context.begin_transaction(): diff --git a/migrations/versions/00daa8c472ba_.py b/migrations/versions/00daa8c472ba_.py index 52fa362..900bbac 100644 --- a/migrations/versions/00daa8c472ba_.py +++ b/migrations/versions/00daa8c472ba_.py @@ -12,31 +12,50 @@ from project import dbtypes # revision identifiers, used by Alembic. -revision = '00daa8c472ba' -down_revision = '50337ecd23db' +revision = "00daa8c472ba" +down_revision = "50337ecd23db" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - #op.drop_table('spatial_ref_sys') - op.drop_constraint('eventsuggestion_event_id_fkey', 'eventsuggestion', type_='foreignkey') - op.create_foreign_key(None, 'eventsuggestion', 'event', ['event_id'], ['id'], ondelete='SET NULL') + # op.drop_table('spatial_ref_sys') + op.drop_constraint( + "eventsuggestion_event_id_fkey", "eventsuggestion", type_="foreignkey" + ) + op.create_foreign_key( + None, "eventsuggestion", "event", ["event_id"], ["id"], ondelete="SET NULL" + ) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_constraint(None, 'eventsuggestion', type_='foreignkey') - op.create_foreign_key('eventsuggestion_event_id_fkey', 'eventsuggestion', 'event', ['event_id'], ['id']) - op.create_table('spatial_ref_sys', - sa.Column('srid', sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column('auth_name', sa.VARCHAR(length=256), autoincrement=False, nullable=True), - sa.Column('auth_srid', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('srtext', sa.VARCHAR(length=2048), autoincrement=False, nullable=True), - sa.Column('proj4text', sa.VARCHAR(length=2048), autoincrement=False, nullable=True), - sa.CheckConstraint('(srid > 0) AND (srid <= 998999)', name='spatial_ref_sys_srid_check'), - sa.PrimaryKeyConstraint('srid', name='spatial_ref_sys_pkey') + op.drop_constraint(None, "eventsuggestion", type_="foreignkey") + op.create_foreign_key( + "eventsuggestion_event_id_fkey", + "eventsuggestion", + "event", + ["event_id"], + ["id"], + ) + op.create_table( + "spatial_ref_sys", + sa.Column("srid", sa.INTEGER(), autoincrement=False, nullable=False), + sa.Column( + "auth_name", sa.VARCHAR(length=256), autoincrement=False, nullable=True + ), + sa.Column("auth_srid", sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column( + "srtext", sa.VARCHAR(length=2048), autoincrement=False, nullable=True + ), + sa.Column( + "proj4text", sa.VARCHAR(length=2048), autoincrement=False, nullable=True + ), + sa.CheckConstraint( + "(srid > 0) AND (srid <= 998999)", name="spatial_ref_sys_srid_check" + ), + sa.PrimaryKeyConstraint("srid", name="spatial_ref_sys_pkey"), ) # ### end Alembic commands ### diff --git a/migrations/versions/021f602d9965_.py b/migrations/versions/021f602d9965_.py index 9f7dcda..48bdae2 100644 --- a/migrations/versions/021f602d9965_.py +++ b/migrations/versions/021f602d9965_.py @@ -12,68 +12,117 @@ from project import dbtypes from project.models import EventRejectionReason, EventReviewStatus # revision identifiers, used by Alembic. -revision = '021f602d9965' -down_revision = '92f37474ad62' +revision = "021f602d9965" +down_revision = "92f37474ad62" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.create_table('eventsuggestion', - sa.Column('created_at', sa.DateTime(), nullable=True), - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('name', sa.Unicode(length=255), nullable=False), - sa.Column('start', sa.DateTime(timezone=True), nullable=False), - sa.Column('description', sa.UnicodeText(), nullable=True), - sa.Column('external_link', sa.String(length=255), nullable=True), - sa.Column('review_status', dbtypes.IntegerEnum(EventReviewStatus), nullable=True), - sa.Column('rejection_resaon', dbtypes.IntegerEnum(EventRejectionReason), nullable=True), - sa.Column('contact_name', sa.Unicode(length=255), nullable=False), - sa.Column('contact_email', sa.Unicode(length=255), nullable=True), - sa.Column('contact_phone', sa.Unicode(length=255), nullable=True), - sa.Column('admin_unit_id', sa.Integer(), nullable=False), - sa.Column('event_place_id', sa.Integer(), nullable=True), - sa.Column('event_place_text', sa.Unicode(length=255), nullable=True), - sa.Column('organizer_id', sa.Integer(), nullable=True), - sa.Column('organizer_text', sa.Unicode(length=255), nullable=True), - sa.Column('photo_id', sa.Integer(), nullable=True), - sa.Column('created_by_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['admin_unit_id'], ['adminunit.id'], ), - sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], ), - sa.ForeignKeyConstraint(['event_place_id'], ['eventplace.id'], ), - sa.ForeignKeyConstraint(['organizer_id'], ['eventorganizer.id'], ), - sa.ForeignKeyConstraint(['photo_id'], ['image.id'], ), - sa.PrimaryKeyConstraint('id') + op.create_table( + "eventsuggestion", + sa.Column("created_at", sa.DateTime(), nullable=True), + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("name", sa.Unicode(length=255), nullable=False), + sa.Column("start", sa.DateTime(timezone=True), nullable=False), + sa.Column("description", sa.UnicodeText(), nullable=True), + sa.Column("external_link", sa.String(length=255), nullable=True), + sa.Column( + "review_status", dbtypes.IntegerEnum(EventReviewStatus), nullable=True + ), + sa.Column( + "rejection_resaon", dbtypes.IntegerEnum(EventRejectionReason), nullable=True + ), + sa.Column("contact_name", sa.Unicode(length=255), nullable=False), + sa.Column("contact_email", sa.Unicode(length=255), nullable=True), + sa.Column("contact_phone", sa.Unicode(length=255), nullable=True), + sa.Column("admin_unit_id", sa.Integer(), nullable=False), + sa.Column("event_place_id", sa.Integer(), nullable=True), + sa.Column("event_place_text", sa.Unicode(length=255), nullable=True), + sa.Column("organizer_id", sa.Integer(), nullable=True), + sa.Column("organizer_text", sa.Unicode(length=255), nullable=True), + sa.Column("photo_id", sa.Integer(), nullable=True), + sa.Column("created_by_id", sa.Integer(), nullable=True), + sa.ForeignKeyConstraint( + ["admin_unit_id"], + ["adminunit.id"], + ), + sa.ForeignKeyConstraint( + ["created_by_id"], + ["user.id"], + ), + sa.ForeignKeyConstraint( + ["event_place_id"], + ["eventplace.id"], + ), + sa.ForeignKeyConstraint( + ["organizer_id"], + ["eventorganizer.id"], + ), + sa.ForeignKeyConstraint( + ["photo_id"], + ["image.id"], + ), + sa.PrimaryKeyConstraint("id"), ) - #op.drop_table('spatial_ref_sys') - op.drop_constraint('event_contact_id_fkey', 'event', type_='foreignkey') - op.drop_column('event', 'review_status') - op.drop_column('event', 'rejection_resaon') - op.drop_column('event', 'contact_id') - op.drop_column('eventcontact', 'email') - op.drop_column('eventcontact', 'name') - op.drop_column('eventcontact', 'phone') + # op.drop_table('spatial_ref_sys') + op.drop_constraint("event_contact_id_fkey", "event", type_="foreignkey") + op.drop_column("event", "review_status") + op.drop_column("event", "rejection_resaon") + op.drop_column("event", "contact_id") + op.drop_column("eventcontact", "email") + op.drop_column("eventcontact", "name") + op.drop_column("eventcontact", "phone") # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.add_column('eventcontact', sa.Column('phone', sa.VARCHAR(length=255), autoincrement=False, nullable=True)) - op.add_column('eventcontact', sa.Column('name', sa.VARCHAR(length=255), autoincrement=False, nullable=False)) - op.add_column('eventcontact', sa.Column('email', sa.VARCHAR(length=255), autoincrement=False, nullable=True)) - op.add_column('event', sa.Column('contact_id', sa.INTEGER(), autoincrement=False, nullable=True)) - op.add_column('event', sa.Column('rejection_resaon', sa.INTEGER(), autoincrement=False, nullable=True)) - op.add_column('event', sa.Column('review_status', sa.INTEGER(), autoincrement=False, nullable=True)) - op.create_foreign_key('event_contact_id_fkey', 'event', 'eventcontact', ['contact_id'], ['id']) - op.create_table('spatial_ref_sys', - sa.Column('srid', sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column('auth_name', sa.VARCHAR(length=256), autoincrement=False, nullable=True), - sa.Column('auth_srid', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('srtext', sa.VARCHAR(length=2048), autoincrement=False, nullable=True), - sa.Column('proj4text', sa.VARCHAR(length=2048), autoincrement=False, nullable=True), - sa.CheckConstraint('(srid > 0) AND (srid <= 998999)', name='spatial_ref_sys_srid_check'), - sa.PrimaryKeyConstraint('srid', name='spatial_ref_sys_pkey') + op.add_column( + "eventcontact", + sa.Column("phone", sa.VARCHAR(length=255), autoincrement=False, nullable=True), ) - op.drop_table('eventsuggestion') + op.add_column( + "eventcontact", + sa.Column("name", sa.VARCHAR(length=255), autoincrement=False, nullable=False), + ) + op.add_column( + "eventcontact", + sa.Column("email", sa.VARCHAR(length=255), autoincrement=False, nullable=True), + ) + op.add_column( + "event", + sa.Column("contact_id", sa.INTEGER(), autoincrement=False, nullable=True), + ) + op.add_column( + "event", + sa.Column("rejection_resaon", sa.INTEGER(), autoincrement=False, nullable=True), + ) + op.add_column( + "event", + sa.Column("review_status", sa.INTEGER(), autoincrement=False, nullable=True), + ) + op.create_foreign_key( + "event_contact_id_fkey", "event", "eventcontact", ["contact_id"], ["id"] + ) + op.create_table( + "spatial_ref_sys", + sa.Column("srid", sa.INTEGER(), autoincrement=False, nullable=False), + sa.Column( + "auth_name", sa.VARCHAR(length=256), autoincrement=False, nullable=True + ), + sa.Column("auth_srid", sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column( + "srtext", sa.VARCHAR(length=2048), autoincrement=False, nullable=True + ), + sa.Column( + "proj4text", sa.VARCHAR(length=2048), autoincrement=False, nullable=True + ), + sa.CheckConstraint( + "(srid > 0) AND (srid <= 998999)", name="spatial_ref_sys_srid_check" + ), + sa.PrimaryKeyConstraint("srid", name="spatial_ref_sys_pkey"), + ) + op.drop_table("eventsuggestion") # ### end Alembic commands ### diff --git a/migrations/versions/091deace5f08_.py b/migrations/versions/091deace5f08_.py index c25ec91..3eee5eb 100644 --- a/migrations/versions/091deace5f08_.py +++ b/migrations/versions/091deace5f08_.py @@ -8,14 +8,12 @@ Create Date: 2020-10-02 09:29:12.932229 from alembic import op import sqlalchemy as sa from sqlalchemy.sql import text -import sqlalchemy_utils -from project import dbtypes from geoalchemy2.types import Geometry # revision identifiers, used by Alembic. -revision = '091deace5f08' -down_revision = '6b7016f73688' +revision = "091deace5f08" +down_revision = "6b7016f73688" branch_labels = None depends_on = None @@ -26,21 +24,39 @@ def upgrade(): bind.execute(text("create extension if not exists postgis;")) # ### commands auto generated by Alembic - please adjust! ### - #op.drop_table('spatial_ref_sys') - op.add_column('location', sa.Column('coordinate', Geometry(geometry_type='POINT', from_text='ST_GeomFromEWKT', name='geometry'), nullable=True)) + # op.drop_table('spatial_ref_sys') + op.add_column( + "location", + sa.Column( + "coordinate", + Geometry( + geometry_type="POINT", from_text="ST_GeomFromEWKT", name="geometry" + ), + nullable=True, + ), + ) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_column('location', 'coordinate') - op.create_table('spatial_ref_sys', - sa.Column('srid', sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column('auth_name', sa.VARCHAR(length=256), autoincrement=False, nullable=True), - sa.Column('auth_srid', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('srtext', sa.VARCHAR(length=2048), autoincrement=False, nullable=True), - sa.Column('proj4text', sa.VARCHAR(length=2048), autoincrement=False, nullable=True), - sa.CheckConstraint('(srid > 0) AND (srid <= 998999)', name='spatial_ref_sys_srid_check'), - sa.PrimaryKeyConstraint('srid', name='spatial_ref_sys_pkey') + op.drop_column("location", "coordinate") + op.create_table( + "spatial_ref_sys", + sa.Column("srid", sa.INTEGER(), autoincrement=False, nullable=False), + sa.Column( + "auth_name", sa.VARCHAR(length=256), autoincrement=False, nullable=True + ), + sa.Column("auth_srid", sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column( + "srtext", sa.VARCHAR(length=2048), autoincrement=False, nullable=True + ), + sa.Column( + "proj4text", sa.VARCHAR(length=2048), autoincrement=False, nullable=True + ), + sa.CheckConstraint( + "(srid > 0) AND (srid <= 998999)", name="spatial_ref_sys_srid_check" + ), + sa.PrimaryKeyConstraint("srid", name="spatial_ref_sys_pkey"), ) # ### end Alembic commands ### diff --git a/migrations/versions/0a282a331e35_.py b/migrations/versions/0a282a331e35_.py index 5bbf539..0b05fb9 100644 --- a/migrations/versions/0a282a331e35_.py +++ b/migrations/versions/0a282a331e35_.py @@ -12,35 +12,48 @@ from project import dbtypes # revision identifiers, used by Alembic. -revision = '0a282a331e35' -down_revision = 'da63ba1d58b1' +revision = "0a282a331e35" +down_revision = "da63ba1d58b1" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - #op.drop_table('spatial_ref_sys') - op.add_column('event', sa.Column('booked_up', sa.Boolean(), nullable=True)) - op.add_column('event', sa.Column('expected_participants', sa.Integer(), nullable=True)) - op.add_column('event', sa.Column('price_info', sa.UnicodeText(), nullable=True)) - op.add_column('event', sa.Column('registration_required', sa.Boolean(), nullable=True)) + # op.drop_table('spatial_ref_sys') + op.add_column("event", sa.Column("booked_up", sa.Boolean(), nullable=True)) + op.add_column( + "event", sa.Column("expected_participants", sa.Integer(), nullable=True) + ) + op.add_column("event", sa.Column("price_info", sa.UnicodeText(), nullable=True)) + op.add_column( + "event", sa.Column("registration_required", sa.Boolean(), nullable=True) + ) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_column('event', 'registration_required') - op.drop_column('event', 'price_info') - op.drop_column('event', 'expected_participants') - op.drop_column('event', 'booked_up') - op.create_table('spatial_ref_sys', - sa.Column('srid', sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column('auth_name', sa.VARCHAR(length=256), autoincrement=False, nullable=True), - sa.Column('auth_srid', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('srtext', sa.VARCHAR(length=2048), autoincrement=False, nullable=True), - sa.Column('proj4text', sa.VARCHAR(length=2048), autoincrement=False, nullable=True), - sa.CheckConstraint('(srid > 0) AND (srid <= 998999)', name='spatial_ref_sys_srid_check'), - sa.PrimaryKeyConstraint('srid', name='spatial_ref_sys_pkey') + op.drop_column("event", "registration_required") + op.drop_column("event", "price_info") + op.drop_column("event", "expected_participants") + op.drop_column("event", "booked_up") + op.create_table( + "spatial_ref_sys", + sa.Column("srid", sa.INTEGER(), autoincrement=False, nullable=False), + sa.Column( + "auth_name", sa.VARCHAR(length=256), autoincrement=False, nullable=True + ), + sa.Column("auth_srid", sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column( + "srtext", sa.VARCHAR(length=2048), autoincrement=False, nullable=True + ), + sa.Column( + "proj4text", sa.VARCHAR(length=2048), autoincrement=False, nullable=True + ), + sa.CheckConstraint( + "(srid > 0) AND (srid <= 998999)", name="spatial_ref_sys_srid_check" + ), + sa.PrimaryKeyConstraint("srid", name="spatial_ref_sys_pkey"), ) # ### end Alembic commands ### diff --git a/migrations/versions/27da3ceea723_.py b/migrations/versions/27da3ceea723_.py index f0759f6..4428dfd 100644 --- a/migrations/versions/27da3ceea723_.py +++ b/migrations/versions/27da3ceea723_.py @@ -8,39 +8,70 @@ Create Date: 2020-11-08 16:14:01.866196 from alembic import op import sqlalchemy as sa import sqlalchemy_utils -from project import dbtypes # revision identifiers, used by Alembic. -revision = '27da3ceea723' -down_revision = '00daa8c472ba' +revision = "27da3ceea723" +down_revision = "00daa8c472ba" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - #op.drop_table('spatial_ref_sys') - op.add_column('adminunit', sa.Column('widget_background_color', sqlalchemy_utils.types.color.ColorType(length=20), nullable=True)) - op.add_column('adminunit', sa.Column('widget_font', sa.Unicode(length=255), nullable=True)) - op.add_column('adminunit', sa.Column('widget_link_color', sqlalchemy_utils.types.color.ColorType(length=20), nullable=True)) - op.add_column('adminunit', sa.Column('widget_primary_color', sqlalchemy_utils.types.color.ColorType(length=20), nullable=True)) + # op.drop_table('spatial_ref_sys') + op.add_column( + "adminunit", + sa.Column( + "widget_background_color", + sqlalchemy_utils.types.color.ColorType(length=20), + nullable=True, + ), + ) + op.add_column( + "adminunit", sa.Column("widget_font", sa.Unicode(length=255), nullable=True) + ) + op.add_column( + "adminunit", + sa.Column( + "widget_link_color", + sqlalchemy_utils.types.color.ColorType(length=20), + nullable=True, + ), + ) + op.add_column( + "adminunit", + sa.Column( + "widget_primary_color", + sqlalchemy_utils.types.color.ColorType(length=20), + nullable=True, + ), + ) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_column('adminunit', 'widget_primary_color') - op.drop_column('adminunit', 'widget_link_color') - op.drop_column('adminunit', 'widget_font') - op.drop_column('adminunit', 'widget_background_color') - op.create_table('spatial_ref_sys', - sa.Column('srid', sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column('auth_name', sa.VARCHAR(length=256), autoincrement=False, nullable=True), - sa.Column('auth_srid', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('srtext', sa.VARCHAR(length=2048), autoincrement=False, nullable=True), - sa.Column('proj4text', sa.VARCHAR(length=2048), autoincrement=False, nullable=True), - sa.CheckConstraint('(srid > 0) AND (srid <= 998999)', name='spatial_ref_sys_srid_check'), - sa.PrimaryKeyConstraint('srid', name='spatial_ref_sys_pkey') + op.drop_column("adminunit", "widget_primary_color") + op.drop_column("adminunit", "widget_link_color") + op.drop_column("adminunit", "widget_font") + op.drop_column("adminunit", "widget_background_color") + op.create_table( + "spatial_ref_sys", + sa.Column("srid", sa.INTEGER(), autoincrement=False, nullable=False), + sa.Column( + "auth_name", sa.VARCHAR(length=256), autoincrement=False, nullable=True + ), + sa.Column("auth_srid", sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column( + "srtext", sa.VARCHAR(length=2048), autoincrement=False, nullable=True + ), + sa.Column( + "proj4text", sa.VARCHAR(length=2048), autoincrement=False, nullable=True + ), + sa.CheckConstraint( + "(srid > 0) AND (srid <= 998999)", name="spatial_ref_sys_srid_check" + ), + sa.PrimaryKeyConstraint("srid", name="spatial_ref_sys_pkey"), ) # ### end Alembic commands ### diff --git a/migrations/versions/3c5b34fd1156_.py b/migrations/versions/3c5b34fd1156_.py index 2212281..354a191 100644 --- a/migrations/versions/3c5b34fd1156_.py +++ b/migrations/versions/3c5b34fd1156_.py @@ -13,49 +13,65 @@ from project import dbtypes from sqlalchemy.ext.declarative import declarative_base # revision identifiers, used by Alembic. -revision = '3c5b34fd1156' -down_revision = '27da3ceea723' +revision = "3c5b34fd1156" +down_revision = "27da3ceea723" branch_labels = None depends_on = None Base = declarative_base() + class Event(Base): - __tablename__ = 'event' + __tablename__ = "event" id = sa.Column(sa.Integer(), primary_key=True) - category_id = sa.Column(sa.Integer, sa.ForeignKey('eventcategory.id'), nullable=False) - category = orm.relationship('EventCategory', uselist=False) - categories = orm.relationship('EventCategory', secondary='event_eventcategories') + category_id = sa.Column( + sa.Integer, sa.ForeignKey("eventcategory.id"), nullable=False + ) + category = orm.relationship("EventCategory", uselist=False) + categories = orm.relationship("EventCategory", secondary="event_eventcategories") + class EventEventCategories(Base): - __tablename__ = 'event_eventcategories' + __tablename__ = "event_eventcategories" id = sa.Column(sa.Integer(), primary_key=True) - event_id = sa.Column(sa.Integer, sa.ForeignKey('event.id'), nullable=False) - category_id = sa.Column(sa.Integer, sa.ForeignKey('eventcategory.id'), nullable=False) + event_id = sa.Column(sa.Integer, sa.ForeignKey("event.id"), nullable=False) + category_id = sa.Column( + sa.Integer, sa.ForeignKey("eventcategory.id"), nullable=False + ) + class EventCategory(Base): - __tablename__ = 'eventcategory' + __tablename__ = "eventcategory" id = sa.Column(sa.Integer(), primary_key=True) name = sa.Column(sa.Unicode(255), nullable=False, unique=True) + def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.create_table('event_eventcategories', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('event_id', sa.Integer(), nullable=False), - sa.Column('category_id', sa.Integer(), nullable=False), - sa.ForeignKeyConstraint(['category_id'], ['eventcategory.id'], ), - sa.ForeignKeyConstraint(['event_id'], ['event.id'], ), - sa.PrimaryKeyConstraint('id') + op.create_table( + "event_eventcategories", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("event_id", sa.Integer(), nullable=False), + sa.Column("category_id", sa.Integer(), nullable=False), + sa.ForeignKeyConstraint( + ["category_id"], + ["eventcategory.id"], + ), + sa.ForeignKeyConstraint( + ["event_id"], + ["event.id"], + ), + sa.PrimaryKeyConstraint("id"), ) migrate_category_to_categories() - #op.drop_table('spatial_ref_sys') - op.drop_constraint('event_category_id_fkey', 'event', type_='foreignkey') - op.drop_column('event', 'category_id') + # op.drop_table('spatial_ref_sys') + op.drop_constraint("event_category_id_fkey", "event", type_="foreignkey") + op.drop_column("event", "category_id") # ### end Alembic commands ### + def migrate_category_to_categories(): bind = op.get_bind() session = orm.Session(bind=bind) @@ -65,18 +81,33 @@ def migrate_category_to_categories(): session.commit() + def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.add_column('event', sa.Column('category_id', sa.INTEGER(), autoincrement=False, nullable=False)) - op.create_foreign_key('event_category_id_fkey', 'event', 'eventcategory', ['category_id'], ['id']) - op.create_table('spatial_ref_sys', - sa.Column('srid', sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column('auth_name', sa.VARCHAR(length=256), autoincrement=False, nullable=True), - sa.Column('auth_srid', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('srtext', sa.VARCHAR(length=2048), autoincrement=False, nullable=True), - sa.Column('proj4text', sa.VARCHAR(length=2048), autoincrement=False, nullable=True), - sa.CheckConstraint('(srid > 0) AND (srid <= 998999)', name='spatial_ref_sys_srid_check'), - sa.PrimaryKeyConstraint('srid', name='spatial_ref_sys_pkey') + op.add_column( + "event", + sa.Column("category_id", sa.INTEGER(), autoincrement=False, nullable=False), ) - op.drop_table('event_eventcategories') + op.create_foreign_key( + "event_category_id_fkey", "event", "eventcategory", ["category_id"], ["id"] + ) + op.create_table( + "spatial_ref_sys", + sa.Column("srid", sa.INTEGER(), autoincrement=False, nullable=False), + sa.Column( + "auth_name", sa.VARCHAR(length=256), autoincrement=False, nullable=True + ), + sa.Column("auth_srid", sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column( + "srtext", sa.VARCHAR(length=2048), autoincrement=False, nullable=True + ), + sa.Column( + "proj4text", sa.VARCHAR(length=2048), autoincrement=False, nullable=True + ), + sa.CheckConstraint( + "(srid > 0) AND (srid <= 998999)", name="spatial_ref_sys_srid_check" + ), + sa.PrimaryKeyConstraint("srid", name="spatial_ref_sys_pkey"), + ) + op.drop_table("event_eventcategories") # ### end Alembic commands ### diff --git a/migrations/versions/41512b20e07c_.py b/migrations/versions/41512b20e07c_.py index 6b14dbb..3e7ecd4 100644 --- a/migrations/versions/41512b20e07c_.py +++ b/migrations/versions/41512b20e07c_.py @@ -12,21 +12,23 @@ from project import dbtypes # revision identifiers, used by Alembic. -revision = '41512b20e07c' -down_revision = 'fd7794ece0b3' +revision = "41512b20e07c" +down_revision = "fd7794ece0b3" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_constraint('event_event_place_id_fkey', 'event', type_='foreignkey') - op.create_foreign_key(None, 'event', 'eventplace', ['event_place_id'], ['id']) + op.drop_constraint("event_event_place_id_fkey", "event", type_="foreignkey") + op.create_foreign_key(None, "event", "eventplace", ["event_place_id"], ["id"]) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_constraint(None, 'event', type_='foreignkey') - op.create_foreign_key('event_event_place_id_fkey', 'event', 'place', ['event_place_id'], ['id']) + op.drop_constraint(None, "event", type_="foreignkey") + op.create_foreign_key( + "event_event_place_id_fkey", "event", "place", ["event_place_id"], ["id"] + ) # ### end Alembic commands ### diff --git a/migrations/versions/4e913af88c33_.py b/migrations/versions/4e913af88c33_.py index d5d60f5..df4dea5 100644 --- a/migrations/versions/4e913af88c33_.py +++ b/migrations/versions/4e913af88c33_.py @@ -12,25 +12,26 @@ from project import dbtypes # revision identifiers, used by Alembic. -revision = '4e913af88c33' -down_revision = '67216b6cf293' +revision = "4e913af88c33" +down_revision = "67216b6cf293" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.create_table('analytics', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('key', sa.Unicode(length=255), nullable=True), - sa.Column('value', sa.UnicodeText(), nullable=True), - sa.Column('created_at', sa.DateTime(), nullable=True), - sa.PrimaryKeyConstraint('id') + op.create_table( + "analytics", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("key", sa.Unicode(length=255), nullable=True), + sa.Column("value", sa.UnicodeText(), nullable=True), + sa.Column("created_at", sa.DateTime(), nullable=True), + sa.PrimaryKeyConstraint("id"), ) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_table('analytics') + op.drop_table("analytics") # ### end Alembic commands ### diff --git a/migrations/versions/50337ecd23db_.py b/migrations/versions/50337ecd23db_.py index ee914a8..f7879ca 100644 --- a/migrations/versions/50337ecd23db_.py +++ b/migrations/versions/50337ecd23db_.py @@ -12,31 +12,40 @@ from project import dbtypes # revision identifiers, used by Alembic. -revision = '50337ecd23db' -down_revision = '6be822396123' +revision = "50337ecd23db" +down_revision = "6be822396123" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - #op.drop_table('spatial_ref_sys') - op.add_column('eventsuggestion', sa.Column('event_id', sa.Integer(), nullable=True)) - op.create_foreign_key(None, 'eventsuggestion', 'event', ['event_id'], ['id']) + # op.drop_table('spatial_ref_sys') + op.add_column("eventsuggestion", sa.Column("event_id", sa.Integer(), nullable=True)) + op.create_foreign_key(None, "eventsuggestion", "event", ["event_id"], ["id"]) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_constraint(None, 'eventsuggestion', type_='foreignkey') - op.drop_column('eventsuggestion', 'event_id') - op.create_table('spatial_ref_sys', - sa.Column('srid', sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column('auth_name', sa.VARCHAR(length=256), autoincrement=False, nullable=True), - sa.Column('auth_srid', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('srtext', sa.VARCHAR(length=2048), autoincrement=False, nullable=True), - sa.Column('proj4text', sa.VARCHAR(length=2048), autoincrement=False, nullable=True), - sa.CheckConstraint('(srid > 0) AND (srid <= 998999)', name='spatial_ref_sys_srid_check'), - sa.PrimaryKeyConstraint('srid', name='spatial_ref_sys_pkey') + op.drop_constraint(None, "eventsuggestion", type_="foreignkey") + op.drop_column("eventsuggestion", "event_id") + op.create_table( + "spatial_ref_sys", + sa.Column("srid", sa.INTEGER(), autoincrement=False, nullable=False), + sa.Column( + "auth_name", sa.VARCHAR(length=256), autoincrement=False, nullable=True + ), + sa.Column("auth_srid", sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column( + "srtext", sa.VARCHAR(length=2048), autoincrement=False, nullable=True + ), + sa.Column( + "proj4text", sa.VARCHAR(length=2048), autoincrement=False, nullable=True + ), + sa.CheckConstraint( + "(srid > 0) AND (srid <= 998999)", name="spatial_ref_sys_srid_check" + ), + sa.PrimaryKeyConstraint("srid", name="spatial_ref_sys_pkey"), ) # ### end Alembic commands ### diff --git a/migrations/versions/51c47c7f0bdb_.py b/migrations/versions/51c47c7f0bdb_.py index 6ffbcb4..326a588 100644 --- a/migrations/versions/51c47c7f0bdb_.py +++ b/migrations/versions/51c47c7f0bdb_.py @@ -7,26 +7,26 @@ Create Date: 2020-09-29 15:38:44.033998 """ from alembic import op import sqlalchemy as sa -import sqlalchemy_utils -from project import dbtypes # revision identifiers, used by Alembic. -revision = '51c47c7f0bdb' -down_revision = '7afc40e11791' +revision = "51c47c7f0bdb" +down_revision = "7afc40e11791" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.add_column('featuredevent', sa.Column('admin_unit_id', sa.Integer(), nullable=False)) - op.create_foreign_key(None, 'featuredevent', 'adminunit', ['admin_unit_id'], ['id']) + op.add_column( + "featuredevent", sa.Column("admin_unit_id", sa.Integer(), nullable=False) + ) + op.create_foreign_key(None, "featuredevent", "adminunit", ["admin_unit_id"], ["id"]) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_constraint(None, 'featuredevent', type_='foreignkey') - op.drop_column('featuredevent', 'admin_unit_id') + op.drop_constraint(None, "featuredevent", type_="foreignkey") + op.drop_column("featuredevent", "admin_unit_id") # ### end Alembic commands ### diff --git a/migrations/versions/5c8457f2eac1_.py b/migrations/versions/5c8457f2eac1_.py index e1a75bf..ef5b2f7 100644 --- a/migrations/versions/5c8457f2eac1_.py +++ b/migrations/versions/5c8457f2eac1_.py @@ -7,26 +7,26 @@ Create Date: 2020-07-13 19:01:04.770613 """ from alembic import op import sqlalchemy as sa -import sqlalchemy_utils -from project import dbtypes # revision identifiers, used by Alembic. -revision = '5c8457f2eac1' -down_revision = 'ed6bb2084bbd' +revision = "5c8457f2eac1" +down_revision = "ed6bb2084bbd" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.add_column('event', sa.Column('end', sa.DateTime(timezone=True), nullable=True)) - op.add_column('event', sa.Column('start', sa.DateTime(timezone=True), nullable=True)) + op.add_column("event", sa.Column("end", sa.DateTime(timezone=True), nullable=True)) + op.add_column( + "event", sa.Column("start", sa.DateTime(timezone=True), nullable=True) + ) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_column('event', 'start') - op.drop_column('event', 'end') + op.drop_column("event", "start") + op.drop_column("event", "end") # ### end Alembic commands ### diff --git a/migrations/versions/62e071b0da50_.py b/migrations/versions/62e071b0da50_.py index e3b7879..e447b1c 100644 --- a/migrations/versions/62e071b0da50_.py +++ b/migrations/versions/62e071b0da50_.py @@ -12,29 +12,36 @@ from project import dbtypes # revision identifiers, used by Alembic. -revision = '62e071b0da50' -down_revision = 'dcd0b71650b0' +revision = "62e071b0da50" +down_revision = "dcd0b71650b0" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.alter_column('eventorganizer', 'name', - existing_type=sa.VARCHAR(length=255), - nullable=False) - op.create_unique_constraint(None, 'eventorganizer', ['name', 'admin_unit_id']) - op.drop_column('eventorganizer', 'org_name') - op.create_unique_constraint(None, 'eventplace', ['name', 'organizer_id', 'admin_unit_id']) + op.alter_column( + "eventorganizer", "name", existing_type=sa.VARCHAR(length=255), nullable=False + ) + op.create_unique_constraint(None, "eventorganizer", ["name", "admin_unit_id"]) + op.drop_column("eventorganizer", "org_name") + op.create_unique_constraint( + None, "eventplace", ["name", "organizer_id", "admin_unit_id"] + ) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_constraint(None, 'eventplace', type_='unique') - op.add_column('eventorganizer', sa.Column('org_name', sa.VARCHAR(length=255), autoincrement=False, nullable=True)) - op.drop_constraint(None, 'eventorganizer', type_='unique') - op.alter_column('eventorganizer', 'name', - existing_type=sa.VARCHAR(length=255), - nullable=True) + op.drop_constraint(None, "eventplace", type_="unique") + op.add_column( + "eventorganizer", + sa.Column( + "org_name", sa.VARCHAR(length=255), autoincrement=False, nullable=True + ), + ) + op.drop_constraint(None, "eventorganizer", type_="unique") + op.alter_column( + "eventorganizer", "name", existing_type=sa.VARCHAR(length=255), nullable=True + ) # ### end Alembic commands ### diff --git a/migrations/versions/67216b6cf293_.py b/migrations/versions/67216b6cf293_.py index 19c0138..fbb69d1 100644 --- a/migrations/versions/67216b6cf293_.py +++ b/migrations/versions/67216b6cf293_.py @@ -7,29 +7,40 @@ Create Date: 2020-08-01 15:43:11.377833 """ from alembic import op import sqlalchemy as sa -import sqlalchemy_utils from project import dbtypes from project.models import EventRejectionReason, EventReviewStatus # revision identifiers, used by Alembic. -revision = '67216b6cf293' -down_revision = 'a336ac384c64' +revision = "67216b6cf293" +down_revision = "a336ac384c64" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.add_column('event', sa.Column('rejection_resaon', dbtypes.IntegerEnum(EventRejectionReason), nullable=True)) - op.add_column('event', sa.Column('review_status', dbtypes.IntegerEnum(EventReviewStatus), nullable=True)) - op.drop_column('event', 'verified') + op.add_column( + "event", + sa.Column( + "rejection_resaon", dbtypes.IntegerEnum(EventRejectionReason), nullable=True + ), + ) + op.add_column( + "event", + sa.Column( + "review_status", dbtypes.IntegerEnum(EventReviewStatus), nullable=True + ), + ) + op.drop_column("event", "verified") # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.add_column('event', sa.Column('verified', sa.BOOLEAN(), autoincrement=False, nullable=True)) - op.drop_column('event', 'review_status') - op.drop_column('event', 'rejection_resaon') + op.add_column( + "event", sa.Column("verified", sa.BOOLEAN(), autoincrement=False, nullable=True) + ) + op.drop_column("event", "review_status") + op.drop_column("event", "rejection_resaon") # ### end Alembic commands ### diff --git a/migrations/versions/699c4f6a7fe8_.py b/migrations/versions/699c4f6a7fe8_.py index 5637a68..b75cde8 100644 --- a/migrations/versions/699c4f6a7fe8_.py +++ b/migrations/versions/699c4f6a7fe8_.py @@ -12,31 +12,37 @@ from project import dbtypes # revision identifiers, used by Alembic. -revision = '699c4f6a7fe8' -down_revision = 'b1c05324cc13' +revision = "699c4f6a7fe8" +down_revision = "b1c05324cc13" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.add_column('eventorganizer', sa.Column('admin_unit_id', sa.Integer(), nullable=True)) - op.create_foreign_key(None, 'eventorganizer', 'adminunit', ['admin_unit_id'], ['id']) - op.add_column('eventplace', sa.Column('admin_unit_id', sa.Integer(), nullable=True)) - op.add_column('eventplace', sa.Column('organizer_id', sa.Integer(), nullable=True)) - op.add_column('eventplace', sa.Column('public', sa.Boolean(), nullable=True)) - op.create_foreign_key(None, 'eventplace', 'eventorganizer', ['organizer_id'], ['id']) - op.create_foreign_key(None, 'eventplace', 'adminunit', ['admin_unit_id'], ['id']) + op.add_column( + "eventorganizer", sa.Column("admin_unit_id", sa.Integer(), nullable=True) + ) + op.create_foreign_key( + None, "eventorganizer", "adminunit", ["admin_unit_id"], ["id"] + ) + op.add_column("eventplace", sa.Column("admin_unit_id", sa.Integer(), nullable=True)) + op.add_column("eventplace", sa.Column("organizer_id", sa.Integer(), nullable=True)) + op.add_column("eventplace", sa.Column("public", sa.Boolean(), nullable=True)) + op.create_foreign_key( + None, "eventplace", "eventorganizer", ["organizer_id"], ["id"] + ) + op.create_foreign_key(None, "eventplace", "adminunit", ["admin_unit_id"], ["id"]) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_constraint(None, 'eventplace', type_='foreignkey') - op.drop_constraint(None, 'eventplace', type_='foreignkey') - op.drop_column('eventplace', 'public') - op.drop_column('eventplace', 'organizer_id') - op.drop_column('eventplace', 'admin_unit_id') - op.drop_constraint(None, 'eventorganizer', type_='foreignkey') - op.drop_column('eventorganizer', 'admin_unit_id') + op.drop_constraint(None, "eventplace", type_="foreignkey") + op.drop_constraint(None, "eventplace", type_="foreignkey") + op.drop_column("eventplace", "public") + op.drop_column("eventplace", "organizer_id") + op.drop_column("eventplace", "admin_unit_id") + op.drop_constraint(None, "eventorganizer", type_="foreignkey") + op.drop_column("eventorganizer", "admin_unit_id") # ### end Alembic commands ### diff --git a/migrations/versions/6b7016f73688_.py b/migrations/versions/6b7016f73688_.py index dc469a6..d56fb86 100644 --- a/migrations/versions/6b7016f73688_.py +++ b/migrations/versions/6b7016f73688_.py @@ -12,169 +12,321 @@ from project import dbtypes from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. -revision = '6b7016f73688' -down_revision = 'a75bd9c8ad3a' +revision = "6b7016f73688" +down_revision = "a75bd9c8ad3a" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_constraint('event_place_id_fkey', 'event', type_='foreignkey') - op.drop_constraint('event_host_id_fkey', 'event', type_='foreignkey') - op.drop_column('event', 'host_id') - op.drop_column('event', 'place_id') - op.drop_table('eventsuggestiondate') - op.drop_table('place') - op.drop_table('org_or_adminunit') - op.drop_table('actor') - op.drop_table('adminunitorgroles_organizations') - op.drop_table('adminunitorgrole') - op.drop_table('adminunitorg') - op.drop_table('orgmemberroles_members') - op.drop_table('orgmember') - op.drop_table('organization') - op.drop_table('eventsuggestion') - op.drop_table('orgmemberrole') + op.drop_constraint("event_place_id_fkey", "event", type_="foreignkey") + op.drop_constraint("event_host_id_fkey", "event", type_="foreignkey") + op.drop_column("event", "host_id") + op.drop_column("event", "place_id") + op.drop_table("eventsuggestiondate") + op.drop_table("place") + op.drop_table("org_or_adminunit") + op.drop_table("actor") + op.drop_table("adminunitorgroles_organizations") + op.drop_table("adminunitorgrole") + op.drop_table("adminunitorg") + op.drop_table("orgmemberroles_members") + op.drop_table("orgmember") + op.drop_table("organization") + op.drop_table("eventsuggestion") + op.drop_table("orgmemberrole") # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.add_column('event', sa.Column('place_id', sa.INTEGER(), autoincrement=False, nullable=True)) - op.add_column('event', sa.Column('host_id', sa.INTEGER(), autoincrement=False, nullable=True)) - op.create_foreign_key('event_host_id_fkey', 'event', 'org_or_adminunit', ['host_id'], ['id']) - op.create_foreign_key('event_place_id_fkey', 'event', 'place', ['place_id'], ['id']) - op.create_table('orgmemberroles_members', - sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column('member_id', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('role_id', sa.INTEGER(), autoincrement=False, nullable=True), - sa.ForeignKeyConstraint(['member_id'], ['orgmember.id'], name='orgmemberroles_members_member_id_fkey'), - sa.ForeignKeyConstraint(['role_id'], ['orgmemberrole.id'], name='orgmemberroles_members_role_id_fkey'), - sa.PrimaryKeyConstraint('id', name='orgmemberroles_members_pkey') + op.add_column( + "event", sa.Column("place_id", sa.INTEGER(), autoincrement=False, nullable=True) ) - op.create_table('orgmemberrole', - sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column('name', sa.VARCHAR(length=80), autoincrement=False, nullable=True), - sa.Column('description', sa.VARCHAR(length=255), autoincrement=False, nullable=True), - sa.Column('permissions', sa.TEXT(), autoincrement=False, nullable=True), - sa.PrimaryKeyConstraint('id', name='orgmemberrole_pkey'), - sa.UniqueConstraint('name', name='orgmemberrole_name_key') + op.add_column( + "event", sa.Column("host_id", sa.INTEGER(), autoincrement=False, nullable=True) ) - op.create_table('eventsuggestion', - sa.Column('created_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True), - sa.Column('id', sa.INTEGER(), server_default=sa.text("nextval('eventsuggestion_id_seq'::regclass)"), autoincrement=True, nullable=False), - sa.Column('admin_unit_id', sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column('host_name', sa.VARCHAR(length=255), autoincrement=False, nullable=False), - sa.Column('event_name', sa.VARCHAR(length=255), autoincrement=False, nullable=False), - sa.Column('description', sa.TEXT(), autoincrement=False, nullable=False), - sa.Column('place_name', sa.VARCHAR(length=255), autoincrement=False, nullable=False), - sa.Column('place_street', sa.VARCHAR(length=255), autoincrement=False, nullable=True), - sa.Column('place_postalCode', sa.VARCHAR(length=255), autoincrement=False, nullable=False), - sa.Column('place_city', sa.VARCHAR(length=255), autoincrement=False, nullable=False), - sa.Column('contact_name', sa.VARCHAR(length=255), autoincrement=False, nullable=False), - sa.Column('contact_email', sa.VARCHAR(length=255), autoincrement=False, nullable=False), - sa.Column('external_link', sa.VARCHAR(length=255), autoincrement=False, nullable=True), - sa.Column('created_by_id', sa.INTEGER(), autoincrement=False, nullable=True), - sa.ForeignKeyConstraint(['admin_unit_id'], ['adminunit.id'], name='eventsuggestion_admin_unit_id_fkey'), - sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], name='eventsuggestion_created_by_id_fkey'), - sa.PrimaryKeyConstraint('id', name='eventsuggestion_pkey'), - postgresql_ignore_search_path=False + op.create_foreign_key( + "event_host_id_fkey", "event", "org_or_adminunit", ["host_id"], ["id"] ) - op.create_table('orgmember', - sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column('organization_id', sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column('user_id', sa.INTEGER(), autoincrement=False, nullable=False), - sa.ForeignKeyConstraint(['organization_id'], ['organization.id'], name='orgmember_organization_id_fkey'), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], name='orgmember_user_id_fkey'), - sa.PrimaryKeyConstraint('id', name='orgmember_pkey') + op.create_foreign_key("event_place_id_fkey", "event", "place", ["place_id"], ["id"]) + op.create_table( + "orgmemberroles_members", + sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False), + sa.Column("member_id", sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column("role_id", sa.INTEGER(), autoincrement=False, nullable=True), + sa.ForeignKeyConstraint( + ["member_id"], + ["orgmember.id"], + name="orgmemberroles_members_member_id_fkey", + ), + sa.ForeignKeyConstraint( + ["role_id"], + ["orgmemberrole.id"], + name="orgmemberroles_members_role_id_fkey", + ), + sa.PrimaryKeyConstraint("id", name="orgmemberroles_members_pkey"), ) - op.create_table('adminunitorg', - sa.Column('id', sa.INTEGER(), server_default=sa.text("nextval('adminunitorg_id_seq'::regclass)"), autoincrement=True, nullable=False), - sa.Column('admin_unit_id', sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column('organization_id', sa.INTEGER(), autoincrement=False, nullable=False), - sa.ForeignKeyConstraint(['admin_unit_id'], ['adminunit.id'], name='adminunitorg_admin_unit_id_fkey'), - sa.ForeignKeyConstraint(['organization_id'], ['organization.id'], name='adminunitorg_organization_id_fkey'), - sa.PrimaryKeyConstraint('id', name='adminunitorg_pkey'), - postgresql_ignore_search_path=False + op.create_table( + "orgmemberrole", + sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False), + sa.Column("name", sa.VARCHAR(length=80), autoincrement=False, nullable=True), + sa.Column( + "description", sa.VARCHAR(length=255), autoincrement=False, nullable=True + ), + sa.Column("permissions", sa.TEXT(), autoincrement=False, nullable=True), + sa.PrimaryKeyConstraint("id", name="orgmemberrole_pkey"), + sa.UniqueConstraint("name", name="orgmemberrole_name_key"), ) - op.create_table('adminunitorgroles_organizations', - sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column('admin_unit_org_id', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('role_id', sa.INTEGER(), autoincrement=False, nullable=True), - sa.ForeignKeyConstraint(['admin_unit_org_id'], ['adminunitorg.id'], name='adminunitorgroles_organizations_admin_unit_org_id_fkey'), - sa.ForeignKeyConstraint(['role_id'], ['adminunitorgrole.id'], name='adminunitorgroles_organizations_role_id_fkey'), - sa.PrimaryKeyConstraint('id', name='adminunitorgroles_organizations_pkey') + op.create_table( + "eventsuggestion", + sa.Column( + "created_at", postgresql.TIMESTAMP(), autoincrement=False, nullable=True + ), + sa.Column( + "id", + sa.INTEGER(), + server_default=sa.text("nextval('eventsuggestion_id_seq'::regclass)"), + autoincrement=True, + nullable=False, + ), + sa.Column("admin_unit_id", sa.INTEGER(), autoincrement=False, nullable=False), + sa.Column( + "host_name", sa.VARCHAR(length=255), autoincrement=False, nullable=False + ), + sa.Column( + "event_name", sa.VARCHAR(length=255), autoincrement=False, nullable=False + ), + sa.Column("description", sa.TEXT(), autoincrement=False, nullable=False), + sa.Column( + "place_name", sa.VARCHAR(length=255), autoincrement=False, nullable=False + ), + sa.Column( + "place_street", sa.VARCHAR(length=255), autoincrement=False, nullable=True + ), + sa.Column( + "place_postalCode", + sa.VARCHAR(length=255), + autoincrement=False, + nullable=False, + ), + sa.Column( + "place_city", sa.VARCHAR(length=255), autoincrement=False, nullable=False + ), + sa.Column( + "contact_name", sa.VARCHAR(length=255), autoincrement=False, nullable=False + ), + sa.Column( + "contact_email", sa.VARCHAR(length=255), autoincrement=False, nullable=False + ), + sa.Column( + "external_link", sa.VARCHAR(length=255), autoincrement=False, nullable=True + ), + sa.Column("created_by_id", sa.INTEGER(), autoincrement=False, nullable=True), + sa.ForeignKeyConstraint( + ["admin_unit_id"], + ["adminunit.id"], + name="eventsuggestion_admin_unit_id_fkey", + ), + sa.ForeignKeyConstraint( + ["created_by_id"], ["user.id"], name="eventsuggestion_created_by_id_fkey" + ), + sa.PrimaryKeyConstraint("id", name="eventsuggestion_pkey"), + postgresql_ignore_search_path=False, ) - op.create_table('organization', - sa.Column('created_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True), - sa.Column('id', sa.INTEGER(), server_default=sa.text("nextval('organization_id_seq'::regclass)"), autoincrement=True, nullable=False), - sa.Column('name', sa.VARCHAR(length=255), autoincrement=False, nullable=True), - sa.Column('legal_name', sa.VARCHAR(length=255), autoincrement=False, nullable=True), - sa.Column('location_id', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('logo_id', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('url', sa.VARCHAR(length=255), autoincrement=False, nullable=True), - sa.Column('created_by_id', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('email', sa.VARCHAR(length=255), autoincrement=False, nullable=True), - sa.Column('phone', sa.VARCHAR(length=255), autoincrement=False, nullable=True), - sa.Column('fax', sa.VARCHAR(length=255), autoincrement=False, nullable=True), - sa.Column('short_name', sa.VARCHAR(length=100), autoincrement=False, nullable=True), - sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], name='organization_created_by_id_fkey'), - sa.ForeignKeyConstraint(['location_id'], ['location.id'], name='organization_location_id_fkey'), - sa.ForeignKeyConstraint(['logo_id'], ['image.id'], name='organization_logo_id_fkey'), - sa.PrimaryKeyConstraint('id', name='organization_pkey'), - sa.UniqueConstraint('name', name='organization_name_key'), - sa.UniqueConstraint('short_name', name='organization_short_name_key'), - postgresql_ignore_search_path=False + op.create_table( + "orgmember", + sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False), + sa.Column("organization_id", sa.INTEGER(), autoincrement=False, nullable=False), + sa.Column("user_id", sa.INTEGER(), autoincrement=False, nullable=False), + sa.ForeignKeyConstraint( + ["organization_id"], + ["organization.id"], + name="orgmember_organization_id_fkey", + ), + sa.ForeignKeyConstraint( + ["user_id"], ["user.id"], name="orgmember_user_id_fkey" + ), + sa.PrimaryKeyConstraint("id", name="orgmember_pkey"), ) - op.create_table('adminunitorgrole', - sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column('name', sa.VARCHAR(length=80), autoincrement=False, nullable=True), - sa.Column('description', sa.VARCHAR(length=255), autoincrement=False, nullable=True), - sa.Column('permissions', sa.TEXT(), autoincrement=False, nullable=True), - sa.PrimaryKeyConstraint('id', name='adminunitorgrole_pkey'), - sa.UniqueConstraint('name', name='adminunitorgrole_name_key') + op.create_table( + "adminunitorg", + sa.Column( + "id", + sa.INTEGER(), + server_default=sa.text("nextval('adminunitorg_id_seq'::regclass)"), + autoincrement=True, + nullable=False, + ), + sa.Column("admin_unit_id", sa.INTEGER(), autoincrement=False, nullable=False), + sa.Column("organization_id", sa.INTEGER(), autoincrement=False, nullable=False), + sa.ForeignKeyConstraint( + ["admin_unit_id"], ["adminunit.id"], name="adminunitorg_admin_unit_id_fkey" + ), + sa.ForeignKeyConstraint( + ["organization_id"], + ["organization.id"], + name="adminunitorg_organization_id_fkey", + ), + sa.PrimaryKeyConstraint("id", name="adminunitorg_pkey"), + postgresql_ignore_search_path=False, ) - op.create_table('actor', - sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column('user_id', sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column('organization_id', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('admin_unit_id', sa.INTEGER(), autoincrement=False, nullable=True), - sa.ForeignKeyConstraint(['admin_unit_id'], ['adminunit.id'], name='actor_admin_unit_id_fkey'), - sa.ForeignKeyConstraint(['organization_id'], ['organization.id'], name='actor_organization_id_fkey'), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], name='actor_user_id_fkey'), - sa.PrimaryKeyConstraint('id', name='actor_pkey'), - sa.UniqueConstraint('user_id', 'organization_id', 'admin_unit_id', name='actor_user_id_organization_id_admin_unit_id_key') + op.create_table( + "adminunitorgroles_organizations", + sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False), + sa.Column( + "admin_unit_org_id", sa.INTEGER(), autoincrement=False, nullable=True + ), + sa.Column("role_id", sa.INTEGER(), autoincrement=False, nullable=True), + sa.ForeignKeyConstraint( + ["admin_unit_org_id"], + ["adminunitorg.id"], + name="adminunitorgroles_organizations_admin_unit_org_id_fkey", + ), + sa.ForeignKeyConstraint( + ["role_id"], + ["adminunitorgrole.id"], + name="adminunitorgroles_organizations_role_id_fkey", + ), + sa.PrimaryKeyConstraint("id", name="adminunitorgroles_organizations_pkey"), ) - op.create_table('org_or_adminunit', - sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column('organization_id', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('admin_unit_id', sa.INTEGER(), autoincrement=False, nullable=True), - sa.CheckConstraint('NOT ((organization_id IS NULL) AND (admin_unit_id IS NULL))', name='org_or_adminunit_check'), - sa.ForeignKeyConstraint(['admin_unit_id'], ['adminunit.id'], name='org_or_adminunit_admin_unit_id_fkey'), - sa.ForeignKeyConstraint(['organization_id'], ['organization.id'], name='org_or_adminunit_organization_id_fkey'), - sa.PrimaryKeyConstraint('id', name='org_or_adminunit_pkey'), - sa.UniqueConstraint('organization_id', 'admin_unit_id', name='org_or_adminunit_organization_id_admin_unit_id_key') + op.create_table( + "organization", + sa.Column( + "created_at", postgresql.TIMESTAMP(), autoincrement=False, nullable=True + ), + sa.Column( + "id", + sa.INTEGER(), + server_default=sa.text("nextval('organization_id_seq'::regclass)"), + autoincrement=True, + nullable=False, + ), + sa.Column("name", sa.VARCHAR(length=255), autoincrement=False, nullable=True), + sa.Column( + "legal_name", sa.VARCHAR(length=255), autoincrement=False, nullable=True + ), + sa.Column("location_id", sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column("logo_id", sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column("url", sa.VARCHAR(length=255), autoincrement=False, nullable=True), + sa.Column("created_by_id", sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column("email", sa.VARCHAR(length=255), autoincrement=False, nullable=True), + sa.Column("phone", sa.VARCHAR(length=255), autoincrement=False, nullable=True), + sa.Column("fax", sa.VARCHAR(length=255), autoincrement=False, nullable=True), + sa.Column( + "short_name", sa.VARCHAR(length=100), autoincrement=False, nullable=True + ), + sa.ForeignKeyConstraint( + ["created_by_id"], ["user.id"], name="organization_created_by_id_fkey" + ), + sa.ForeignKeyConstraint( + ["location_id"], ["location.id"], name="organization_location_id_fkey" + ), + sa.ForeignKeyConstraint( + ["logo_id"], ["image.id"], name="organization_logo_id_fkey" + ), + sa.PrimaryKeyConstraint("id", name="organization_pkey"), + sa.UniqueConstraint("name", name="organization_name_key"), + sa.UniqueConstraint("short_name", name="organization_short_name_key"), + postgresql_ignore_search_path=False, ) - op.create_table('place', - sa.Column('created_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True), - sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column('name', sa.VARCHAR(length=255), autoincrement=False, nullable=False), - sa.Column('location_id', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('photo_id', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('url', sa.VARCHAR(length=255), autoincrement=False, nullable=True), - sa.Column('description', sa.TEXT(), autoincrement=False, nullable=True), - sa.Column('created_by_id', sa.INTEGER(), autoincrement=False, nullable=True), - sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], name='place_created_by_id_fkey'), - sa.ForeignKeyConstraint(['location_id'], ['location.id'], name='place_location_id_fkey'), - sa.ForeignKeyConstraint(['photo_id'], ['image.id'], name='place_photo_id_fkey'), - sa.PrimaryKeyConstraint('id', name='place_pkey') + op.create_table( + "adminunitorgrole", + sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False), + sa.Column("name", sa.VARCHAR(length=80), autoincrement=False, nullable=True), + sa.Column( + "description", sa.VARCHAR(length=255), autoincrement=False, nullable=True + ), + sa.Column("permissions", sa.TEXT(), autoincrement=False, nullable=True), + sa.PrimaryKeyConstraint("id", name="adminunitorgrole_pkey"), + sa.UniqueConstraint("name", name="adminunitorgrole_name_key"), ) - op.create_table('eventsuggestiondate', - sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column('event_suggestion_id', sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column('start', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=False), - sa.ForeignKeyConstraint(['event_suggestion_id'], ['eventsuggestion.id'], name='eventsuggestiondate_event_suggestion_id_fkey'), - sa.PrimaryKeyConstraint('id', name='eventsuggestiondate_pkey') + op.create_table( + "actor", + sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False), + sa.Column("user_id", sa.INTEGER(), autoincrement=False, nullable=False), + sa.Column("organization_id", sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column("admin_unit_id", sa.INTEGER(), autoincrement=False, nullable=True), + sa.ForeignKeyConstraint( + ["admin_unit_id"], ["adminunit.id"], name="actor_admin_unit_id_fkey" + ), + sa.ForeignKeyConstraint( + ["organization_id"], ["organization.id"], name="actor_organization_id_fkey" + ), + sa.ForeignKeyConstraint(["user_id"], ["user.id"], name="actor_user_id_fkey"), + sa.PrimaryKeyConstraint("id", name="actor_pkey"), + sa.UniqueConstraint( + "user_id", + "organization_id", + "admin_unit_id", + name="actor_user_id_organization_id_admin_unit_id_key", + ), + ) + op.create_table( + "org_or_adminunit", + sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False), + sa.Column("organization_id", sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column("admin_unit_id", sa.INTEGER(), autoincrement=False, nullable=True), + sa.CheckConstraint( + "NOT ((organization_id IS NULL) AND (admin_unit_id IS NULL))", + name="org_or_adminunit_check", + ), + sa.ForeignKeyConstraint( + ["admin_unit_id"], + ["adminunit.id"], + name="org_or_adminunit_admin_unit_id_fkey", + ), + sa.ForeignKeyConstraint( + ["organization_id"], + ["organization.id"], + name="org_or_adminunit_organization_id_fkey", + ), + sa.PrimaryKeyConstraint("id", name="org_or_adminunit_pkey"), + sa.UniqueConstraint( + "organization_id", + "admin_unit_id", + name="org_or_adminunit_organization_id_admin_unit_id_key", + ), + ) + op.create_table( + "place", + sa.Column( + "created_at", postgresql.TIMESTAMP(), autoincrement=False, nullable=True + ), + sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False), + sa.Column("name", sa.VARCHAR(length=255), autoincrement=False, nullable=False), + sa.Column("location_id", sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column("photo_id", sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column("url", sa.VARCHAR(length=255), autoincrement=False, nullable=True), + sa.Column("description", sa.TEXT(), autoincrement=False, nullable=True), + sa.Column("created_by_id", sa.INTEGER(), autoincrement=False, nullable=True), + sa.ForeignKeyConstraint( + ["created_by_id"], ["user.id"], name="place_created_by_id_fkey" + ), + sa.ForeignKeyConstraint( + ["location_id"], ["location.id"], name="place_location_id_fkey" + ), + sa.ForeignKeyConstraint(["photo_id"], ["image.id"], name="place_photo_id_fkey"), + sa.PrimaryKeyConstraint("id", name="place_pkey"), + ) + op.create_table( + "eventsuggestiondate", + sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False), + sa.Column( + "event_suggestion_id", sa.INTEGER(), autoincrement=False, nullable=False + ), + sa.Column( + "start", + postgresql.TIMESTAMP(timezone=True), + autoincrement=False, + nullable=False, + ), + sa.ForeignKeyConstraint( + ["event_suggestion_id"], + ["eventsuggestion.id"], + name="eventsuggestiondate_event_suggestion_id_fkey", + ), + sa.PrimaryKeyConstraint("id", name="eventsuggestiondate_pkey"), ) # ### end Alembic commands ### diff --git a/migrations/versions/6be822396123_.py b/migrations/versions/6be822396123_.py index 63d7cfb..083745f 100644 --- a/migrations/versions/6be822396123_.py +++ b/migrations/versions/6be822396123_.py @@ -12,37 +12,54 @@ from project import dbtypes from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. -revision = '6be822396123' -down_revision = '021f602d9965' +revision = "6be822396123" +down_revision = "021f602d9965" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - #op.drop_table('spatial_ref_sys') - op.drop_table('eventcontact') - op.add_column('eventsuggestion', sa.Column('contact_email_notice', sa.Boolean(), nullable=True)) + # op.drop_table('spatial_ref_sys') + op.drop_table("eventcontact") + op.add_column( + "eventsuggestion", + sa.Column("contact_email_notice", sa.Boolean(), nullable=True), + ) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_column('eventsuggestion', 'contact_email_notice') - op.create_table('eventcontact', - sa.Column('created_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True), - sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column('created_by_id', sa.INTEGER(), autoincrement=False, nullable=True), - sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], name='eventcontact_created_by_id_fkey'), - sa.PrimaryKeyConstraint('id', name='eventcontact_pkey') + op.drop_column("eventsuggestion", "contact_email_notice") + op.create_table( + "eventcontact", + sa.Column( + "created_at", postgresql.TIMESTAMP(), autoincrement=False, nullable=True + ), + sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False), + sa.Column("created_by_id", sa.INTEGER(), autoincrement=False, nullable=True), + sa.ForeignKeyConstraint( + ["created_by_id"], ["user.id"], name="eventcontact_created_by_id_fkey" + ), + sa.PrimaryKeyConstraint("id", name="eventcontact_pkey"), ) - op.create_table('spatial_ref_sys', - sa.Column('srid', sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column('auth_name', sa.VARCHAR(length=256), autoincrement=False, nullable=True), - sa.Column('auth_srid', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('srtext', sa.VARCHAR(length=2048), autoincrement=False, nullable=True), - sa.Column('proj4text', sa.VARCHAR(length=2048), autoincrement=False, nullable=True), - sa.CheckConstraint('(srid > 0) AND (srid <= 998999)', name='spatial_ref_sys_srid_check'), - sa.PrimaryKeyConstraint('srid', name='spatial_ref_sys_pkey') + op.create_table( + "spatial_ref_sys", + sa.Column("srid", sa.INTEGER(), autoincrement=False, nullable=False), + sa.Column( + "auth_name", sa.VARCHAR(length=256), autoincrement=False, nullable=True + ), + sa.Column("auth_srid", sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column( + "srtext", sa.VARCHAR(length=2048), autoincrement=False, nullable=True + ), + sa.Column( + "proj4text", sa.VARCHAR(length=2048), autoincrement=False, nullable=True + ), + sa.CheckConstraint( + "(srid > 0) AND (srid <= 998999)", name="spatial_ref_sys_srid_check" + ), + sa.PrimaryKeyConstraint("srid", name="spatial_ref_sys_pkey"), ) # ### end Alembic commands ### diff --git a/migrations/versions/75c07cb9cfe3_.py b/migrations/versions/75c07cb9cfe3_.py index 5228d41..279dc5e 100644 --- a/migrations/versions/75c07cb9cfe3_.py +++ b/migrations/versions/75c07cb9cfe3_.py @@ -11,35 +11,43 @@ import sqlalchemy_utils # revision identifiers, used by Alembic. -revision = '75c07cb9cfe3' -down_revision = 'abf0f671ba27' +revision = "75c07cb9cfe3" +down_revision = "abf0f671ba27" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.add_column('adminunit', sa.Column('email', sa.Unicode(length=255), nullable=True)) - op.add_column('adminunit', sa.Column('location_id', sa.Integer(), nullable=True)) - op.add_column('adminunit', sa.Column('logo_id', sa.Integer(), nullable=True)) - op.add_column('adminunit', sa.Column('phone', sa.Unicode(length=255), nullable=True)) - op.add_column('adminunit', sa.Column('url', sa.String(length=255), nullable=True)) - op.create_foreign_key(None, 'adminunit', 'image', ['logo_id'], ['id']) - op.create_foreign_key(None, 'adminunit', 'location', ['location_id'], ['id']) - op.add_column('organization', sa.Column('email', sa.Unicode(length=255), nullable=True)) - op.add_column('organization', sa.Column('phone', sa.Unicode(length=255), nullable=True)) + op.add_column( + "adminunit", sa.Column("email", sa.Unicode(length=255), nullable=True) + ) + op.add_column("adminunit", sa.Column("location_id", sa.Integer(), nullable=True)) + op.add_column("adminunit", sa.Column("logo_id", sa.Integer(), nullable=True)) + op.add_column( + "adminunit", sa.Column("phone", sa.Unicode(length=255), nullable=True) + ) + op.add_column("adminunit", sa.Column("url", sa.String(length=255), nullable=True)) + op.create_foreign_key(None, "adminunit", "image", ["logo_id"], ["id"]) + op.create_foreign_key(None, "adminunit", "location", ["location_id"], ["id"]) + op.add_column( + "organization", sa.Column("email", sa.Unicode(length=255), nullable=True) + ) + op.add_column( + "organization", sa.Column("phone", sa.Unicode(length=255), nullable=True) + ) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_column('organization', 'phone') - op.drop_column('organization', 'email') - op.drop_constraint(None, 'adminunit', type_='foreignkey') - op.drop_constraint(None, 'adminunit', type_='foreignkey') - op.drop_column('adminunit', 'url') - op.drop_column('adminunit', 'phone') - op.drop_column('adminunit', 'logo_id') - op.drop_column('adminunit', 'location_id') - op.drop_column('adminunit', 'email') + op.drop_column("organization", "phone") + op.drop_column("organization", "email") + op.drop_constraint(None, "adminunit", type_="foreignkey") + op.drop_constraint(None, "adminunit", type_="foreignkey") + op.drop_column("adminunit", "url") + op.drop_column("adminunit", "phone") + op.drop_column("adminunit", "logo_id") + op.drop_column("adminunit", "location_id") + op.drop_column("adminunit", "email") # ### end Alembic commands ### diff --git a/migrations/versions/7afc40e11791_.py b/migrations/versions/7afc40e11791_.py index 710cf99..6d951b2 100644 --- a/migrations/versions/7afc40e11791_.py +++ b/migrations/versions/7afc40e11791_.py @@ -7,38 +7,52 @@ Create Date: 2020-09-28 10:38:46.424791 """ from alembic import op import sqlalchemy as sa -import sqlalchemy_utils from project import dbtypes from project.models import FeaturedEventRejectionReason, FeaturedEventReviewStatus # revision identifiers, used by Alembic. -revision = '7afc40e11791' -down_revision = 'a8c662c46047' +revision = "7afc40e11791" +down_revision = "a8c662c46047" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.create_table('featuredevent', - sa.Column('created_at', sa.DateTime(), nullable=True), - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('event_id', sa.Integer(), nullable=False), - sa.Column('review_status', dbtypes.IntegerEnum(FeaturedEventReviewStatus), nullable=True), - sa.Column('rejection_resaon', dbtypes.IntegerEnum(FeaturedEventRejectionReason), nullable=True), - sa.Column('rating', sa.Integer(), nullable=True), - sa.Column('created_by_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], ), - sa.ForeignKeyConstraint(['event_id'], ['event.id'], ), - sa.PrimaryKeyConstraint('id') + op.create_table( + "featuredevent", + sa.Column("created_at", sa.DateTime(), nullable=True), + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("event_id", sa.Integer(), nullable=False), + sa.Column( + "review_status", + dbtypes.IntegerEnum(FeaturedEventReviewStatus), + nullable=True, + ), + sa.Column( + "rejection_resaon", + dbtypes.IntegerEnum(FeaturedEventRejectionReason), + nullable=True, + ), + sa.Column("rating", sa.Integer(), nullable=True), + sa.Column("created_by_id", sa.Integer(), nullable=True), + sa.ForeignKeyConstraint( + ["created_by_id"], + ["user.id"], + ), + sa.ForeignKeyConstraint( + ["event_id"], + ["event.id"], + ), + sa.PrimaryKeyConstraint("id"), ) - op.add_column('event', sa.Column('rating', sa.Integer(), nullable=True)) + op.add_column("event", sa.Column("rating", sa.Integer(), nullable=True)) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_column('event', 'rating') - op.drop_table('featuredevent') + op.drop_column("event", "rating") + op.drop_table("featuredevent") # ### end Alembic commands ### diff --git a/migrations/versions/8f4df40a36f3_.py b/migrations/versions/8f4df40a36f3_.py index 59a4a8c..4316eb7 100644 --- a/migrations/versions/8f4df40a36f3_.py +++ b/migrations/versions/8f4df40a36f3_.py @@ -12,27 +12,31 @@ from project import dbtypes # revision identifiers, used by Alembic. -revision = '8f4df40a36f3' -down_revision = 'f71c86333bfb' +revision = "8f4df40a36f3" +down_revision = "f71c86333bfb" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.create_table('adminunitmemberinvitation', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('admin_unit_id', sa.Integer(), nullable=False), - sa.Column('email', sa.String(length=255), nullable=True), - sa.Column('roles', sa.UnicodeText(), nullable=True), - sa.ForeignKeyConstraint(['admin_unit_id'], ['adminunit.id'], ), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('email', 'admin_unit_id') + op.create_table( + "adminunitmemberinvitation", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("admin_unit_id", sa.Integer(), nullable=False), + sa.Column("email", sa.String(length=255), nullable=True), + sa.Column("roles", sa.UnicodeText(), nullable=True), + sa.ForeignKeyConstraint( + ["admin_unit_id"], + ["adminunit.id"], + ), + sa.PrimaryKeyConstraint("id"), + sa.UniqueConstraint("email", "admin_unit_id"), ) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_table('adminunitmemberinvitation') + op.drop_table("adminunitmemberinvitation") # ### end Alembic commands ### diff --git a/migrations/versions/92f37474ad62_.py b/migrations/versions/92f37474ad62_.py index d3d16f8..4c11377 100644 --- a/migrations/versions/92f37474ad62_.py +++ b/migrations/versions/92f37474ad62_.py @@ -7,41 +7,65 @@ Create Date: 2020-10-18 13:06:47.639083 """ from alembic import op import sqlalchemy as sa -import sqlalchemy_utils -from project import dbtypes -from project.models import EventRejectionReason, EventReviewStatus # revision identifiers, used by Alembic. -revision = '92f37474ad62' -down_revision = '0a282a331e35' +revision = "92f37474ad62" +down_revision = "0a282a331e35" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - #op.drop_table('spatial_ref_sys') - op.drop_constraint('eventplace_name_organizer_id_admin_unit_id_key', 'eventplace', type_='unique') - op.drop_constraint('eventplace_organizer_id_fkey', 'eventplace', type_='foreignkey') - op.drop_column('eventplace', 'public') - op.drop_column('eventplace', 'organizer_id') + # op.drop_table('spatial_ref_sys') + op.drop_constraint( + "eventplace_name_organizer_id_admin_unit_id_key", "eventplace", type_="unique" + ) + op.drop_constraint("eventplace_organizer_id_fkey", "eventplace", type_="foreignkey") + op.drop_column("eventplace", "public") + op.drop_column("eventplace", "organizer_id") # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.add_column('eventplace', sa.Column('organizer_id', sa.INTEGER(), autoincrement=False, nullable=True)) - op.add_column('eventplace', sa.Column('public', sa.BOOLEAN(), autoincrement=False, nullable=True)) - op.create_foreign_key('eventplace_organizer_id_fkey', 'eventplace', 'eventorganizer', ['organizer_id'], ['id']) - op.create_unique_constraint('eventplace_name_organizer_id_admin_unit_id_key', 'eventplace', ['name', 'organizer_id', 'admin_unit_id']) - op.create_table('spatial_ref_sys', - sa.Column('srid', sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column('auth_name', sa.VARCHAR(length=256), autoincrement=False, nullable=True), - sa.Column('auth_srid', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('srtext', sa.VARCHAR(length=2048), autoincrement=False, nullable=True), - sa.Column('proj4text', sa.VARCHAR(length=2048), autoincrement=False, nullable=True), - sa.CheckConstraint('(srid > 0) AND (srid <= 998999)', name='spatial_ref_sys_srid_check'), - sa.PrimaryKeyConstraint('srid', name='spatial_ref_sys_pkey') + op.add_column( + "eventplace", + sa.Column("organizer_id", sa.INTEGER(), autoincrement=False, nullable=True), + ) + op.add_column( + "eventplace", + sa.Column("public", sa.BOOLEAN(), autoincrement=False, nullable=True), + ) + op.create_foreign_key( + "eventplace_organizer_id_fkey", + "eventplace", + "eventorganizer", + ["organizer_id"], + ["id"], + ) + op.create_unique_constraint( + "eventplace_name_organizer_id_admin_unit_id_key", + "eventplace", + ["name", "organizer_id", "admin_unit_id"], + ) + op.create_table( + "spatial_ref_sys", + sa.Column("srid", sa.INTEGER(), autoincrement=False, nullable=False), + sa.Column( + "auth_name", sa.VARCHAR(length=256), autoincrement=False, nullable=True + ), + sa.Column("auth_srid", sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column( + "srtext", sa.VARCHAR(length=2048), autoincrement=False, nullable=True + ), + sa.Column( + "proj4text", sa.VARCHAR(length=2048), autoincrement=False, nullable=True + ), + sa.CheckConstraint( + "(srid > 0) AND (srid <= 998999)", name="spatial_ref_sys_srid_check" + ), + sa.PrimaryKeyConstraint("srid", name="spatial_ref_sys_pkey"), ) # ### end Alembic commands ### diff --git a/migrations/versions/975c22ae802b_.py b/migrations/versions/975c22ae802b_.py index eec41c4..8114754 100644 --- a/migrations/versions/975c22ae802b_.py +++ b/migrations/versions/975c22ae802b_.py @@ -12,48 +12,44 @@ from project import dbtypes # revision identifiers, used by Alembic. -revision = '975c22ae802b' -down_revision = '5c8457f2eac1' +revision = "975c22ae802b" +down_revision = "5c8457f2eac1" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.create_table('eventorganizer', - sa.Column('created_at', sa.DateTime(), nullable=True), - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('name', sa.Unicode(length=255), nullable=True), - sa.Column('org_name', sa.Unicode(length=255), nullable=True), - sa.Column('url', sa.String(length=255), nullable=True), - sa.Column('email', sa.Unicode(length=255), nullable=True), - sa.Column('phone', sa.Unicode(length=255), nullable=True), - sa.Column('created_by_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('id') + op.create_table( + "eventorganizer", + sa.Column("created_at", sa.DateTime(), nullable=True), + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("name", sa.Unicode(length=255), nullable=True), + sa.Column("org_name", sa.Unicode(length=255), nullable=True), + sa.Column("url", sa.String(length=255), nullable=True), + sa.Column("email", sa.Unicode(length=255), nullable=True), + sa.Column("phone", sa.Unicode(length=255), nullable=True), + sa.Column("created_by_id", sa.Integer(), nullable=True), + sa.ForeignKeyConstraint( + ["created_by_id"], + ["user.id"], + ), + sa.PrimaryKeyConstraint("id"), ) - op.add_column('event', sa.Column('organizer_id', sa.Integer(), nullable=True)) - op.alter_column('event', 'host_id', - existing_type=sa.INTEGER(), - nullable=True) - op.alter_column('event', 'place_id', - existing_type=sa.INTEGER(), - nullable=True) - op.create_foreign_key(None, 'event', 'eventorganizer', ['organizer_id'], ['id']) - op.drop_constraint('place_name_key', 'place', type_='unique') + op.add_column("event", sa.Column("organizer_id", sa.Integer(), nullable=True)) + op.alter_column("event", "host_id", existing_type=sa.INTEGER(), nullable=True) + op.alter_column("event", "place_id", existing_type=sa.INTEGER(), nullable=True) + op.create_foreign_key(None, "event", "eventorganizer", ["organizer_id"], ["id"]) + op.drop_constraint("place_name_key", "place", type_="unique") # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.create_unique_constraint('place_name_key', 'place', ['name']) - op.drop_constraint(None, 'event', type_='foreignkey') - op.alter_column('event', 'place_id', - existing_type=sa.INTEGER(), - nullable=False) - op.alter_column('event', 'host_id', - existing_type=sa.INTEGER(), - nullable=False) - op.drop_column('event', 'organizer_id') - op.drop_table('eventorganizer') + op.create_unique_constraint("place_name_key", "place", ["name"]) + op.drop_constraint(None, "event", type_="foreignkey") + op.alter_column("event", "place_id", existing_type=sa.INTEGER(), nullable=False) + op.alter_column("event", "host_id", existing_type=sa.INTEGER(), nullable=False) + op.drop_column("event", "organizer_id") + op.drop_table("eventorganizer") # ### end Alembic commands ### diff --git a/migrations/versions/a336ac384c64_.py b/migrations/versions/a336ac384c64_.py index 7c830c9..6f3413e 100644 --- a/migrations/versions/a336ac384c64_.py +++ b/migrations/versions/a336ac384c64_.py @@ -12,32 +12,36 @@ from project import dbtypes # revision identifiers, used by Alembic. -revision = 'a336ac384c64' -down_revision = '62e071b0da50' +revision = "a336ac384c64" +down_revision = "62e071b0da50" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.create_table('eventcontact', - sa.Column('created_at', sa.DateTime(), nullable=True), - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('name', sa.Unicode(length=255), nullable=False), - sa.Column('email', sa.Unicode(length=255), nullable=True), - sa.Column('phone', sa.Unicode(length=255), nullable=True), - sa.Column('created_by_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('id') + op.create_table( + "eventcontact", + sa.Column("created_at", sa.DateTime(), nullable=True), + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("name", sa.Unicode(length=255), nullable=False), + sa.Column("email", sa.Unicode(length=255), nullable=True), + sa.Column("phone", sa.Unicode(length=255), nullable=True), + sa.Column("created_by_id", sa.Integer(), nullable=True), + sa.ForeignKeyConstraint( + ["created_by_id"], + ["user.id"], + ), + sa.PrimaryKeyConstraint("id"), ) - op.add_column('event', sa.Column('contact_id', sa.Integer(), nullable=True)) - op.create_foreign_key(None, 'event', 'eventcontact', ['contact_id'], ['id']) + op.add_column("event", sa.Column("contact_id", sa.Integer(), nullable=True)) + op.create_foreign_key(None, "event", "eventcontact", ["contact_id"], ["id"]) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_constraint(None, 'event', type_='foreignkey') - op.drop_column('event', 'contact_id') - op.drop_table('eventcontact') + op.drop_constraint(None, "event", type_="foreignkey") + op.drop_column("event", "contact_id") + op.drop_table("eventcontact") # ### end Alembic commands ### diff --git a/migrations/versions/a75bd9c8ad3a_.py b/migrations/versions/a75bd9c8ad3a_.py index 963c246..ce11bca 100644 --- a/migrations/versions/a75bd9c8ad3a_.py +++ b/migrations/versions/a75bd9c8ad3a_.py @@ -7,65 +7,104 @@ Create Date: 2020-09-29 16:53:02.520125 """ from alembic import op import sqlalchemy as sa -import sqlalchemy_utils from project import dbtypes from sqlalchemy.dialects import postgresql -from project.models import EventReferenceRequestRejectionReason, EventReferenceRequestReviewStatus +from project.models import ( + EventReferenceRequestRejectionReason, + EventReferenceRequestReviewStatus, +) # revision identifiers, used by Alembic. -revision = 'a75bd9c8ad3a' -down_revision = '51c47c7f0bdb' +revision = "a75bd9c8ad3a" +down_revision = "51c47c7f0bdb" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.create_table('eventreference', - sa.Column('created_at', sa.DateTime(), nullable=True), - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('event_id', sa.Integer(), nullable=False), - sa.Column('admin_unit_id', sa.Integer(), nullable=False), - sa.Column('rating', sa.Integer(), nullable=True), - sa.Column('created_by_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['admin_unit_id'], ['adminunit.id'], ), - sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], ), - sa.ForeignKeyConstraint(['event_id'], ['event.id'], ), - sa.PrimaryKeyConstraint('id') + op.create_table( + "eventreference", + sa.Column("created_at", sa.DateTime(), nullable=True), + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("event_id", sa.Integer(), nullable=False), + sa.Column("admin_unit_id", sa.Integer(), nullable=False), + sa.Column("rating", sa.Integer(), nullable=True), + sa.Column("created_by_id", sa.Integer(), nullable=True), + sa.ForeignKeyConstraint( + ["admin_unit_id"], + ["adminunit.id"], + ), + sa.ForeignKeyConstraint( + ["created_by_id"], + ["user.id"], + ), + sa.ForeignKeyConstraint( + ["event_id"], + ["event.id"], + ), + sa.PrimaryKeyConstraint("id"), ) - op.create_table('eventreferencerequest', - sa.Column('created_at', sa.DateTime(), nullable=True), - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('event_id', sa.Integer(), nullable=False), - sa.Column('admin_unit_id', sa.Integer(), nullable=False), - sa.Column('review_status', dbtypes.IntegerEnum(EventReferenceRequestReviewStatus), nullable=True), - sa.Column('rejection_reason', dbtypes.IntegerEnum(EventReferenceRequestRejectionReason), nullable=True), - sa.Column('created_by_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['admin_unit_id'], ['adminunit.id'], ), - sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], ), - sa.ForeignKeyConstraint(['event_id'], ['event.id'], ), - sa.PrimaryKeyConstraint('id') + op.create_table( + "eventreferencerequest", + sa.Column("created_at", sa.DateTime(), nullable=True), + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("event_id", sa.Integer(), nullable=False), + sa.Column("admin_unit_id", sa.Integer(), nullable=False), + sa.Column( + "review_status", + dbtypes.IntegerEnum(EventReferenceRequestReviewStatus), + nullable=True, + ), + sa.Column( + "rejection_reason", + dbtypes.IntegerEnum(EventReferenceRequestRejectionReason), + nullable=True, + ), + sa.Column("created_by_id", sa.Integer(), nullable=True), + sa.ForeignKeyConstraint( + ["admin_unit_id"], + ["adminunit.id"], + ), + sa.ForeignKeyConstraint( + ["created_by_id"], + ["user.id"], + ), + sa.ForeignKeyConstraint( + ["event_id"], + ["event.id"], + ), + sa.PrimaryKeyConstraint("id"), ) - op.drop_table('featuredevent') + op.drop_table("featuredevent") # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.create_table('featuredevent', - sa.Column('created_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True), - sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column('event_id', sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column('review_status', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('rejection_resaon', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('rating', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('created_by_id', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('admin_unit_id', sa.INTEGER(), autoincrement=False, nullable=False), - sa.ForeignKeyConstraint(['admin_unit_id'], ['adminunit.id'], name='featuredevent_admin_unit_id_fkey'), - sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], name='featuredevent_created_by_id_fkey'), - sa.ForeignKeyConstraint(['event_id'], ['event.id'], name='featuredevent_event_id_fkey'), - sa.PrimaryKeyConstraint('id', name='featuredevent_pkey') + op.create_table( + "featuredevent", + sa.Column( + "created_at", postgresql.TIMESTAMP(), autoincrement=False, nullable=True + ), + sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False), + sa.Column("event_id", sa.INTEGER(), autoincrement=False, nullable=False), + sa.Column("review_status", sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column("rejection_resaon", sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column("rating", sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column("created_by_id", sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column("admin_unit_id", sa.INTEGER(), autoincrement=False, nullable=False), + sa.ForeignKeyConstraint( + ["admin_unit_id"], ["adminunit.id"], name="featuredevent_admin_unit_id_fkey" + ), + sa.ForeignKeyConstraint( + ["created_by_id"], ["user.id"], name="featuredevent_created_by_id_fkey" + ), + sa.ForeignKeyConstraint( + ["event_id"], ["event.id"], name="featuredevent_event_id_fkey" + ), + sa.PrimaryKeyConstraint("id", name="featuredevent_pkey"), ) - op.drop_table('eventreferencerequest') - op.drop_table('eventreference') + op.drop_table("eventreferencerequest") + op.drop_table("eventreference") # ### end Alembic commands ### diff --git a/migrations/versions/a8c662c46047_.py b/migrations/versions/a8c662c46047_.py index 53dc204..670324e 100644 --- a/migrations/versions/a8c662c46047_.py +++ b/migrations/versions/a8c662c46047_.py @@ -12,21 +12,23 @@ from project import dbtypes # revision identifiers, used by Alembic. -revision = 'a8c662c46047' -down_revision = '8f4df40a36f3' +revision = "a8c662c46047" +down_revision = "8f4df40a36f3" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.add_column('adminunitmemberrole', sa.Column('title', sa.Unicode(length=255), nullable=True)) - op.add_column('role', sa.Column('title', sa.Unicode(length=255), nullable=True)) + op.add_column( + "adminunitmemberrole", sa.Column("title", sa.Unicode(length=255), nullable=True) + ) + op.add_column("role", sa.Column("title", sa.Unicode(length=255), nullable=True)) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_column('role', 'title') - op.drop_column('adminunitmemberrole', 'title') + op.drop_column("role", "title") + op.drop_column("adminunitmemberrole", "title") # ### end Alembic commands ### diff --git a/migrations/versions/abf0f671ba27_.py b/migrations/versions/abf0f671ba27_.py index c2dd613..7d464db 100644 --- a/migrations/versions/abf0f671ba27_.py +++ b/migrations/versions/abf0f671ba27_.py @@ -11,29 +11,33 @@ import sqlalchemy_utils # revision identifiers, used by Alembic. -revision = 'abf0f671ba27' -down_revision = 'bbad7e33a780' +revision = "abf0f671ba27" +down_revision = "bbad7e33a780" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.create_table('flask_dance_oauth', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('provider', sa.String(length=50), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('token', sqlalchemy_utils.types.json.JSONType(), nullable=False), - sa.Column('provider_user_id', sa.String(length=256), nullable=False), - sa.Column('user_id', sa.Integer(), nullable=False), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('provider_user_id') + op.create_table( + "flask_dance_oauth", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("provider", sa.String(length=50), nullable=False), + sa.Column("created_at", sa.DateTime(), nullable=False), + sa.Column("token", sqlalchemy_utils.types.json.JSONType(), nullable=False), + sa.Column("provider_user_id", sa.String(length=256), nullable=False), + sa.Column("user_id", sa.Integer(), nullable=False), + sa.ForeignKeyConstraint( + ["user_id"], + ["user.id"], + ), + sa.PrimaryKeyConstraint("id"), + sa.UniqueConstraint("provider_user_id"), ) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_table('flask_dance_oauth') + op.drop_table("flask_dance_oauth") # ### end Alembic commands ### diff --git a/migrations/versions/b128cc637447_.py b/migrations/versions/b128cc637447_.py index 559ad4c..3f0ad95 100644 --- a/migrations/versions/b128cc637447_.py +++ b/migrations/versions/b128cc637447_.py @@ -12,23 +12,27 @@ from project import dbtypes # revision identifiers, used by Alembic. -revision = 'b128cc637447' -down_revision = '41512b20e07c' +revision = "b128cc637447" +down_revision = "41512b20e07c" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.add_column('adminunit', sa.Column('fax', sa.Unicode(length=255), nullable=True)) - op.add_column('eventorganizer', sa.Column('fax', sa.Unicode(length=255), nullable=True)) - op.add_column('organization', sa.Column('fax', sa.Unicode(length=255), nullable=True)) + op.add_column("adminunit", sa.Column("fax", sa.Unicode(length=255), nullable=True)) + op.add_column( + "eventorganizer", sa.Column("fax", sa.Unicode(length=255), nullable=True) + ) + op.add_column( + "organization", sa.Column("fax", sa.Unicode(length=255), nullable=True) + ) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_column('organization', 'fax') - op.drop_column('eventorganizer', 'fax') - op.drop_column('adminunit', 'fax') + op.drop_column("organization", "fax") + op.drop_column("eventorganizer", "fax") + op.drop_column("adminunit", "fax") # ### end Alembic commands ### diff --git a/migrations/versions/b1c05324cc13_.py b/migrations/versions/b1c05324cc13_.py index 7f357d4..b6e12ba 100644 --- a/migrations/versions/b1c05324cc13_.py +++ b/migrations/versions/b1c05324cc13_.py @@ -12,21 +12,21 @@ from project import dbtypes # revision identifiers, used by Alembic. -revision = 'b1c05324cc13' -down_revision = 'cce1284874fa' +revision = "b1c05324cc13" +down_revision = "cce1284874fa" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.create_unique_constraint(None, 'adminunit', ['short_name']) - op.create_unique_constraint(None, 'organization', ['short_name']) + op.create_unique_constraint(None, "adminunit", ["short_name"]) + op.create_unique_constraint(None, "organization", ["short_name"]) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_constraint(None, 'organization', type_='unique') - op.drop_constraint(None, 'adminunit', type_='unique') + op.drop_constraint(None, "organization", type_="unique") + op.drop_constraint(None, "adminunit", type_="unique") # ### end Alembic commands ### diff --git a/migrations/versions/bbad7e33a780_.py b/migrations/versions/bbad7e33a780_.py index b31ed3d..661c020 100644 --- a/migrations/versions/bbad7e33a780_.py +++ b/migrations/versions/bbad7e33a780_.py @@ -1,7 +1,7 @@ """empty message Revision ID: bbad7e33a780 -Revises: +Revises: Create Date: 2020-06-24 21:17:25.548159 """ @@ -10,7 +10,7 @@ import sqlalchemy as sa # revision identifiers, used by Alembic. -revision = 'bbad7e33a780' +revision = "bbad7e33a780" down_revision = None branch_labels = None depends_on = None @@ -18,282 +18,420 @@ depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.create_table('adminunitmemberrole', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('name', sa.String(length=80), nullable=True), - sa.Column('description', sa.String(length=255), nullable=True), - sa.Column('permissions', sa.UnicodeText(), nullable=True), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('name') + op.create_table( + "adminunitmemberrole", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("name", sa.String(length=80), nullable=True), + sa.Column("description", sa.String(length=255), nullable=True), + sa.Column("permissions", sa.UnicodeText(), nullable=True), + sa.PrimaryKeyConstraint("id"), + sa.UniqueConstraint("name"), ) - op.create_table('adminunitorgrole', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('name', sa.String(length=80), nullable=True), - sa.Column('description', sa.String(length=255), nullable=True), - sa.Column('permissions', sa.UnicodeText(), nullable=True), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('name') + op.create_table( + "adminunitorgrole", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("name", sa.String(length=80), nullable=True), + sa.Column("description", sa.String(length=255), nullable=True), + sa.Column("permissions", sa.UnicodeText(), nullable=True), + sa.PrimaryKeyConstraint("id"), + sa.UniqueConstraint("name"), ) - op.create_table('eventcategory', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('name', sa.Unicode(length=255), nullable=False), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('name') + op.create_table( + "eventcategory", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("name", sa.Unicode(length=255), nullable=False), + sa.PrimaryKeyConstraint("id"), + sa.UniqueConstraint("name"), ) - op.create_table('orgmemberrole', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('name', sa.String(length=80), nullable=True), - sa.Column('description', sa.String(length=255), nullable=True), - sa.Column('permissions', sa.UnicodeText(), nullable=True), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('name') + op.create_table( + "orgmemberrole", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("name", sa.String(length=80), nullable=True), + sa.Column("description", sa.String(length=255), nullable=True), + sa.Column("permissions", sa.UnicodeText(), nullable=True), + sa.PrimaryKeyConstraint("id"), + sa.UniqueConstraint("name"), ) - op.create_table('role', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('name', sa.String(length=80), nullable=True), - sa.Column('description', sa.String(length=255), nullable=True), - sa.Column('permissions', sa.UnicodeText(), nullable=True), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('name') + op.create_table( + "role", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("name", sa.String(length=80), nullable=True), + sa.Column("description", sa.String(length=255), nullable=True), + sa.Column("permissions", sa.UnicodeText(), nullable=True), + sa.PrimaryKeyConstraint("id"), + sa.UniqueConstraint("name"), ) - op.create_table('user', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('email', sa.String(length=255), nullable=True), - sa.Column('username', sa.String(length=255), nullable=True), - sa.Column('password', sa.String(length=255), nullable=True), - sa.Column('last_login_at', sa.DateTime(), nullable=True), - sa.Column('current_login_at', sa.DateTime(), nullable=True), - sa.Column('last_login_ip', sa.String(length=100), nullable=True), - sa.Column('current_login_ip', sa.String(length=100), nullable=True), - sa.Column('login_count', sa.Integer(), nullable=True), - sa.Column('active', sa.Boolean(), nullable=True), - sa.Column('fs_uniquifier', sa.String(length=255), nullable=True), - sa.Column('confirmed_at', sa.DateTime(), nullable=True), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('email') + op.create_table( + "user", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("email", sa.String(length=255), nullable=True), + sa.Column("username", sa.String(length=255), nullable=True), + sa.Column("password", sa.String(length=255), nullable=True), + sa.Column("last_login_at", sa.DateTime(), nullable=True), + sa.Column("current_login_at", sa.DateTime(), nullable=True), + sa.Column("last_login_ip", sa.String(length=100), nullable=True), + sa.Column("current_login_ip", sa.String(length=100), nullable=True), + sa.Column("login_count", sa.Integer(), nullable=True), + sa.Column("active", sa.Boolean(), nullable=True), + sa.Column("fs_uniquifier", sa.String(length=255), nullable=True), + sa.Column("confirmed_at", sa.DateTime(), nullable=True), + sa.PrimaryKeyConstraint("id"), + sa.UniqueConstraint("email"), ) - op.create_table('adminunit', - sa.Column('created_at', sa.DateTime(), nullable=True), - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('name', sa.Unicode(length=255), nullable=True), - sa.Column('created_by_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('name') + op.create_table( + "adminunit", + sa.Column("created_at", sa.DateTime(), nullable=True), + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("name", sa.Unicode(length=255), nullable=True), + sa.Column("created_by_id", sa.Integer(), nullable=True), + sa.ForeignKeyConstraint( + ["created_by_id"], + ["user.id"], + ), + sa.PrimaryKeyConstraint("id"), + sa.UniqueConstraint("name"), ) - op.create_table('image', - sa.Column('created_at', sa.DateTime(), nullable=True), - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('data', sa.LargeBinary(), nullable=True), - sa.Column('encoding_format', sa.String(length=80), nullable=True), - sa.Column('created_by_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('id') + op.create_table( + "image", + sa.Column("created_at", sa.DateTime(), nullable=True), + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("data", sa.LargeBinary(), nullable=True), + sa.Column("encoding_format", sa.String(length=80), nullable=True), + sa.Column("created_by_id", sa.Integer(), nullable=True), + sa.ForeignKeyConstraint( + ["created_by_id"], + ["user.id"], + ), + sa.PrimaryKeyConstraint("id"), ) - op.create_table('location', - sa.Column('created_at', sa.DateTime(), nullable=True), - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('street', sa.Unicode(length=255), nullable=True), - sa.Column('postalCode', sa.Unicode(length=255), nullable=True), - sa.Column('city', sa.Unicode(length=255), nullable=True), - sa.Column('state', sa.Unicode(length=255), nullable=True), - sa.Column('country', sa.Unicode(length=255), nullable=True), - sa.Column('latitude', sa.Numeric(precision=18, scale=16), nullable=True), - sa.Column('longitude', sa.Numeric(precision=19, scale=16), nullable=True), - sa.Column('created_by_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('id') + op.create_table( + "location", + sa.Column("created_at", sa.DateTime(), nullable=True), + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("street", sa.Unicode(length=255), nullable=True), + sa.Column("postalCode", sa.Unicode(length=255), nullable=True), + sa.Column("city", sa.Unicode(length=255), nullable=True), + sa.Column("state", sa.Unicode(length=255), nullable=True), + sa.Column("country", sa.Unicode(length=255), nullable=True), + sa.Column("latitude", sa.Numeric(precision=18, scale=16), nullable=True), + sa.Column("longitude", sa.Numeric(precision=19, scale=16), nullable=True), + sa.Column("created_by_id", sa.Integer(), nullable=True), + sa.ForeignKeyConstraint( + ["created_by_id"], + ["user.id"], + ), + sa.PrimaryKeyConstraint("id"), ) - op.create_table('roles_users', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('user_id', sa.Integer(), nullable=True), - sa.Column('role_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['role_id'], ['role.id'], ), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('id') + op.create_table( + "roles_users", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("user_id", sa.Integer(), nullable=True), + sa.Column("role_id", sa.Integer(), nullable=True), + sa.ForeignKeyConstraint( + ["role_id"], + ["role.id"], + ), + sa.ForeignKeyConstraint( + ["user_id"], + ["user.id"], + ), + sa.PrimaryKeyConstraint("id"), ) - op.create_table('adminunitmember', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('admin_unit_id', sa.Integer(), nullable=False), - sa.Column('user_id', sa.Integer(), nullable=False), - sa.ForeignKeyConstraint(['admin_unit_id'], ['adminunit.id'], ), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('id') + op.create_table( + "adminunitmember", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("admin_unit_id", sa.Integer(), nullable=False), + sa.Column("user_id", sa.Integer(), nullable=False), + sa.ForeignKeyConstraint( + ["admin_unit_id"], + ["adminunit.id"], + ), + sa.ForeignKeyConstraint( + ["user_id"], + ["user.id"], + ), + sa.PrimaryKeyConstraint("id"), ) - op.create_table('eventsuggestion', - sa.Column('created_at', sa.DateTime(), nullable=True), - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('admin_unit_id', sa.Integer(), nullable=False), - sa.Column('host_name', sa.Unicode(length=255), nullable=False), - sa.Column('event_name', sa.Unicode(length=255), nullable=False), - sa.Column('description', sa.UnicodeText(), nullable=False), - sa.Column('place_name', sa.Unicode(length=255), nullable=False), - sa.Column('place_street', sa.Unicode(length=255), nullable=True), - sa.Column('place_postalCode', sa.Unicode(length=255), nullable=False), - sa.Column('place_city', sa.Unicode(length=255), nullable=False), - sa.Column('contact_name', sa.Unicode(length=255), nullable=False), - sa.Column('contact_email', sa.Unicode(length=255), nullable=False), - sa.Column('external_link', sa.String(length=255), nullable=True), - sa.Column('created_by_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['admin_unit_id'], ['adminunit.id'], ), - sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('id') + op.create_table( + "eventsuggestion", + sa.Column("created_at", sa.DateTime(), nullable=True), + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("admin_unit_id", sa.Integer(), nullable=False), + sa.Column("host_name", sa.Unicode(length=255), nullable=False), + sa.Column("event_name", sa.Unicode(length=255), nullable=False), + sa.Column("description", sa.UnicodeText(), nullable=False), + sa.Column("place_name", sa.Unicode(length=255), nullable=False), + sa.Column("place_street", sa.Unicode(length=255), nullable=True), + sa.Column("place_postalCode", sa.Unicode(length=255), nullable=False), + sa.Column("place_city", sa.Unicode(length=255), nullable=False), + sa.Column("contact_name", sa.Unicode(length=255), nullable=False), + sa.Column("contact_email", sa.Unicode(length=255), nullable=False), + sa.Column("external_link", sa.String(length=255), nullable=True), + sa.Column("created_by_id", sa.Integer(), nullable=True), + sa.ForeignKeyConstraint( + ["admin_unit_id"], + ["adminunit.id"], + ), + sa.ForeignKeyConstraint( + ["created_by_id"], + ["user.id"], + ), + sa.PrimaryKeyConstraint("id"), ) - op.create_table('organization', - sa.Column('created_at', sa.DateTime(), nullable=True), - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('name', sa.Unicode(length=255), nullable=True), - sa.Column('legal_name', sa.Unicode(length=255), nullable=True), - sa.Column('location_id', sa.Integer(), nullable=True), - sa.Column('logo_id', sa.Integer(), nullable=True), - sa.Column('url', sa.String(length=255), nullable=True), - sa.Column('created_by_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], ), - sa.ForeignKeyConstraint(['location_id'], ['location.id'], ), - sa.ForeignKeyConstraint(['logo_id'], ['image.id'], ), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('name') + op.create_table( + "organization", + sa.Column("created_at", sa.DateTime(), nullable=True), + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("name", sa.Unicode(length=255), nullable=True), + sa.Column("legal_name", sa.Unicode(length=255), nullable=True), + sa.Column("location_id", sa.Integer(), nullable=True), + sa.Column("logo_id", sa.Integer(), nullable=True), + sa.Column("url", sa.String(length=255), nullable=True), + sa.Column("created_by_id", sa.Integer(), nullable=True), + sa.ForeignKeyConstraint( + ["created_by_id"], + ["user.id"], + ), + sa.ForeignKeyConstraint( + ["location_id"], + ["location.id"], + ), + sa.ForeignKeyConstraint( + ["logo_id"], + ["image.id"], + ), + sa.PrimaryKeyConstraint("id"), + sa.UniqueConstraint("name"), ) - op.create_table('place', - sa.Column('created_at', sa.DateTime(), nullable=True), - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('name', sa.Unicode(length=255), nullable=False), - sa.Column('location_id', sa.Integer(), nullable=True), - sa.Column('photo_id', sa.Integer(), nullable=True), - sa.Column('url', sa.String(length=255), nullable=True), - sa.Column('description', sa.UnicodeText(), nullable=True), - sa.Column('created_by_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], ), - sa.ForeignKeyConstraint(['location_id'], ['location.id'], ), - sa.ForeignKeyConstraint(['photo_id'], ['image.id'], ), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('name') + op.create_table( + "place", + sa.Column("created_at", sa.DateTime(), nullable=True), + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("name", sa.Unicode(length=255), nullable=False), + sa.Column("location_id", sa.Integer(), nullable=True), + sa.Column("photo_id", sa.Integer(), nullable=True), + sa.Column("url", sa.String(length=255), nullable=True), + sa.Column("description", sa.UnicodeText(), nullable=True), + sa.Column("created_by_id", sa.Integer(), nullable=True), + sa.ForeignKeyConstraint( + ["created_by_id"], + ["user.id"], + ), + sa.ForeignKeyConstraint( + ["location_id"], + ["location.id"], + ), + sa.ForeignKeyConstraint( + ["photo_id"], + ["image.id"], + ), + sa.PrimaryKeyConstraint("id"), + sa.UniqueConstraint("name"), ) - op.create_table('actor', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('user_id', sa.Integer(), nullable=False), - sa.Column('organization_id', sa.Integer(), nullable=True), - sa.Column('admin_unit_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['admin_unit_id'], ['adminunit.id'], ), - sa.ForeignKeyConstraint(['organization_id'], ['organization.id'], ), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('user_id', 'organization_id', 'admin_unit_id') + op.create_table( + "actor", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("user_id", sa.Integer(), nullable=False), + sa.Column("organization_id", sa.Integer(), nullable=True), + sa.Column("admin_unit_id", sa.Integer(), nullable=True), + sa.ForeignKeyConstraint( + ["admin_unit_id"], + ["adminunit.id"], + ), + sa.ForeignKeyConstraint( + ["organization_id"], + ["organization.id"], + ), + sa.ForeignKeyConstraint( + ["user_id"], + ["user.id"], + ), + sa.PrimaryKeyConstraint("id"), + sa.UniqueConstraint("user_id", "organization_id", "admin_unit_id"), ) - op.create_table('adminunitmemberroles_members', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('member_id', sa.Integer(), nullable=True), - sa.Column('role_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['member_id'], ['adminunitmember.id'], ), - sa.ForeignKeyConstraint(['role_id'], ['adminunitmemberrole.id'], ), - sa.PrimaryKeyConstraint('id') + op.create_table( + "adminunitmemberroles_members", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("member_id", sa.Integer(), nullable=True), + sa.Column("role_id", sa.Integer(), nullable=True), + sa.ForeignKeyConstraint( + ["member_id"], + ["adminunitmember.id"], + ), + sa.ForeignKeyConstraint( + ["role_id"], + ["adminunitmemberrole.id"], + ), + sa.PrimaryKeyConstraint("id"), ) - op.create_table('adminunitorg', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('admin_unit_id', sa.Integer(), nullable=False), - sa.Column('organization_id', sa.Integer(), nullable=False), - sa.ForeignKeyConstraint(['admin_unit_id'], ['adminunit.id'], ), - sa.ForeignKeyConstraint(['organization_id'], ['organization.id'], ), - sa.PrimaryKeyConstraint('id') + op.create_table( + "adminunitorg", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("admin_unit_id", sa.Integer(), nullable=False), + sa.Column("organization_id", sa.Integer(), nullable=False), + sa.ForeignKeyConstraint( + ["admin_unit_id"], + ["adminunit.id"], + ), + sa.ForeignKeyConstraint( + ["organization_id"], + ["organization.id"], + ), + sa.PrimaryKeyConstraint("id"), ) - op.create_table('eventsuggestiondate', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('event_suggestion_id', sa.Integer(), nullable=False), - sa.Column('start', sa.DateTime(timezone=True), nullable=False), - sa.ForeignKeyConstraint(['event_suggestion_id'], ['eventsuggestion.id'], ), - sa.PrimaryKeyConstraint('id') + op.create_table( + "eventsuggestiondate", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("event_suggestion_id", sa.Integer(), nullable=False), + sa.Column("start", sa.DateTime(timezone=True), nullable=False), + sa.ForeignKeyConstraint( + ["event_suggestion_id"], + ["eventsuggestion.id"], + ), + sa.PrimaryKeyConstraint("id"), ) - op.create_table('org_or_adminunit', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('organization_id', sa.Integer(), nullable=True), - sa.Column('admin_unit_id', sa.Integer(), nullable=True), - sa.CheckConstraint('NOT(organization_id IS NULL AND admin_unit_id IS NULL)'), - sa.ForeignKeyConstraint(['admin_unit_id'], ['adminunit.id'], ), - sa.ForeignKeyConstraint(['organization_id'], ['organization.id'], ), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('organization_id', 'admin_unit_id') + op.create_table( + "org_or_adminunit", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("organization_id", sa.Integer(), nullable=True), + sa.Column("admin_unit_id", sa.Integer(), nullable=True), + sa.CheckConstraint("NOT(organization_id IS NULL AND admin_unit_id IS NULL)"), + sa.ForeignKeyConstraint( + ["admin_unit_id"], + ["adminunit.id"], + ), + sa.ForeignKeyConstraint( + ["organization_id"], + ["organization.id"], + ), + sa.PrimaryKeyConstraint("id"), + sa.UniqueConstraint("organization_id", "admin_unit_id"), ) - op.create_table('orgmember', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('organization_id', sa.Integer(), nullable=False), - sa.Column('user_id', sa.Integer(), nullable=False), - sa.ForeignKeyConstraint(['organization_id'], ['organization.id'], ), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('id') + op.create_table( + "orgmember", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("organization_id", sa.Integer(), nullable=False), + sa.Column("user_id", sa.Integer(), nullable=False), + sa.ForeignKeyConstraint( + ["organization_id"], + ["organization.id"], + ), + sa.ForeignKeyConstraint( + ["user_id"], + ["user.id"], + ), + sa.PrimaryKeyConstraint("id"), ) - op.create_table('adminunitorgroles_organizations', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('admin_unit_org_id', sa.Integer(), nullable=True), - sa.Column('role_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['admin_unit_org_id'], ['adminunitorg.id'], ), - sa.ForeignKeyConstraint(['role_id'], ['adminunitorgrole.id'], ), - sa.PrimaryKeyConstraint('id') + op.create_table( + "adminunitorgroles_organizations", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("admin_unit_org_id", sa.Integer(), nullable=True), + sa.Column("role_id", sa.Integer(), nullable=True), + sa.ForeignKeyConstraint( + ["admin_unit_org_id"], + ["adminunitorg.id"], + ), + sa.ForeignKeyConstraint( + ["role_id"], + ["adminunitorgrole.id"], + ), + sa.PrimaryKeyConstraint("id"), ) - op.create_table('event', - sa.Column('created_at', sa.DateTime(), nullable=True), - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('admin_unit_id', sa.Integer(), nullable=False), - sa.Column('host_id', sa.Integer(), nullable=False), - sa.Column('place_id', sa.Integer(), nullable=False), - sa.Column('name', sa.Unicode(length=255), nullable=False), - sa.Column('description', sa.UnicodeText(), nullable=False), - sa.Column('external_link', sa.String(length=255), nullable=True), - sa.Column('ticket_link', sa.String(length=255), nullable=True), - sa.Column('verified', sa.Boolean(), nullable=True), - sa.Column('photo_id', sa.Integer(), nullable=True), - sa.Column('category_id', sa.Integer(), nullable=False), - sa.Column('recurrence_rule', sa.UnicodeText(), nullable=True), - sa.Column('created_by_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['admin_unit_id'], ['adminunit.id'], ), - sa.ForeignKeyConstraint(['category_id'], ['eventcategory.id'], ), - sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], ), - sa.ForeignKeyConstraint(['host_id'], ['org_or_adminunit.id'], ), - sa.ForeignKeyConstraint(['photo_id'], ['image.id'], ), - sa.ForeignKeyConstraint(['place_id'], ['place.id'], ), - sa.PrimaryKeyConstraint('id') + op.create_table( + "event", + sa.Column("created_at", sa.DateTime(), nullable=True), + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("admin_unit_id", sa.Integer(), nullable=False), + sa.Column("host_id", sa.Integer(), nullable=False), + sa.Column("place_id", sa.Integer(), nullable=False), + sa.Column("name", sa.Unicode(length=255), nullable=False), + sa.Column("description", sa.UnicodeText(), nullable=False), + sa.Column("external_link", sa.String(length=255), nullable=True), + sa.Column("ticket_link", sa.String(length=255), nullable=True), + sa.Column("verified", sa.Boolean(), nullable=True), + sa.Column("photo_id", sa.Integer(), nullable=True), + sa.Column("category_id", sa.Integer(), nullable=False), + sa.Column("recurrence_rule", sa.UnicodeText(), nullable=True), + sa.Column("created_by_id", sa.Integer(), nullable=True), + sa.ForeignKeyConstraint( + ["admin_unit_id"], + ["adminunit.id"], + ), + sa.ForeignKeyConstraint( + ["category_id"], + ["eventcategory.id"], + ), + sa.ForeignKeyConstraint( + ["created_by_id"], + ["user.id"], + ), + sa.ForeignKeyConstraint( + ["host_id"], + ["org_or_adminunit.id"], + ), + sa.ForeignKeyConstraint( + ["photo_id"], + ["image.id"], + ), + sa.ForeignKeyConstraint( + ["place_id"], + ["place.id"], + ), + sa.PrimaryKeyConstraint("id"), ) - op.create_table('orgmemberroles_members', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('member_id', sa.Integer(), nullable=True), - sa.Column('role_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['member_id'], ['orgmember.id'], ), - sa.ForeignKeyConstraint(['role_id'], ['orgmemberrole.id'], ), - sa.PrimaryKeyConstraint('id') + op.create_table( + "orgmemberroles_members", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("member_id", sa.Integer(), nullable=True), + sa.Column("role_id", sa.Integer(), nullable=True), + sa.ForeignKeyConstraint( + ["member_id"], + ["orgmember.id"], + ), + sa.ForeignKeyConstraint( + ["role_id"], + ["orgmemberrole.id"], + ), + sa.PrimaryKeyConstraint("id"), ) - op.create_table('eventdate', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('event_id', sa.Integer(), nullable=False), - sa.Column('start', sa.DateTime(timezone=True), nullable=False), - sa.ForeignKeyConstraint(['event_id'], ['event.id'], ), - sa.PrimaryKeyConstraint('id') + op.create_table( + "eventdate", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("event_id", sa.Integer(), nullable=False), + sa.Column("start", sa.DateTime(timezone=True), nullable=False), + sa.ForeignKeyConstraint( + ["event_id"], + ["event.id"], + ), + sa.PrimaryKeyConstraint("id"), ) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_table('eventdate') - op.drop_table('orgmemberroles_members') - op.drop_table('event') - op.drop_table('adminunitorgroles_organizations') - op.drop_table('orgmember') - op.drop_table('org_or_adminunit') - op.drop_table('eventsuggestiondate') - op.drop_table('adminunitorg') - op.drop_table('adminunitmemberroles_members') - op.drop_table('actor') - op.drop_table('place') - op.drop_table('organization') - op.drop_table('eventsuggestion') - op.drop_table('adminunitmember') - op.drop_table('roles_users') - op.drop_table('location') - op.drop_table('image') - op.drop_table('adminunit') - op.drop_table('user') - op.drop_table('role') - op.drop_table('orgmemberrole') - op.drop_table('eventcategory') - op.drop_table('adminunitorgrole') - op.drop_table('adminunitmemberrole') + op.drop_table("eventdate") + op.drop_table("orgmemberroles_members") + op.drop_table("event") + op.drop_table("adminunitorgroles_organizations") + op.drop_table("orgmember") + op.drop_table("org_or_adminunit") + op.drop_table("eventsuggestiondate") + op.drop_table("adminunitorg") + op.drop_table("adminunitmemberroles_members") + op.drop_table("actor") + op.drop_table("place") + op.drop_table("organization") + op.drop_table("eventsuggestion") + op.drop_table("adminunitmember") + op.drop_table("roles_users") + op.drop_table("location") + op.drop_table("image") + op.drop_table("adminunit") + op.drop_table("user") + op.drop_table("role") + op.drop_table("orgmemberrole") + op.drop_table("eventcategory") + op.drop_table("adminunitorgrole") + op.drop_table("adminunitmemberrole") # ### end Alembic commands ### diff --git a/migrations/versions/cce1284874fa_.py b/migrations/versions/cce1284874fa_.py index 9d91018..b4b6a5d 100644 --- a/migrations/versions/cce1284874fa_.py +++ b/migrations/versions/cce1284874fa_.py @@ -12,21 +12,25 @@ from project import dbtypes # revision identifiers, used by Alembic. -revision = 'cce1284874fa' -down_revision = 'b128cc637447' +revision = "cce1284874fa" +down_revision = "b128cc637447" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.add_column('adminunit', sa.Column('short_name', sa.Unicode(length=100), nullable=True)) - op.add_column('organization', sa.Column('short_name', sa.Unicode(length=100), nullable=True)) + op.add_column( + "adminunit", sa.Column("short_name", sa.Unicode(length=100), nullable=True) + ) + op.add_column( + "organization", sa.Column("short_name", sa.Unicode(length=100), nullable=True) + ) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_column('organization', 'short_name') - op.drop_column('adminunit', 'short_name') + op.drop_column("organization", "short_name") + op.drop_column("adminunit", "short_name") # ### end Alembic commands ### diff --git a/migrations/versions/da63ba1d58b1_.py b/migrations/versions/da63ba1d58b1_.py index 2f8b885..c9c816e 100644 --- a/migrations/versions/da63ba1d58b1_.py +++ b/migrations/versions/da63ba1d58b1_.py @@ -12,29 +12,40 @@ from project import dbtypes # revision identifiers, used by Alembic. -revision = 'da63ba1d58b1' -down_revision = '091deace5f08' +revision = "da63ba1d58b1" +down_revision = "091deace5f08" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - #op.drop_table('spatial_ref_sys') - op.add_column('image', sa.Column('copyright_text', sa.Unicode(length=255), nullable=True)) + # op.drop_table('spatial_ref_sys') + op.add_column( + "image", sa.Column("copyright_text", sa.Unicode(length=255), nullable=True) + ) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_column('image', 'copyright_text') - op.create_table('spatial_ref_sys', - sa.Column('srid', sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column('auth_name', sa.VARCHAR(length=256), autoincrement=False, nullable=True), - sa.Column('auth_srid', sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column('srtext', sa.VARCHAR(length=2048), autoincrement=False, nullable=True), - sa.Column('proj4text', sa.VARCHAR(length=2048), autoincrement=False, nullable=True), - sa.CheckConstraint('(srid > 0) AND (srid <= 998999)', name='spatial_ref_sys_srid_check'), - sa.PrimaryKeyConstraint('srid', name='spatial_ref_sys_pkey') + op.drop_column("image", "copyright_text") + op.create_table( + "spatial_ref_sys", + sa.Column("srid", sa.INTEGER(), autoincrement=False, nullable=False), + sa.Column( + "auth_name", sa.VARCHAR(length=256), autoincrement=False, nullable=True + ), + sa.Column("auth_srid", sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column( + "srtext", sa.VARCHAR(length=2048), autoincrement=False, nullable=True + ), + sa.Column( + "proj4text", sa.VARCHAR(length=2048), autoincrement=False, nullable=True + ), + sa.CheckConstraint( + "(srid > 0) AND (srid <= 998999)", name="spatial_ref_sys_srid_check" + ), + sa.PrimaryKeyConstraint("srid", name="spatial_ref_sys_pkey"), ) # ### end Alembic commands ### diff --git a/migrations/versions/dcd0b71650b0_.py b/migrations/versions/dcd0b71650b0_.py index fd3d5c7..811c074 100644 --- a/migrations/versions/dcd0b71650b0_.py +++ b/migrations/versions/dcd0b71650b0_.py @@ -12,25 +12,27 @@ from project import dbtypes # revision identifiers, used by Alembic. -revision = 'dcd0b71650b0' -down_revision = '699c4f6a7fe8' +revision = "dcd0b71650b0" +down_revision = "699c4f6a7fe8" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.add_column('eventorganizer', sa.Column('location_id', sa.Integer(), nullable=True)) - op.add_column('eventorganizer', sa.Column('logo_id', sa.Integer(), nullable=True)) - op.create_foreign_key(None, 'eventorganizer', 'image', ['logo_id'], ['id']) - op.create_foreign_key(None, 'eventorganizer', 'location', ['location_id'], ['id']) + op.add_column( + "eventorganizer", sa.Column("location_id", sa.Integer(), nullable=True) + ) + op.add_column("eventorganizer", sa.Column("logo_id", sa.Integer(), nullable=True)) + op.create_foreign_key(None, "eventorganizer", "image", ["logo_id"], ["id"]) + op.create_foreign_key(None, "eventorganizer", "location", ["location_id"], ["id"]) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_constraint(None, 'eventorganizer', type_='foreignkey') - op.drop_constraint(None, 'eventorganizer', type_='foreignkey') - op.drop_column('eventorganizer', 'logo_id') - op.drop_column('eventorganizer', 'location_id') + op.drop_constraint(None, "eventorganizer", type_="foreignkey") + op.drop_constraint(None, "eventorganizer", type_="foreignkey") + op.drop_column("eventorganizer", "logo_id") + op.drop_column("eventorganizer", "location_id") # ### end Alembic commands ### diff --git a/migrations/versions/ed6bb2084bbd_.py b/migrations/versions/ed6bb2084bbd_.py index cdcb04e..c9b639e 100644 --- a/migrations/versions/ed6bb2084bbd_.py +++ b/migrations/versions/ed6bb2084bbd_.py @@ -7,26 +7,29 @@ Create Date: 2020-07-08 08:53:44.373606 """ from alembic import op import sqlalchemy as sa -import sqlalchemy_utils -from project import dbtypes # revision identifiers, used by Alembic. -revision = 'ed6bb2084bbd' -down_revision = 'f1bc3fa623c7' +revision = "ed6bb2084bbd" +down_revision = "f1bc3fa623c7" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.add_column('event', sa.Column('previous_start_date', sa.DateTime(timezone=True), nullable=True)) - op.add_column('eventdate', sa.Column('end', sa.DateTime(timezone=True), nullable=True)) + op.add_column( + "event", + sa.Column("previous_start_date", sa.DateTime(timezone=True), nullable=True), + ) + op.add_column( + "eventdate", sa.Column("end", sa.DateTime(timezone=True), nullable=True) + ) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_column('eventdate', 'end') - op.drop_column('event', 'previous_start_date') + op.drop_column("eventdate", "end") + op.drop_column("event", "previous_start_date") # ### end Alembic commands ### diff --git a/migrations/versions/f1bc3fa623c7_.py b/migrations/versions/f1bc3fa623c7_.py index 11e5602..4a609c6 100644 --- a/migrations/versions/f1bc3fa623c7_.py +++ b/migrations/versions/f1bc3fa623c7_.py @@ -7,38 +7,53 @@ Create Date: 2020-07-07 15:49:58.653888 """ from alembic import op import sqlalchemy as sa -import sqlalchemy_utils from project import dbtypes from project.models import EventTargetGroupOrigin, EventAttendanceMode, EventStatus # revision identifiers, used by Alembic. -revision = 'f1bc3fa623c7' -down_revision = '75c07cb9cfe3' +revision = "f1bc3fa623c7" +down_revision = "75c07cb9cfe3" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.add_column('event', sa.Column('accessible_for_free', sa.Boolean(), nullable=True)) - op.add_column('event', sa.Column('age_from', sa.Integer(), nullable=True)) - op.add_column('event', sa.Column('age_to', sa.Integer(), nullable=True)) - op.add_column('event', sa.Column('attendance_mode', dbtypes.IntegerEnum(EventAttendanceMode), nullable=True)) - op.add_column('event', sa.Column('kid_friendly', sa.Boolean(), nullable=True)) - op.add_column('event', sa.Column('status', dbtypes.IntegerEnum(EventStatus), nullable=True)) - op.add_column('event', sa.Column('tags', sa.UnicodeText(), nullable=True)) - op.add_column('event', sa.Column('target_group_origin', dbtypes.IntegerEnum(EventTargetGroupOrigin), nullable=True)) + op.add_column( + "event", sa.Column("accessible_for_free", sa.Boolean(), nullable=True) + ) + op.add_column("event", sa.Column("age_from", sa.Integer(), nullable=True)) + op.add_column("event", sa.Column("age_to", sa.Integer(), nullable=True)) + op.add_column( + "event", + sa.Column( + "attendance_mode", dbtypes.IntegerEnum(EventAttendanceMode), nullable=True + ), + ) + op.add_column("event", sa.Column("kid_friendly", sa.Boolean(), nullable=True)) + op.add_column( + "event", sa.Column("status", dbtypes.IntegerEnum(EventStatus), nullable=True) + ) + op.add_column("event", sa.Column("tags", sa.UnicodeText(), nullable=True)) + op.add_column( + "event", + sa.Column( + "target_group_origin", + dbtypes.IntegerEnum(EventTargetGroupOrigin), + nullable=True, + ), + ) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_column('event', 'target_group_origin') - op.drop_column('event', 'tags') - op.drop_column('event', 'status') - op.drop_column('event', 'kid_friendly') - op.drop_column('event', 'attendance_mode') - op.drop_column('event', 'age_to') - op.drop_column('event', 'age_from') - op.drop_column('event', 'accessible_for_free') + op.drop_column("event", "target_group_origin") + op.drop_column("event", "tags") + op.drop_column("event", "status") + op.drop_column("event", "kid_friendly") + op.drop_column("event", "attendance_mode") + op.drop_column("event", "age_to") + op.drop_column("event", "age_from") + op.drop_column("event", "accessible_for_free") # ### end Alembic commands ### diff --git a/migrations/versions/f71c86333bfb_.py b/migrations/versions/f71c86333bfb_.py index 2950384..e5470e9 100644 --- a/migrations/versions/f71c86333bfb_.py +++ b/migrations/versions/f71c86333bfb_.py @@ -12,23 +12,29 @@ from project import dbtypes # revision identifiers, used by Alembic. -revision = 'f71c86333bfb' -down_revision = '4e913af88c33' +revision = "f71c86333bfb" +down_revision = "4e913af88c33" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.add_column('analytics', sa.Column('value1', sa.Unicode(length=255), nullable=True)) - op.add_column('analytics', sa.Column('value2', sa.Unicode(length=255), nullable=True)) - op.drop_column('analytics', 'value') + op.add_column( + "analytics", sa.Column("value1", sa.Unicode(length=255), nullable=True) + ) + op.add_column( + "analytics", sa.Column("value2", sa.Unicode(length=255), nullable=True) + ) + op.drop_column("analytics", "value") # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.add_column('analytics', sa.Column('value', sa.TEXT(), autoincrement=False, nullable=True)) - op.drop_column('analytics', 'value2') - op.drop_column('analytics', 'value1') + op.add_column( + "analytics", sa.Column("value", sa.TEXT(), autoincrement=False, nullable=True) + ) + op.drop_column("analytics", "value2") + op.drop_column("analytics", "value1") # ### end Alembic commands ### diff --git a/migrations/versions/fd7794ece0b3_.py b/migrations/versions/fd7794ece0b3_.py index 37281e5..97be003 100644 --- a/migrations/versions/fd7794ece0b3_.py +++ b/migrations/versions/fd7794ece0b3_.py @@ -12,36 +12,46 @@ from project import dbtypes # revision identifiers, used by Alembic. -revision = 'fd7794ece0b3' -down_revision = '975c22ae802b' +revision = "fd7794ece0b3" +down_revision = "975c22ae802b" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.create_table('eventplace', - sa.Column('created_at', sa.DateTime(), nullable=True), - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('name', sa.Unicode(length=255), nullable=False), - sa.Column('location_id', sa.Integer(), nullable=True), - sa.Column('photo_id', sa.Integer(), nullable=True), - sa.Column('url', sa.String(length=255), nullable=True), - sa.Column('description', sa.UnicodeText(), nullable=True), - sa.Column('created_by_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], ), - sa.ForeignKeyConstraint(['location_id'], ['location.id'], ), - sa.ForeignKeyConstraint(['photo_id'], ['image.id'], ), - sa.PrimaryKeyConstraint('id') + op.create_table( + "eventplace", + sa.Column("created_at", sa.DateTime(), nullable=True), + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("name", sa.Unicode(length=255), nullable=False), + sa.Column("location_id", sa.Integer(), nullable=True), + sa.Column("photo_id", sa.Integer(), nullable=True), + sa.Column("url", sa.String(length=255), nullable=True), + sa.Column("description", sa.UnicodeText(), nullable=True), + sa.Column("created_by_id", sa.Integer(), nullable=True), + sa.ForeignKeyConstraint( + ["created_by_id"], + ["user.id"], + ), + sa.ForeignKeyConstraint( + ["location_id"], + ["location.id"], + ), + sa.ForeignKeyConstraint( + ["photo_id"], + ["image.id"], + ), + sa.PrimaryKeyConstraint("id"), ) - op.add_column('event', sa.Column('event_place_id', sa.Integer(), nullable=True)) - op.create_foreign_key(None, 'event', 'place', ['event_place_id'], ['id']) + op.add_column("event", sa.Column("event_place_id", sa.Integer(), nullable=True)) + op.create_foreign_key(None, "event", "place", ["event_place_id"], ["id"]) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_constraint(None, 'event', type_='foreignkey') - op.drop_column('event', 'event_place_id') - op.drop_table('eventplace') + op.drop_constraint(None, "event", type_="foreignkey") + op.drop_column("event", "event_place_id") + op.drop_table("eventplace") # ### end Alembic commands ### diff --git a/project/__init__.py b/project/__init__.py index 1fb0caa..6f4026f 100644 --- a/project/__init__.py +++ b/project/__init__.py @@ -1,46 +1,45 @@ import os -from base64 import b64decode -from flask import jsonify, Flask, render_template, request, url_for, redirect, abort, flash, current_app +from flask import Flask from flask_sqlalchemy import SQLAlchemy -from sqlalchemy.orm import joinedload -from sqlalchemy.sql import asc, func -from sqlalchemy import and_, or_, not_, event -from flask_security import Security, current_user, auth_required, roles_required, SQLAlchemySessionUserDatastore -from flask_security.utils import FsPermNeed -from flask_babelex import Babel, gettext, lazy_gettext, format_datetime, to_user_timezone -from flask_principal import Permission +from flask_security import ( + Security, + SQLAlchemySessionUserDatastore, +) +from flask_babelex import Babel from flask_cors import CORS -import pytz -import json from flask_qrcode import QRcode -from flask_mail import Mail, Message, email_dispatched +from flask_mail import Mail, email_dispatched # Create app app = Flask(__name__) -app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URL'] -app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False -app.config['SECURITY_CONFIRMABLE'] = False -app.config['SECURITY_TRACKABLE'] = True -app.config['SECURITY_REGISTERABLE'] = True -app.config['SECURITY_SEND_REGISTER_EMAIL'] = False -app.config['SECURITY_RECOVERABLE'] = True -app.config['SECURITY_CHANGEABLE'] = True -app.config['SECURITY_EMAIL_SENDER'] = os.getenv("MAIL_DEFAULT_SENDER") -app.config['LANGUAGES'] = ['en', 'de'] -app.config['GOOGLE_OAUTH_CLIENT_ID'] = os.getenv('GOOGLE_OAUTH_CLIENT_ID') -app.config['GOOGLE_OAUTH_CLIENT_SECRET'] = os.getenv('GOOGLE_OAUTH_CLIENT_SECRET') -app.config['OAUTHLIB_INSECURE_TRANSPORT'] = True -app.config['OAUTHLIB_RELAX_TOKEN_SCOPE'] = True +app.config["SQLALCHEMY_DATABASE_URI"] = os.environ["DATABASE_URL"] +app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False +app.config["SECURITY_CONFIRMABLE"] = False +app.config["SECURITY_TRACKABLE"] = True +app.config["SECURITY_REGISTERABLE"] = True +app.config["SECURITY_SEND_REGISTER_EMAIL"] = False +app.config["SECURITY_RECOVERABLE"] = True +app.config["SECURITY_CHANGEABLE"] = True +app.config["SECURITY_EMAIL_SENDER"] = os.getenv("MAIL_DEFAULT_SENDER") +app.config["LANGUAGES"] = ["en", "de"] +app.config["GOOGLE_OAUTH_CLIENT_ID"] = os.getenv("GOOGLE_OAUTH_CLIENT_ID") +app.config["GOOGLE_OAUTH_CLIENT_SECRET"] = os.getenv("GOOGLE_OAUTH_CLIENT_SECRET") +app.config["OAUTHLIB_INSECURE_TRANSPORT"] = True +app.config["OAUTHLIB_RELAX_TOKEN_SCOPE"] = True # Generate a nice key using secrets.token_urlsafe() -app.config['SECRET_KEY'] = os.environ.get("SECRET_KEY", 'pf9Wkove4IKEAXvy-cQkeDPhv9Cb3Ag-wyJILbq_dFw') +app.config["SECRET_KEY"] = os.environ.get( + "SECRET_KEY", "pf9Wkove4IKEAXvy-cQkeDPhv9Cb3Ag-wyJILbq_dFw" +) # Bcrypt is set as default SECURITY_PASSWORD_HASH, which requires a salt # Generate a good salt using: secrets.SystemRandom().getrandbits(128) -app.config['SECURITY_PASSWORD_SALT'] = os.environ.get("SECURITY_PASSWORD_SALT", '146585145368132386173505678016728509634') +app.config["SECURITY_PASSWORD_SALT"] = os.environ.get( + "SECURITY_PASSWORD_SALT", "146585145368132386173505678016728509634" +) # i18n -app.config['BABEL_DEFAULT_LOCALE'] = 'de' -app.config['BABEL_DEFAULT_TIMEZONE'] = 'Europe/Berlin' +app.config["BABEL_DEFAULT_LOCALE"] = "de" +app.config["BABEL_DEFAULT_TIMEZONE"] = "Europe/Berlin" babel = Babel(app) # cors @@ -50,24 +49,26 @@ cors = CORS(app, resources={r"/api/*": {"origins": "*"}}) mail_server = os.getenv("MAIL_SERVER") if mail_server is None: - app.config['MAIL_SUPPRESS_SEND'] = True - app.config['MAIL_DEFAULT_SENDER'] = 'test@oveda.de' + app.config["MAIL_SUPPRESS_SEND"] = True + app.config["MAIL_DEFAULT_SENDER"] = "test@oveda.de" else: - app.config['MAIL_SUPPRESS_SEND'] = False - app.config['MAIL_SERVER'] = mail_server - app.config['MAIL_PORT'] = os.getenv("MAIL_PORT") - app.config['MAIL_USE_TLS'] = os.getenv("MAIL_USE_TLS", True) - app.config['MAIL_USE_SSL'] = os.getenv("MAIL_USE_SSL", False) - app.config['MAIL_USERNAME'] = os.getenv("MAIL_USERNAME") - app.config['MAIL_PASSWORD'] = os.getenv("MAIL_PASSWORD") - app.config['MAIL_DEFAULT_SENDER'] = os.getenv("MAIL_DEFAULT_SENDER") + app.config["MAIL_SUPPRESS_SEND"] = False + app.config["MAIL_SERVER"] = mail_server + app.config["MAIL_PORT"] = os.getenv("MAIL_PORT") + app.config["MAIL_USE_TLS"] = os.getenv("MAIL_USE_TLS", True) + app.config["MAIL_USE_SSL"] = os.getenv("MAIL_USE_SSL", False) + app.config["MAIL_USERNAME"] = os.getenv("MAIL_USERNAME") + app.config["MAIL_PASSWORD"] = os.getenv("MAIL_PASSWORD") + app.config["MAIL_DEFAULT_SENDER"] = os.getenv("MAIL_DEFAULT_SENDER") mail = Mail(app) -if app.config['MAIL_SUPPRESS_SEND']: +if app.config["MAIL_SUPPRESS_SEND"]: + def log_message(message, app): print(message.subject) print(message.body) + email_dispatched.connect(log_message) # Create db @@ -78,20 +79,23 @@ QRcode(app) # JSON from project.jsonld import DateTimeEncoder + app.json_encoder = DateTimeEncoder # Setup Flask-Security from project.models import User, Role + user_datastore = SQLAlchemySessionUserDatastore(db.session, User, Role) security = Security(app, user_datastore) # OAuth from project.oauth import blueprint + app.register_blueprint(blueprint, url_prefix="/login") -from project.i10n import * -from project.jinja_filters import * -from project.init_data import * +from project import i10n +from project import jinja_filters +from project import init_data # Routes from project.views import ( @@ -113,8 +117,8 @@ from project.views import ( reference_request_review, root, user, - widget + widget, ) -if __name__ == '__main__': - app.run() \ No newline at end of file +if __name__ == "__main__": + app.run() diff --git a/project/access.py b/project/access.py index d860af8..b1f6fce 100644 --- a/project/access.py +++ b/project/access.py @@ -4,23 +4,29 @@ from flask_security.utils import FsPermNeed from flask_principal import Permission from project.models import AdminUnitMember, AdminUnit + def has_current_user_permission(permission): user_perm = Permission(FsPermNeed(permission)) return user_perm.can() + def has_admin_unit_member_permission(admin_unit_member, permission): for role in admin_unit_member.roles: if permission in role.get_permissions(): return True return False + def has_current_user_member_permission_for_admin_unit(admin_unit_id, permission): - admin_unit_member = AdminUnitMember.query.filter_by(admin_unit_id=admin_unit_id, user_id=current_user.id).first() + admin_unit_member = AdminUnitMember.query.filter_by( + admin_unit_id=admin_unit_id, user_id=current_user.id + ).first() if admin_unit_member is not None: if has_admin_unit_member_permission(admin_unit_member, permission): return True return False + def has_current_user_permission_for_admin_unit(admin_unit, permission): if not current_user.is_authenticated: return False @@ -33,40 +39,54 @@ def has_current_user_permission_for_admin_unit(admin_unit, permission): return False + def has_access(admin_unit, permission): return has_current_user_permission_for_admin_unit(admin_unit, permission) + def access_or_401(admin_unit, permission): if not has_access(admin_unit, permission): abort(401) + def can_list_admin_unit_members(admin_unit): - return has_current_user_permission_for_admin_unit(admin_unit, 'admin_unit.members:read') + return has_current_user_permission_for_admin_unit( + admin_unit, "admin_unit.members:read" + ) + def can_create_event(admin_unit): - return has_current_user_permission_for_admin_unit(admin_unit, 'event:create') + return has_current_user_permission_for_admin_unit(admin_unit, "event:create") + def can_update_event(event): - return has_current_user_permission_for_admin_unit(event.admin_unit, 'event:update') + return has_current_user_permission_for_admin_unit(event.admin_unit, "event:update") + def can_delete_event(event): - return has_current_user_permission_for_admin_unit(event.admin_unit, 'event:delete') + return has_current_user_permission_for_admin_unit(event.admin_unit, "event:delete") + def can_reference_event(event): return len(get_admin_units_for_event_reference(event)) > 0 + def can_update_organizer(organizer): return get_admin_unit_for_manage(organizer.admin_unit_id) is not None + def can_create_admin_unit(): return current_user.is_authenticated + def can_verify_event_for_admin_unit(admin_unit): - return has_current_user_permission_for_admin_unit(admin_unit, 'event:verify') + return has_current_user_permission_for_admin_unit(admin_unit, "event:verify") + def can_verify_event(event): return can_verify_event_for_admin_unit(event.admin_unit) + def get_admin_units_with_current_user_permission(permission): result = list() @@ -77,41 +97,48 @@ def get_admin_units_with_current_user_permission(permission): return result + def get_admin_units_for_event_reference(event): result = list() - admin_units = get_admin_units_with_current_user_permission('event:reference') + admin_units = get_admin_units_with_current_user_permission("event:reference") for admin_unit in admin_units: if admin_unit.id != event.admin_unit_id: result.append(admin_unit) return result + def admin_units_the_current_user_is_member_of(): result = list() if current_user.is_authenticated: - admin_unit_members = AdminUnitMember.query.filter_by(user_id=current_user.id).all() + admin_unit_members = AdminUnitMember.query.filter_by( + user_id=current_user.id + ).all() for admin_unit_member in admin_unit_members: result.append(admin_unit_member.adminunit) return result + def get_admin_units_for_manage(): # Global admin - if current_user.has_role('admin'): + if current_user.has_role("admin"): return AdminUnit.query.all() return admin_units_the_current_user_is_member_of() + def get_admin_unit_for_manage(admin_unit_id): admin_units = get_admin_units_for_manage() return next((au for au in admin_units if au.id == admin_unit_id), None) + def get_admin_unit_for_manage_or_404(admin_unit_id): admin_unit = get_admin_unit_for_manage(admin_unit_id) if not admin_unit: abort(404) - return admin_unit \ No newline at end of file + return admin_unit diff --git a/project/dateutils.py b/project/dateutils.py index 404d78c..58d6013 100644 --- a/project/dateutils.py +++ b/project/dateutils.py @@ -1,41 +1,58 @@ import pytz -from dateutil import rrule -from dateutil.rrule import rrulestr, rruleset, rrule +from dateutil.rrule import rrulestr from datetime import datetime from dateutil.relativedelta import relativedelta -berlin_tz = pytz.timezone('Europe/Berlin') +berlin_tz = pytz.timezone("Europe/Berlin") now = datetime.now(tz=berlin_tz) today = datetime(now.year, now.month, now.day, tzinfo=now.tzinfo) -def create_berlin_date(year, month, day, hour, minute = 0): + +def create_berlin_date(year, month, day, hour, minute=0): return berlin_tz.localize(datetime(year, month, day, hour=hour, minute=minute)) + def date_add_time(date, hour=0, minute=0, second=0, tzinfo=None): - return datetime(date.year, date.month, date.day, hour=hour, minute=minute, second=second, tzinfo=tzinfo) + return datetime( + date.year, + date.month, + date.day, + hour=hour, + minute=minute, + second=second, + tzinfo=tzinfo, + ) + def date_set_end_of_day(date): return date_add_time(date, hour=23, minute=59, second=59) + def form_input_to_date(date_str, hour=0, minute=0, second=0): date = datetime.strptime(date_str, "%Y-%m-%d") date_time = date_add_time(date, hour=hour, minute=minute, second=second) return berlin_tz.localize(date_time) + def form_input_from_date(date): return date.strftime("%Y-%m-%d") + def dates_from_recurrence_rule(start, recurrence_rule): result = list() - adv_recurrence_rule = recurrence_rule.replace('T000000', 'T235959') + adv_recurrence_rule = recurrence_rule.replace("T000000", "T235959") start_wo_tz = start.replace(tzinfo=None) rule_set = rrulestr(adv_recurrence_rule, forceset=True, dtstart=start_wo_tz) start_date = start_wo_tz end_date = start_date + relativedelta(years=1) - start_date_begin_of_day = datetime(start_date.year, start_date.month, start_date.day) - end_date_end_of_day = datetime(end_date.year, end_date.month, end_date.day, hour=23, minute=59, second=59) + start_date_begin_of_day = datetime( + start_date.year, start_date.month, start_date.day + ) + end_date_end_of_day = datetime( + end_date.year, end_date.month, end_date.day, hour=23, minute=59, second=59 + ) for rule_date in rule_set.between(start_date_begin_of_day, end_date_end_of_day): rule_data_w_tz = berlin_tz.localize(rule_date) @@ -43,7 +60,9 @@ def dates_from_recurrence_rule(start, recurrence_rule): return result -BATCH_DELTA = 3 # How many batches to show before + after current batch + +BATCH_DELTA = 3 # How many batches to show before + after current batch + def calculate_occurrences(start_date, date_format, rrule_str, start, batch_size): # TODO: Return error on failure @@ -53,9 +72,9 @@ def calculate_occurrences(start_date, date_format, rrule_str, start, batch_size) iterator = iter(rule) cur_batch = start // batch_size - start = cur_batch * batch_size # Avoid stupid start-values + start = cur_batch * batch_size # Avoid stupid start-values - if hasattr(rule, '_exdate'): + if hasattr(rule, "_exdate"): exdates = sorted(rule._exdate) else: exdates = [] @@ -79,13 +98,17 @@ def calculate_occurrences(start_date, date_format, rrule_str, start, batch_size) else: # include them exdate = exdates.pop(0) - occurrences.append({'date': exdate.strftime('%Y%m%dT%H%M%S'), - 'formattedDate': exdate.strftime(date_format), - 'type': 'exdate',}) + occurrences.append( + { + "date": exdate.strftime("%Y%m%dT%H%M%S"), + "formattedDate": exdate.strftime(date_format), + "type": "exdate", + } + ) i += 1 if i >= batch_size + start: - break # We are done! + break # We are done! i += 1 if i <= start: @@ -93,24 +116,32 @@ def calculate_occurrences(start_date, date_format, rrule_str, start, batch_size) continue # Add it to the results - if date in getattr(rule, '_rdate', []): - occurrence_type = 'rdate' + if date in getattr(rule, "_rdate", []): + occurrence_type = "rdate" elif date == start_date: - occurrence_type = 'start' + occurrence_type = "start" else: - occurrence_type = 'rrule' - occurrences.append({'date': date.strftime('%Y%m%dT%H%M%S'), - 'formattedDate': date.strftime(date_format), - 'type': occurrence_type,}) + occurrence_type = "rrule" + occurrences.append( + { + "date": date.strftime("%Y%m%dT%H%M%S"), + "formattedDate": date.strftime(date_format), + "type": occurrence_type, + } + ) while exdates: # There are exdates that are after the end of the recurrence. # Excluding the last dates make no sense, as you can change the # range instead, but we need to support it anyway. exdate = exdates.pop(0) - occurrences.append({'date': exdate.strftime('%Y%m%dT%H%M%S'), - 'formattedDate': exdate.strftime(date_format), - 'type': 'exdate',}) + occurrences.append( + { + "date": exdate.strftime("%Y%m%dT%H%M%S"), + "formattedDate": exdate.strftime(date_format), + "type": "exdate", + } + ) # Calculate no of occurrences, but only to a max of three times # the batch size. This will support infinite recurrence in a @@ -132,18 +163,21 @@ def calculate_occurrences(start_date, date_format, rrule_str, start, batch_size) # Total number of occurrences: num_occurrences += batch_size + start - max_batch = (num_occurrences - 1)//batch_size + max_batch = (num_occurrences - 1) // batch_size if last_batch > max_batch: last_batch = max_batch first_batch = max(0, max_batch - (BATCH_DELTA * 2)) - batches = [((x * batch_size) + 1, (x + 1) * batch_size) for x in range(first_batch, last_batch + 1)] - batch_data = {'start': start, - 'end': num_occurrences, - 'batch_size': batch_size, - 'batches': batches, - 'currentBatch': cur_batch - first_batch, - } - - return {'occurrences': occurrences, 'batch': batch_data} + batches = [ + ((x * batch_size) + 1, (x + 1) * batch_size) + for x in range(first_batch, last_batch + 1) + ] + batch_data = { + "start": start, + "end": num_occurrences, + "batch_size": batch_size, + "batches": batches, + "currentBatch": cur_batch - first_batch, + } + return {"occurrences": occurrences, "batch": batch_data} diff --git a/project/dbtypes.py b/project/dbtypes.py index 536092c..311aa72 100644 --- a/project/dbtypes.py +++ b/project/dbtypes.py @@ -1,8 +1,10 @@ from sqlalchemy.types import TypeDecorator from sqlalchemy import Integer + class IntegerEnum(TypeDecorator): impl = Integer + def __init__(self, enumtype, *args, **kwargs): super().__init__(*args, **kwargs) self._enumtype = enumtype diff --git a/project/forms/admin_unit.py b/project/forms/admin_unit.py index e1d8903..7bcb205 100644 --- a/project/forms/admin_unit.py +++ b/project/forms/admin_unit.py @@ -1,49 +1,90 @@ from flask_babelex import lazy_gettext from flask_wtf import FlaskForm -from flask_wtf.file import FileField, FileAllowed -from wtforms import StringField, SubmitField, DecimalField, TextAreaField, FormField, SelectField +from wtforms import ( + StringField, + SubmitField, + DecimalField, + FormField, +) from wtforms.fields.html5 import EmailField, TelField, URLField from wtforms.validators import DataRequired, Optional, Regexp from wtforms.widgets.html5 import ColorInput -import decimal from project.models import Location, Image from project.forms.common import FileImageForm + class AdminUnitLocationForm(FlaskForm): - street = StringField(lazy_gettext('Street'), validators=[Optional()]) - postalCode = StringField(lazy_gettext('Postal code'), validators=[DataRequired()]) - city = StringField(lazy_gettext('City'), validators=[DataRequired()]) - state = StringField(lazy_gettext('State'), validators=[Optional()]) - latitude = DecimalField(lazy_gettext('Latitude'), places=16, validators=[Optional()]) - longitude = DecimalField(lazy_gettext('Longitude'), places=16, validators=[Optional()]) + street = StringField(lazy_gettext("Street"), validators=[Optional()]) + postalCode = StringField(lazy_gettext("Postal code"), validators=[DataRequired()]) + city = StringField(lazy_gettext("City"), validators=[DataRequired()]) + state = StringField(lazy_gettext("State"), validators=[Optional()]) + latitude = DecimalField( + lazy_gettext("Latitude"), places=16, validators=[Optional()] + ) + longitude = DecimalField( + lazy_gettext("Longitude"), places=16, validators=[Optional()] + ) + class BaseAdminUnitForm(FlaskForm): - name = StringField(lazy_gettext('Name'), validators=[DataRequired()]) - short_name = StringField(lazy_gettext('Short name'), description=lazy_gettext('The short name is used to create a unique identifier for your events'), validators=[DataRequired(), Regexp('^\w+$', message=lazy_gettext("Short name must contain only letters numbers or underscore"))]) - url = URLField(lazy_gettext('Link URL'), validators=[Optional()]) - email = EmailField(lazy_gettext('Email'), validators=[Optional()]) - phone = TelField(lazy_gettext('Phone'), validators=[Optional()]) - fax = TelField(lazy_gettext('Fax'), validators=[Optional()]) - logo = FormField(FileImageForm, lazy_gettext('Logo'), default=lambda: Image()) + name = StringField(lazy_gettext("Name"), validators=[DataRequired()]) + short_name = StringField( + lazy_gettext("Short name"), + description=lazy_gettext( + "The short name is used to create a unique identifier for your events" + ), + validators=[ + DataRequired(), + Regexp( + r"^\w+$", + message=lazy_gettext( + "Short name must contain only letters numbers or underscore" + ), + ), + ], + ) + url = URLField(lazy_gettext("Link URL"), validators=[Optional()]) + email = EmailField(lazy_gettext("Email"), validators=[Optional()]) + phone = TelField(lazy_gettext("Phone"), validators=[Optional()]) + fax = TelField(lazy_gettext("Fax"), validators=[Optional()]) + logo = FormField(FileImageForm, lazy_gettext("Logo"), default=lambda: Image()) location = FormField(AdminUnitLocationForm, default=lambda: Location()) def populate_obj(self, obj): for name, field in self._fields.items(): - if name == 'location' and not obj.location: + if name == "location" and not obj.location: obj.location = Location() - elif name == 'logo' and not obj.logo: + elif name == "logo" and not obj.logo: obj.logo = Image() field.populate_obj(obj, name) + class CreateAdminUnitForm(BaseAdminUnitForm): submit = SubmitField(lazy_gettext("Create admin unit")) + class UpdateAdminUnitForm(BaseAdminUnitForm): submit = SubmitField(lazy_gettext("Update settings")) + class UpdateAdminUnitWidgetForm(FlaskForm): - widget_font = StringField(lazy_gettext('Font'), validators=[Optional()]) - widget_background_color = StringField(lazy_gettext('Background Color'), default='#ffffff', widget=ColorInput(), validators=[Optional()]) - widget_primary_color = StringField(lazy_gettext('Primary Color'), default='#007bff', widget=ColorInput(), validators=[Optional()]) - widget_link_color = StringField(lazy_gettext('Link Color'), default='#007bff', widget=ColorInput(), validators=[Optional()]) - submit = SubmitField(lazy_gettext("Update settings")) \ No newline at end of file + widget_font = StringField(lazy_gettext("Font"), validators=[Optional()]) + widget_background_color = StringField( + lazy_gettext("Background Color"), + default="#ffffff", + widget=ColorInput(), + validators=[Optional()], + ) + widget_primary_color = StringField( + lazy_gettext("Primary Color"), + default="#007bff", + widget=ColorInput(), + validators=[Optional()], + ) + widget_link_color = StringField( + lazy_gettext("Link Color"), + default="#007bff", + widget=ColorInput(), + validators=[Optional()], + ) + submit = SubmitField(lazy_gettext("Update settings")) diff --git a/project/forms/admin_unit_member.py b/project/forms/admin_unit_member.py index e6a1a80..e13e7d8 100644 --- a/project/forms/admin_unit_member.py +++ b/project/forms/admin_unit_member.py @@ -1,31 +1,32 @@ from flask_babelex import lazy_gettext from flask_wtf import FlaskForm -from flask_wtf.file import FileField, FileAllowed -from wtforms import StringField, SubmitField, DecimalField, TextAreaField, FormField, SelectField -from wtforms.fields.html5 import EmailField, TelField -from wtforms.validators import DataRequired, Optional, Regexp -import decimal -from project.models import Location +from wtforms import SubmitField +from wtforms.fields.html5 import EmailField +from wtforms.validators import DataRequired from project.forms.widgets import MultiCheckboxField + class InviteAdminUnitMemberForm(FlaskForm): - email = EmailField(lazy_gettext('Email'), validators=[DataRequired()]) - roles = MultiCheckboxField(lazy_gettext('Roles')) + email = EmailField(lazy_gettext("Email"), validators=[DataRequired()]) + roles = MultiCheckboxField(lazy_gettext("Roles")) submit = SubmitField(lazy_gettext("Invite")) + class NegotiateAdminUnitMemberInvitationForm(FlaskForm): accept = SubmitField(lazy_gettext("Accept")) decline = SubmitField(lazy_gettext("Decline")) + class DeleteAdminUnitInvitationForm(FlaskForm): submit = SubmitField(lazy_gettext("Delete invitation")) - email = EmailField(lazy_gettext('Email'), validators=[DataRequired()]) + email = EmailField(lazy_gettext("Email"), validators=[DataRequired()]) + class DeleteAdminUnitMemberForm(FlaskForm): submit = SubmitField(lazy_gettext("Delete member")) - email = EmailField(lazy_gettext('Email'), validators=[DataRequired()]) + email = EmailField(lazy_gettext("Email"), validators=[DataRequired()]) + class UpdateAdminUnitMemberForm(FlaskForm): - roles = MultiCheckboxField(lazy_gettext('Roles')) + roles = MultiCheckboxField(lazy_gettext("Roles")) submit = SubmitField(lazy_gettext("Update member")) - diff --git a/project/forms/common.py b/project/forms/common.py index 1fc04ec..5ad8265 100644 --- a/project/forms/common.py +++ b/project/forms/common.py @@ -2,16 +2,25 @@ from flask_babelex import lazy_gettext from flask_wtf import FlaskForm from flask_wtf.file import FileField, FileAllowed from wtforms import StringField, BooleanField, HiddenField -from wtforms.validators import DataRequired, Optional +from wtforms.validators import Optional import re import base64 + class BaseImageForm(FlaskForm): - copyright_text = StringField(lazy_gettext('Copyright text'), validators=[Optional()]) + copyright_text = StringField( + lazy_gettext("Copyright text"), validators=[Optional()] + ) + class FileImageForm(BaseImageForm): - image_file = FileField(lazy_gettext('File'), validators=[FileAllowed(['jpg', 'jpeg', 'png'], lazy_gettext('Images only!'))]) - delete_flag = BooleanField(lazy_gettext('Delete image'), default=False, validators=[Optional()]) + image_file = FileField( + lazy_gettext("File"), + validators=[FileAllowed(["jpg", "jpeg", "png"], lazy_gettext("Images only!"))], + ) + delete_flag = BooleanField( + lazy_gettext("Delete image"), default=False, validators=[Optional()] + ) def populate_obj(self, obj): super(BaseImageForm, self).populate_obj(obj) @@ -24,6 +33,7 @@ class FileImageForm(BaseImageForm): obj.data = None obj.encoding_format = None + class Base64ImageForm(BaseImageForm): image_base64 = HiddenField() @@ -31,8 +41,10 @@ class Base64ImageForm(BaseImageForm): super(BaseImageForm, self).process(formdata, obj, data, **kwargs) if self.image_base64.data is None and obj and obj.data: - base64_str = base64.b64encode(obj.data).decode('utf-8') - self.image_base64.data = 'data:{};base64,{}'.format(obj.encoding_format, base64_str) + base64_str = base64.b64encode(obj.data).decode("utf-8") + self.image_base64.data = "data:{};base64,{}".format( + obj.encoding_format, base64_str + ) def populate_obj(self, obj): super(BaseImageForm, self).populate_obj(obj) @@ -49,35 +61,36 @@ class Base64ImageForm(BaseImageForm): obj.data = None obj.encoding_format = None + event_rating_choices = [ - (0,lazy_gettext('0 (Little relevant)')), - (10,'1'), - (20,'2'), - (30,'3'), - (40,'4'), - (50,'5'), - (60,'6'), - (70,'7'), - (80,'8'), - (90,'9'), - (100,lazy_gettext('10 (Highlight)')) - ] + (0, lazy_gettext("0 (Little relevant)")), + (10, "1"), + (20, "2"), + (30, "3"), + (40, "4"), + (50, "5"), + (60, "6"), + (70, "7"), + (80, "8"), + (90, "9"), + (100, lazy_gettext("10 (Highlight)")), +] weekday_choices = [ - (1,lazy_gettext('Monday')), - (2,lazy_gettext('Tueday')), - (3,lazy_gettext('Wednesday')), - (4,lazy_gettext('Thursday')), - (5,lazy_gettext('Friday')), - (6,lazy_gettext('Saturday')), - (0,lazy_gettext('Sunday')) - ] + (1, lazy_gettext("Monday")), + (2, lazy_gettext("Tueday")), + (3, lazy_gettext("Wednesday")), + (4, lazy_gettext("Thursday")), + (5, lazy_gettext("Friday")), + (6, lazy_gettext("Saturday")), + (0, lazy_gettext("Sunday")), +] distance_choices = [ - (500,lazy_gettext('500 m')), - (5000,lazy_gettext('5 km')), - (10000,lazy_gettext('10 km')), - (25000,lazy_gettext('20 km')), - (50000,lazy_gettext('50 km')), - (100000,lazy_gettext('100 km')) - ] + (500, lazy_gettext("500 m")), + (5000, lazy_gettext("5 km")), + (10000, lazy_gettext("10 km")), + (25000, lazy_gettext("20 km")), + (50000, lazy_gettext("50 km")), + (100000, lazy_gettext("100 km")), +] diff --git a/project/forms/event.py b/project/forms/event.py index 4730e42..4bae0ec 100644 --- a/project/forms/event.py +++ b/project/forms/event.py @@ -1,100 +1,183 @@ from flask import request from flask_babelex import lazy_gettext, gettext from flask_wtf import FlaskForm -from flask_wtf.file import FileField, FileAllowed -from wtforms import SelectMultipleField, FieldList, RadioField, DateTimeField, StringField, SubmitField, TextAreaField, SelectField, BooleanField, IntegerField, FormField -from wtforms.fields.html5 import DateTimeLocalField, EmailField, URLField +from wtforms import ( + SelectMultipleField, + RadioField, + StringField, + SubmitField, + TextAreaField, + SelectField, + BooleanField, + IntegerField, + FormField, +) +from wtforms.fields.html5 import EmailField, URLField from wtforms.validators import DataRequired, Optional -from wtforms.widgets import html_params, HTMLString -from project.models import EventPlace, EventTargetGroupOrigin, EventAttendanceMode, EventStatus, Location, EventOrganizer, EventRejectionReason, EventReviewStatus, Image +from project.models import ( + EventPlace, + EventTargetGroupOrigin, + EventAttendanceMode, + EventStatus, + Location, + EventOrganizer, + Image, +) from project.forms.common import event_rating_choices, Base64ImageForm from project.forms.widgets import CustomDateTimeField, CustomDateField + class EventPlaceLocationForm(FlaskForm): - street = StringField(lazy_gettext('Street'), validators=[Optional()]) - postalCode = StringField(lazy_gettext('Postal code'), validators=[Optional()]) - city = StringField(lazy_gettext('City'), validators=[Optional()]) + street = StringField(lazy_gettext("Street"), validators=[Optional()]) + postalCode = StringField(lazy_gettext("Postal code"), validators=[Optional()]) + city = StringField(lazy_gettext("City"), validators=[Optional()]) + class EventPlaceForm(FlaskForm): - name = StringField(lazy_gettext('Name'), validators=[Optional()]) + name = StringField(lazy_gettext("Name"), validators=[Optional()]) location = FormField(EventPlaceLocationForm, default=lambda: Location()) def populate_obj(self, obj): for name, field in self._fields.items(): - if name == 'location' and not obj.location: + if name == "location" and not obj.location: obj.location = Location() field.populate_obj(obj, name) + class OrganizerForm(EventPlaceForm): pass + class EventOrganizerForm(FlaskForm): - name = StringField(lazy_gettext('Organizator'), validators=[Optional()]) - url = URLField(lazy_gettext('Link URL'), validators=[Optional()]) - email = EmailField(lazy_gettext('Email'), validators=[Optional()]) - phone = StringField(lazy_gettext('Phone'), validators=[Optional()]) - fax = StringField(lazy_gettext('Fax'), validators=[Optional()]) + name = StringField(lazy_gettext("Organizator"), validators=[Optional()]) + url = URLField(lazy_gettext("Link URL"), validators=[Optional()]) + email = EmailField(lazy_gettext("Email"), validators=[Optional()]) + phone = StringField(lazy_gettext("Phone"), validators=[Optional()]) + fax = StringField(lazy_gettext("Fax"), validators=[Optional()]) + class BaseEventForm(FlaskForm): - name = StringField(lazy_gettext('Name'), validators=[DataRequired()]) - external_link = URLField(lazy_gettext('Link URL'), validators=[Optional()]) - ticket_link = StringField(lazy_gettext('Ticket Link URL'), validators=[Optional()]) - description = TextAreaField(lazy_gettext('Description'), validators=[DataRequired()]) - recurrence_rule = TextAreaField(lazy_gettext('Recurrence rule'), validators=[Optional()]) - start = CustomDateTimeField(lazy_gettext('Start'), validators=[DataRequired()]) - end = CustomDateTimeField(lazy_gettext('End'), validators=[Optional()]) - previous_start_date = CustomDateTimeField(lazy_gettext('Previous start date'), validators=[Optional()]) - tags = StringField(lazy_gettext('Tags'), validators=[Optional()]) - category_ids = SelectMultipleField(lazy_gettext('Categories'), validators=[DataRequired()], coerce=int) + name = StringField(lazy_gettext("Name"), validators=[DataRequired()]) + external_link = URLField(lazy_gettext("Link URL"), validators=[Optional()]) + ticket_link = StringField(lazy_gettext("Ticket Link URL"), validators=[Optional()]) + description = TextAreaField( + lazy_gettext("Description"), validators=[DataRequired()] + ) + recurrence_rule = TextAreaField( + lazy_gettext("Recurrence rule"), validators=[Optional()] + ) + start = CustomDateTimeField(lazy_gettext("Start"), validators=[DataRequired()]) + end = CustomDateTimeField(lazy_gettext("End"), validators=[Optional()]) + previous_start_date = CustomDateTimeField( + lazy_gettext("Previous start date"), validators=[Optional()] + ) + tags = StringField(lazy_gettext("Tags"), validators=[Optional()]) + category_ids = SelectMultipleField( + lazy_gettext("Categories"), validators=[DataRequired()], coerce=int + ) - kid_friendly = BooleanField(lazy_gettext('Kid friendly'), validators=[Optional()]) - accessible_for_free = BooleanField(lazy_gettext('Accessible for free'), validators=[Optional()]) - age_from = IntegerField(lazy_gettext('Typical Age from'), validators=[Optional()]) - age_to = IntegerField(lazy_gettext('Typical Age to'), validators=[Optional()]) - registration_required = BooleanField(lazy_gettext('Registration required'), validators=[Optional()]) - booked_up = BooleanField(lazy_gettext('Booked up'), validators=[Optional()]) - expected_participants = IntegerField(lazy_gettext('Expected number of participants'), validators=[Optional()]) - price_info = TextAreaField(lazy_gettext('Price info'), validators=[Optional()]) + kid_friendly = BooleanField(lazy_gettext("Kid friendly"), validators=[Optional()]) + accessible_for_free = BooleanField( + lazy_gettext("Accessible for free"), validators=[Optional()] + ) + age_from = IntegerField(lazy_gettext("Typical Age from"), validators=[Optional()]) + age_to = IntegerField(lazy_gettext("Typical Age to"), validators=[Optional()]) + registration_required = BooleanField( + lazy_gettext("Registration required"), validators=[Optional()] + ) + booked_up = BooleanField(lazy_gettext("Booked up"), validators=[Optional()]) + expected_participants = IntegerField( + lazy_gettext("Expected number of participants"), validators=[Optional()] + ) + price_info = TextAreaField(lazy_gettext("Price info"), validators=[Optional()]) - target_group_origin = SelectField(lazy_gettext('Target group origin'), coerce=int, choices=[ - (int(EventTargetGroupOrigin.both), lazy_gettext('EventTargetGroupOrigin.both')), - (int(EventTargetGroupOrigin.tourist), lazy_gettext('EventTargetGroupOrigin.tourist')), - (int(EventTargetGroupOrigin.resident), lazy_gettext('EventTargetGroupOrigin.resident'))]) + target_group_origin = SelectField( + lazy_gettext("Target group origin"), + coerce=int, + choices=[ + ( + int(EventTargetGroupOrigin.both), + lazy_gettext("EventTargetGroupOrigin.both"), + ), + ( + int(EventTargetGroupOrigin.tourist), + lazy_gettext("EventTargetGroupOrigin.tourist"), + ), + ( + int(EventTargetGroupOrigin.resident), + lazy_gettext("EventTargetGroupOrigin.resident"), + ), + ], + ) - attendance_mode = SelectField(lazy_gettext('Attendance mode'), coerce=int, choices=[ - (int(EventAttendanceMode.offline), lazy_gettext('EventAttendanceMode.offline')), - (int(EventAttendanceMode.online), lazy_gettext('EventAttendanceMode.online')), - (int(EventAttendanceMode.mixed), lazy_gettext('EventAttendanceMode.mixed'))]) + attendance_mode = SelectField( + lazy_gettext("Attendance mode"), + coerce=int, + choices=[ + ( + int(EventAttendanceMode.offline), + lazy_gettext("EventAttendanceMode.offline"), + ), + ( + int(EventAttendanceMode.online), + lazy_gettext("EventAttendanceMode.online"), + ), + (int(EventAttendanceMode.mixed), lazy_gettext("EventAttendanceMode.mixed")), + ], + ) + + photo = FormField(Base64ImageForm, lazy_gettext("Photo"), default=lambda: Image()) + rating = SelectField( + lazy_gettext("Rating"), default=50, coerce=int, choices=event_rating_choices + ) - photo = FormField(Base64ImageForm, lazy_gettext('Photo'), default=lambda: Image()) - rating = SelectField(lazy_gettext('Rating'), default=50, coerce=int, choices=event_rating_choices) class CreateEventForm(BaseEventForm): - event_place_choice = RadioField(lazy_gettext('Place'), choices=[(1,lazy_gettext('Select existing place')), (2,lazy_gettext('Enter new place'))], default=1, coerce=int) - event_place_id = SelectField(lazy_gettext('Place'), validators=[Optional()], coerce=int) + event_place_choice = RadioField( + lazy_gettext("Place"), + choices=[ + (1, lazy_gettext("Select existing place")), + (2, lazy_gettext("Enter new place")), + ], + default=1, + coerce=int, + ) + event_place_id = SelectField( + lazy_gettext("Place"), validators=[Optional()], coerce=int + ) new_event_place = FormField(EventPlaceForm, default=lambda: EventPlace()) - organizer_choice = RadioField(lazy_gettext('Organizer'), choices=[(1,lazy_gettext('Select existing organizer')), (2,lazy_gettext('Enter new organizer'))], default=1, coerce=int) - organizer_id = SelectField(lazy_gettext('Organizer'), validators=[Optional()], coerce=int) + organizer_choice = RadioField( + lazy_gettext("Organizer"), + choices=[ + (1, lazy_gettext("Select existing organizer")), + (2, lazy_gettext("Enter new organizer")), + ], + default=1, + coerce=int, + ) + organizer_id = SelectField( + lazy_gettext("Organizer"), validators=[Optional()], coerce=int + ) new_organizer = FormField(OrganizerForm, default=lambda: EventOrganizer()) submit = SubmitField(lazy_gettext("Create event")) def populate_obj(self, obj): for name, field in self._fields.items(): - if name == 'new_event_place': + if name == "new_event_place": if self.event_place_choice.data != 2: continue if not obj.event_place: obj.event_place = EventPlace() - field.populate_obj(obj, 'event_place') - elif name == 'new_organizer': + field.populate_obj(obj, "event_place") + elif name == "new_organizer": if self.organizer_choice.data != 2: continue if not obj.organizer: obj.organizer = EventOrganizer() - field.populate_obj(obj, 'organizer') - elif name == 'photo' and not obj.photo: + field.populate_obj(obj, "organizer") + elif name == "photo" and not obj.photo: obj.photo = Image() field.populate_obj(obj, name) @@ -102,50 +185,67 @@ class CreateEventForm(BaseEventForm): if not super(BaseEventForm, self).validate(): return False if self.event_place_id.data == 0 and not self.new_event_place.form.name.data: - msg = gettext('Select existing place or enter new place') + msg = gettext("Select existing place or enter new place") self.event_place_id.errors.append(msg) self.new_event_place.form.name.errors.append(msg) return False if self.organizer_id.data == 0 and not self.new_organizer.form.name.data: - msg = gettext('Select existing organizer or enter new organizer') + msg = gettext("Select existing organizer or enter new organizer") self.organizer_id.errors.append(msg) self.new_organizer.form.name.errors.append(msg) return False return True -class UpdateEventForm(BaseEventForm): - event_place_id = SelectField(lazy_gettext('Place'), validators=[DataRequired()], coerce=int) - organizer_id = SelectField(lazy_gettext('Organizer'), validators=[DataRequired()], coerce=int) - status = SelectField(lazy_gettext('Status'), coerce=int, choices=[ - (int(EventStatus.scheduled), lazy_gettext('EventStatus.scheduled')), - (int(EventStatus.cancelled), lazy_gettext('EventStatus.cancelled')), - (int(EventStatus.movedOnline), lazy_gettext('EventStatus.movedOnline')), - (int(EventStatus.postponed), lazy_gettext('EventStatus.postponed')), - (int(EventStatus.rescheduled), lazy_gettext('EventStatus.rescheduled'))]) +class UpdateEventForm(BaseEventForm): + event_place_id = SelectField( + lazy_gettext("Place"), validators=[DataRequired()], coerce=int + ) + organizer_id = SelectField( + lazy_gettext("Organizer"), validators=[DataRequired()], coerce=int + ) + + status = SelectField( + lazy_gettext("Status"), + coerce=int, + choices=[ + (int(EventStatus.scheduled), lazy_gettext("EventStatus.scheduled")), + (int(EventStatus.cancelled), lazy_gettext("EventStatus.cancelled")), + (int(EventStatus.movedOnline), lazy_gettext("EventStatus.movedOnline")), + (int(EventStatus.postponed), lazy_gettext("EventStatus.postponed")), + (int(EventStatus.rescheduled), lazy_gettext("EventStatus.rescheduled")), + ], + ) submit = SubmitField(lazy_gettext("Update event")) def populate_obj(self, obj): for name, field in self._fields.items(): - if name == 'photo' and not obj.photo: + if name == "photo" and not obj.photo: obj.photo = Image() field.populate_obj(obj, name) + class DeleteEventForm(FlaskForm): submit = SubmitField(lazy_gettext("Delete event")) - name = StringField(lazy_gettext('Name'), validators=[DataRequired()]) + name = StringField(lazy_gettext("Name"), validators=[DataRequired()]) + class FindEventForm(FlaskForm): class Meta: csrf = False - date_from = CustomDateField(lazy_gettext('From'), validators=[Optional()]) - date_to = CustomDateField(lazy_gettext('to'), validators=[Optional()]) - keyword = StringField(lazy_gettext('Keyword'), validators=[Optional()]) - category_id = SelectField(lazy_gettext('Category'), validators=[Optional()], coerce=int) - organizer_id = SelectField(lazy_gettext('Organizer'), validators=[Optional()], coerce=int) + + date_from = CustomDateField(lazy_gettext("From"), validators=[Optional()]) + date_to = CustomDateField(lazy_gettext("to"), validators=[Optional()]) + keyword = StringField(lazy_gettext("Keyword"), validators=[Optional()]) + category_id = SelectField( + lazy_gettext("Category"), validators=[Optional()], coerce=int + ) + organizer_id = SelectField( + lazy_gettext("Organizer"), validators=[Optional()], coerce=int + ) submit = SubmitField(lazy_gettext("Find events")) def is_submitted(self): - return 'submit' in request.args + return "submit" in request.args diff --git a/project/forms/event_date.py b/project/forms/event_date.py index 5b8fe3b..ab790c9 100644 --- a/project/forms/event_date.py +++ b/project/forms/event_date.py @@ -1,28 +1,37 @@ from flask import request -from flask_babelex import lazy_gettext, gettext +from flask_babelex import lazy_gettext from flask_wtf import FlaskForm -from flask_wtf.file import FileField, FileAllowed -from wtforms import HiddenField, SelectMultipleField, FieldList, RadioField, DateTimeField, StringField, SubmitField, TextAreaField, SelectField, BooleanField, IntegerField, FormField -from wtforms.fields.html5 import DateTimeLocalField, EmailField -from wtforms.validators import DataRequired, Optional -from wtforms.widgets import html_params, HTMLString -from project.models import EventPlace, EventTargetGroupOrigin, EventAttendanceMode, EventStatus, Location, EventOrganizer, EventRejectionReason, EventReviewStatus -from project.forms.common import event_rating_choices, weekday_choices, distance_choices -from project.forms.widgets import CustomDateField, MultiCheckboxField +from wtforms import ( + HiddenField, + StringField, + SubmitField, + SelectField, +) +from wtforms.validators import Optional +from project.forms.common import distance_choices +from project.forms.widgets import CustomDateField + class FindEventDateForm(FlaskForm): class Meta: csrf = False - date_from = CustomDateField(lazy_gettext('From'), validators=[Optional()]) - date_to = CustomDateField(lazy_gettext('to'), validators=[Optional()]) - keyword = StringField(lazy_gettext('Keyword'), validators=[Optional()]) - category_id = SelectField(lazy_gettext('Category'), validators=[Optional()], coerce=int) + date_from = CustomDateField(lazy_gettext("From"), validators=[Optional()]) + date_to = CustomDateField(lazy_gettext("to"), validators=[Optional()]) + keyword = StringField(lazy_gettext("Keyword"), validators=[Optional()]) + category_id = SelectField( + lazy_gettext("Category"), validators=[Optional()], coerce=int + ) coordinate = HiddenField(validators=[Optional()]) - location = StringField(lazy_gettext('Location'), validators=[Optional()]) - distance = SelectField(lazy_gettext('Distance'), validators=[Optional()], coerce=int, choices=distance_choices) + location = StringField(lazy_gettext("Location"), validators=[Optional()]) + distance = SelectField( + lazy_gettext("Distance"), + validators=[Optional()], + coerce=int, + choices=distance_choices, + ) submit = SubmitField(lazy_gettext("Find")) def is_submitted(self): - return 'submit' in request.args \ No newline at end of file + return "submit" in request.args diff --git a/project/forms/event_place.py b/project/forms/event_place.py index acea9ca..ff1eb4e 100644 --- a/project/forms/event_place.py +++ b/project/forms/event_place.py @@ -1,48 +1,62 @@ -from flask_babelex import lazy_gettext, gettext +from flask_babelex import lazy_gettext from flask_wtf import FlaskForm -from flask_wtf.file import FileField, FileAllowed -from wtforms import DecimalField, RadioField, DateTimeField, StringField, SubmitField, TextAreaField, SelectField, BooleanField, IntegerField, FormField -from wtforms.fields.html5 import DateTimeLocalField, EmailField, URLField +from wtforms import ( + DecimalField, + StringField, + SubmitField, + TextAreaField, + FormField, +) +from wtforms.fields.html5 import URLField from wtforms.validators import DataRequired, Optional -from wtforms.widgets import html_params, HTMLString -import decimal from project.models import Location, Image from project.forms.common import FileImageForm + class EventPlaceLocationForm(FlaskForm): - street = StringField(lazy_gettext('Street'), validators=[Optional()]) - postalCode = StringField(lazy_gettext('Postal code'), validators=[Optional()]) - city = StringField(lazy_gettext('City'), validators=[Optional()]) - state = StringField(lazy_gettext('State'), validators=[Optional()]) - latitude = DecimalField(lazy_gettext('Latitude'), places=16, validators=[Optional()]) - longitude = DecimalField(lazy_gettext('Longitude'), places=16, validators=[Optional()]) + street = StringField(lazy_gettext("Street"), validators=[Optional()]) + postalCode = StringField(lazy_gettext("Postal code"), validators=[Optional()]) + city = StringField(lazy_gettext("City"), validators=[Optional()]) + state = StringField(lazy_gettext("State"), validators=[Optional()]) + latitude = DecimalField( + lazy_gettext("Latitude"), places=16, validators=[Optional()] + ) + longitude = DecimalField( + lazy_gettext("Longitude"), places=16, validators=[Optional()] + ) + class BaseEventPlaceForm(FlaskForm): - name = StringField(lazy_gettext('Name'), validators=[DataRequired()]) - url = URLField(lazy_gettext('Link URL'), validators=[Optional()]) - photo = FormField(FileImageForm, lazy_gettext('Photo'), default=lambda: Image()) - description = TextAreaField(lazy_gettext('Description'), validators=[Optional()]) + name = StringField(lazy_gettext("Name"), validators=[DataRequired()]) + url = URLField(lazy_gettext("Link URL"), validators=[Optional()]) + photo = FormField(FileImageForm, lazy_gettext("Photo"), default=lambda: Image()) + description = TextAreaField(lazy_gettext("Description"), validators=[Optional()]) location = FormField(EventPlaceLocationForm) def populate_obj(self, obj): for name, field in self._fields.items(): - if name == 'location' and not obj.location: + if name == "location" and not obj.location: obj.location = Location() - elif name == 'photo' and not obj.photo: + elif name == "photo" and not obj.photo: obj.photo = Image() field.populate_obj(obj, name) + class CreateEventPlaceForm(BaseEventPlaceForm): submit = SubmitField(lazy_gettext("Create place")) + class UpdateEventPlaceForm(BaseEventPlaceForm): submit = SubmitField(lazy_gettext("Update place")) + class DeleteEventPlaceForm(FlaskForm): submit = SubmitField(lazy_gettext("Delete place")) - name = StringField(lazy_gettext('Name'), validators=[DataRequired()]) + name = StringField(lazy_gettext("Name"), validators=[DataRequired()]) + class FindEventPlaceForm(FlaskForm): class Meta: csrf = False + submit = SubmitField(lazy_gettext("Find places")) diff --git a/project/forms/event_suggestion.py b/project/forms/event_suggestion.py index af5bbea..9185ac0 100644 --- a/project/forms/event_suggestion.py +++ b/project/forms/event_suggestion.py @@ -1,52 +1,135 @@ -from flask import request -from flask_babelex import lazy_gettext, gettext +from flask_babelex import lazy_gettext from flask_wtf import FlaskForm -from flask_wtf.file import FileField, FileAllowed -from wtforms import FieldList, RadioField, DateTimeField, StringField, SubmitField, TextAreaField, SelectField, BooleanField, IntegerField, FormField -from wtforms.fields.html5 import DateTimeLocalField, EmailField, TelField, URLField +from wtforms import ( + StringField, + SubmitField, + TextAreaField, + SelectField, + BooleanField, + FormField, +) +from wtforms.fields.html5 import EmailField, TelField, URLField from wtforms.validators import DataRequired, Optional -from wtforms.widgets import html_params, HTMLString -from project.models import EventSuggestion, EventPlace, EventTargetGroupOrigin, EventAttendanceMode, EventStatus, Location, EventOrganizer, EventRejectionReason, EventReviewStatus, Image -from project.forms.common import event_rating_choices, Base64ImageForm -from project.forms.widgets import CustomDateTimeField, CustomDateField, TagSelectField -from project.forms.common import event_rating_choices +from project.models import ( + EventRejectionReason, + Image, +) +from project.forms.common import Base64ImageForm +from project.forms.widgets import CustomDateTimeField, TagSelectField + class CreateEventSuggestionForm(FlaskForm): - name = StringField(lazy_gettext('Name'), validators=[DataRequired()], description=lazy_gettext('Enter a short, meaningful name for the event.')) - start = CustomDateTimeField(lazy_gettext('Start'), validators=[DataRequired()], description=lazy_gettext('Indicate when the event will take place.')) - description = TextAreaField(lazy_gettext('Description'), validators=[Optional()], description=lazy_gettext('Add an optional description of the event.')) - external_link = URLField(lazy_gettext('Link URL'), validators=[Optional()], description=lazy_gettext('Add an optional link. That can make the review easier.')) + name = StringField( + lazy_gettext("Name"), + validators=[DataRequired()], + description=lazy_gettext("Enter a short, meaningful name for the event."), + ) + start = CustomDateTimeField( + lazy_gettext("Start"), + validators=[DataRequired()], + description=lazy_gettext("Indicate when the event will take place."), + ) + description = TextAreaField( + lazy_gettext("Description"), + validators=[Optional()], + description=lazy_gettext("Add an optional description of the event."), + ) + external_link = URLField( + lazy_gettext("Link URL"), + validators=[Optional()], + description=lazy_gettext( + "Add an optional link. That can make the review easier." + ), + ) - contact_name = StringField(lazy_gettext('Name'), validators=[DataRequired()], description=lazy_gettext('Please enter your name for the review.')) - contact_phone = TelField(lazy_gettext('Phone'), validators=[Optional()], description=lazy_gettext('Please enter your phone number or email address for the review.')) - contact_email = EmailField(lazy_gettext('Email'), validators=[Optional()], description=lazy_gettext('Please enter your email address or phone number for the review.')) - contact_email_notice = BooleanField(lazy_gettext('I would like to be notified by email after the review'), validators=[Optional()]) + contact_name = StringField( + lazy_gettext("Name"), + validators=[DataRequired()], + description=lazy_gettext("Please enter your name for the review."), + ) + contact_phone = TelField( + lazy_gettext("Phone"), + validators=[Optional()], + description=lazy_gettext( + "Please enter your phone number or email address for the review." + ), + ) + contact_email = EmailField( + lazy_gettext("Email"), + validators=[Optional()], + description=lazy_gettext( + "Please enter your email address or phone number for the review." + ), + ) + contact_email_notice = BooleanField( + lazy_gettext("I would like to be notified by email after the review"), + validators=[Optional()], + ) - event_place_id = TagSelectField(lazy_gettext('Place'), validators=[DataRequired()], description=lazy_gettext('Choose where the event takes place. If the venue is not yet in the list, just enter it.')) - organizer_id = TagSelectField(lazy_gettext('Organizer'), validators=[DataRequired()], description=lazy_gettext('Select the organizer. If the organizer is not yet on the list, just enter it.')) - photo = FormField(Base64ImageForm, lazy_gettext('Photo'), default=lambda: Image(), description=lazy_gettext('We recommend uploading a photo for the event. It looks a lot more, but of course it works without it.')) - accept_tos = BooleanField(lazy_gettext('I confirm that I have clarified all information (text, images, etc.) that I upload into the system with regard to their rights of use and declare that they may be passed on.'), validators=[DataRequired()]) + event_place_id = TagSelectField( + lazy_gettext("Place"), + validators=[DataRequired()], + description=lazy_gettext( + "Choose where the event takes place. If the venue is not yet in the list, just enter it." + ), + ) + organizer_id = TagSelectField( + lazy_gettext("Organizer"), + validators=[DataRequired()], + description=lazy_gettext( + "Select the organizer. If the organizer is not yet on the list, just enter it." + ), + ) + photo = FormField( + Base64ImageForm, + lazy_gettext("Photo"), + default=lambda: Image(), + description=lazy_gettext( + "We recommend uploading a photo for the event. It looks a lot more, but of course it works without it." + ), + ) + accept_tos = BooleanField( + lazy_gettext( + "I confirm that I have clarified all information (text, images, etc.) that I upload into the system with regard to their rights of use and declare that they may be passed on." + ), + validators=[DataRequired()], + ) submit = SubmitField(lazy_gettext("Create event suggestion")) def populate_obj(self, obj): for name, field in self._fields.items(): - if name == 'photo' and not obj.photo: + if name == "photo" and not obj.photo: obj.photo = Image() - if name == 'event_place_id' and self.event_place_id.is_free_text(): + if name == "event_place_id" and self.event_place_id.is_free_text(): obj.event_place_text = self.event_place_id.data obj.event_place_id = None - elif name == 'organizer_id' and self.organizer_id.is_free_text(): + elif name == "organizer_id" and self.organizer_id.is_free_text(): obj.organizer_text = self.organizer_id.data obj.organizer_id = None else: field.populate_obj(obj, name) + class RejectEventSuggestionForm(FlaskForm): - rejection_resaon = SelectField(lazy_gettext('Rejection reason'), coerce=int, choices=[ - (0, ''), - (int(EventRejectionReason.duplicate), lazy_gettext('EventRejectionReason.duplicate')), - (int(EventRejectionReason.untrustworthy), lazy_gettext('EventRejectionReason.untrustworthy')), - (int(EventRejectionReason.illegal), lazy_gettext('EventRejectionReason.illegal'))]) + rejection_resaon = SelectField( + lazy_gettext("Rejection reason"), + coerce=int, + choices=[ + (0, ""), + ( + int(EventRejectionReason.duplicate), + lazy_gettext("EventRejectionReason.duplicate"), + ), + ( + int(EventRejectionReason.untrustworthy), + lazy_gettext("EventRejectionReason.untrustworthy"), + ), + ( + int(EventRejectionReason.illegal), + lazy_gettext("EventRejectionReason.illegal"), + ), + ], + ) submit = SubmitField(lazy_gettext("Reject event suggestion")) diff --git a/project/forms/organizer.py b/project/forms/organizer.py index e968c2e..0cfebed 100644 --- a/project/forms/organizer.py +++ b/project/forms/organizer.py @@ -1,44 +1,56 @@ from flask_babelex import lazy_gettext from flask_wtf import FlaskForm -from flask_wtf.file import FileField, FileAllowed -from wtforms import StringField, SubmitField, DecimalField, TextAreaField, FormField, SelectField +from wtforms import ( + StringField, + SubmitField, + DecimalField, + FormField, +) from wtforms.fields.html5 import EmailField, TelField, URLField -from wtforms.validators import DataRequired, Optional, Regexp -import decimal +from wtforms.validators import DataRequired, Optional from project.models import Location, Image from project.forms.common import FileImageForm + class OrganizerLocationForm(FlaskForm): - street = StringField(lazy_gettext('Street'), validators=[Optional()]) - postalCode = StringField(lazy_gettext('Postal code'), validators=[Optional()]) - city = StringField(lazy_gettext('City'), validators=[Optional()]) - state = StringField(lazy_gettext('State'), validators=[Optional()]) - latitude = DecimalField(lazy_gettext('Latitude'), places=16, validators=[Optional()]) - longitude = DecimalField(lazy_gettext('Longitude'), places=16, validators=[Optional()]) + street = StringField(lazy_gettext("Street"), validators=[Optional()]) + postalCode = StringField(lazy_gettext("Postal code"), validators=[Optional()]) + city = StringField(lazy_gettext("City"), validators=[Optional()]) + state = StringField(lazy_gettext("State"), validators=[Optional()]) + latitude = DecimalField( + lazy_gettext("Latitude"), places=16, validators=[Optional()] + ) + longitude = DecimalField( + lazy_gettext("Longitude"), places=16, validators=[Optional()] + ) + class BaseOrganizerForm(FlaskForm): - name = StringField(lazy_gettext('Name'), validators=[DataRequired()]) - url = URLField(lazy_gettext('Link URL'), validators=[Optional()]) - email = EmailField(lazy_gettext('Email'), validators=[Optional()]) - phone = TelField(lazy_gettext('Phone'), validators=[Optional()]) - fax = TelField(lazy_gettext('Fax'), validators=[Optional()]) - logo = FormField(FileImageForm, lazy_gettext('Logo'), default=lambda: Image()) + name = StringField(lazy_gettext("Name"), validators=[DataRequired()]) + url = URLField(lazy_gettext("Link URL"), validators=[Optional()]) + email = EmailField(lazy_gettext("Email"), validators=[Optional()]) + phone = TelField(lazy_gettext("Phone"), validators=[Optional()]) + fax = TelField(lazy_gettext("Fax"), validators=[Optional()]) + logo = FormField(FileImageForm, lazy_gettext("Logo"), default=lambda: Image()) location = FormField(OrganizerLocationForm) def populate_obj(self, obj): for name, field in self._fields.items(): - if name == 'location' and not obj.location: + if name == "location" and not obj.location: obj.location = Location() - elif name == 'logo' and not obj.logo: + elif name == "logo" and not obj.logo: obj.logo = Image() field.populate_obj(obj, name) + class CreateOrganizerForm(BaseOrganizerForm): submit = SubmitField(lazy_gettext("Create organizer")) + class UpdateOrganizerForm(BaseOrganizerForm): submit = SubmitField(lazy_gettext("Update organizer")) + class DeleteOrganizerForm(FlaskForm): submit = SubmitField(lazy_gettext("Delete organizer")) - name = StringField(lazy_gettext('Name'), validators=[DataRequired()]) \ No newline at end of file + name = StringField(lazy_gettext("Name"), validators=[DataRequired()]) diff --git a/project/forms/planing.py b/project/forms/planing.py index 12bdf48..01197a9 100644 --- a/project/forms/planing.py +++ b/project/forms/planing.py @@ -1,28 +1,37 @@ from flask import request -from flask_babelex import lazy_gettext, gettext +from flask_babelex import lazy_gettext from flask_wtf import FlaskForm -from flask_wtf.file import FileField, FileAllowed -from wtforms import HiddenField, SelectMultipleField, FieldList, RadioField, DateTimeField, StringField, SubmitField, TextAreaField, SelectField, BooleanField, IntegerField, FormField -from wtforms.fields.html5 import DateTimeLocalField, EmailField -from wtforms.validators import DataRequired, Optional -from wtforms.widgets import html_params, HTMLString -from project.models import EventPlace, EventTargetGroupOrigin, EventAttendanceMode, EventStatus, Location, EventOrganizer, EventRejectionReason, EventReviewStatus -from project.forms.common import event_rating_choices, weekday_choices, distance_choices +from wtforms import HiddenField, StringField, SubmitField, SelectField +from wtforms.validators import Optional +from project.forms.common import weekday_choices, distance_choices from project.forms.widgets import CustomDateField, MultiCheckboxField + class PlaningForm(FlaskForm): class Meta: csrf = False - date_from = CustomDateField(lazy_gettext('From'), validators=[Optional()]) - date_to = CustomDateField(lazy_gettext('to'), validators=[Optional()]) - category_id = SelectField(lazy_gettext('Category'), validators=[Optional()], coerce=int) + date_from = CustomDateField(lazy_gettext("From"), validators=[Optional()]) + date_to = CustomDateField(lazy_gettext("to"), validators=[Optional()]) + category_id = SelectField( + lazy_gettext("Category"), validators=[Optional()], coerce=int + ) coordinate = HiddenField(validators=[Optional()]) - location = StringField(lazy_gettext('Location'), validators=[Optional()]) - distance = SelectField(lazy_gettext('Distance'), validators=[Optional()], coerce=int, choices=distance_choices) - weekday = MultiCheckboxField(lazy_gettext('Weekdays'), validators=[Optional()], coerce=int, choices=weekday_choices) + location = StringField(lazy_gettext("Location"), validators=[Optional()]) + distance = SelectField( + lazy_gettext("Distance"), + validators=[Optional()], + coerce=int, + choices=distance_choices, + ) + weekday = MultiCheckboxField( + lazy_gettext("Weekdays"), + validators=[Optional()], + coerce=int, + choices=weekday_choices, + ) submit = SubmitField(lazy_gettext("Find")) def is_submitted(self): - return 'submit' in request.args \ No newline at end of file + return "submit" in request.args diff --git a/project/forms/reference.py b/project/forms/reference.py index 4ea4b0c..e2dff4a 100644 --- a/project/forms/reference.py +++ b/project/forms/reference.py @@ -1,18 +1,27 @@ -from flask_babelex import lazy_gettext, gettext +from flask_babelex import lazy_gettext from flask_wtf import FlaskForm from wtforms import SelectField, StringField, SubmitField from wtforms.validators import DataRequired from project.forms.common import event_rating_choices + class CreateEventReferenceForm(FlaskForm): - admin_unit_id = SelectField(lazy_gettext('Admin unit'), validators=[DataRequired()], coerce=int) - rating = SelectField(lazy_gettext('Rating'), default=50, coerce=int, choices=event_rating_choices) + admin_unit_id = SelectField( + lazy_gettext("Admin unit"), validators=[DataRequired()], coerce=int + ) + rating = SelectField( + lazy_gettext("Rating"), default=50, coerce=int, choices=event_rating_choices + ) submit = SubmitField(lazy_gettext("Save reference")) + class UpdateEventReferenceForm(FlaskForm): - rating = SelectField(lazy_gettext('Rating'), default=50, coerce=int, choices=event_rating_choices) + rating = SelectField( + lazy_gettext("Rating"), default=50, coerce=int, choices=event_rating_choices + ) submit = SubmitField(lazy_gettext("Update reference")) + class DeleteReferenceForm(FlaskForm): submit = SubmitField(lazy_gettext("Delete reference")) - name = StringField(lazy_gettext('Name'), validators=[DataRequired()]) \ No newline at end of file + name = StringField(lazy_gettext("Name"), validators=[DataRequired()]) diff --git a/project/forms/reference_request.py b/project/forms/reference_request.py index 0094bf9..8c34d93 100644 --- a/project/forms/reference_request.py +++ b/project/forms/reference_request.py @@ -1,30 +1,71 @@ -from flask_babelex import lazy_gettext, gettext +from flask_babelex import lazy_gettext from flask_wtf import FlaskForm from wtforms import SelectField, StringField, SubmitField from wtforms.validators import DataRequired from project.forms.common import event_rating_choices -from project.models import EventReferenceRequestRejectionReason, EventReferenceRequestReviewStatus +from project.models import ( + EventReferenceRequestRejectionReason, + EventReferenceRequestReviewStatus, +) + class CreateEventReferenceRequestForm(FlaskForm): - admin_unit_id = SelectField(lazy_gettext('Admin unit'), validators=[DataRequired()], coerce=int) + admin_unit_id = SelectField( + lazy_gettext("Admin unit"), validators=[DataRequired()], coerce=int + ) submit = SubmitField(lazy_gettext("Save request")) + class DeleteReferenceRequestForm(FlaskForm): submit = SubmitField(lazy_gettext("Delete request")) - name = StringField(lazy_gettext('Name'), validators=[DataRequired()]) + name = StringField(lazy_gettext("Name"), validators=[DataRequired()]) + class ReferenceRequestReviewForm(FlaskForm): - review_status = SelectField(lazy_gettext('Review status'), coerce=int, choices=[ - (int(EventReferenceRequestReviewStatus.inbox), lazy_gettext('EventReferenceRequestReviewStatus.inbox')), - (int(EventReferenceRequestReviewStatus.verified), lazy_gettext('EventReferenceRequestReviewStatus.verified')), - (int(EventReferenceRequestReviewStatus.rejected), lazy_gettext('EventReferenceRequestReviewStatus.rejected'))]) + review_status = SelectField( + lazy_gettext("Review status"), + coerce=int, + choices=[ + ( + int(EventReferenceRequestReviewStatus.inbox), + lazy_gettext("EventReferenceRequestReviewStatus.inbox"), + ), + ( + int(EventReferenceRequestReviewStatus.verified), + lazy_gettext("EventReferenceRequestReviewStatus.verified"), + ), + ( + int(EventReferenceRequestReviewStatus.rejected), + lazy_gettext("EventReferenceRequestReviewStatus.rejected"), + ), + ], + ) - rejection_reason = SelectField(lazy_gettext('Rejection reason'), coerce=int, choices=[ - (0, ''), - (int(EventReferenceRequestRejectionReason.duplicate), lazy_gettext('EventReferenceRequestRejectionReason.duplicate')), - (int(EventReferenceRequestRejectionReason.untrustworthy), lazy_gettext('EventReferenceRequestRejectionReason.untrustworthy')), - (int(EventReferenceRequestRejectionReason.irrelevant), lazy_gettext('EventReferenceRequestRejectionReason.irrelevant')), - (int(EventReferenceRequestRejectionReason.illegal), lazy_gettext('EventReferenceRequestRejectionReason.illegal'))]) + rejection_reason = SelectField( + lazy_gettext("Rejection reason"), + coerce=int, + choices=[ + (0, ""), + ( + int(EventReferenceRequestRejectionReason.duplicate), + lazy_gettext("EventReferenceRequestRejectionReason.duplicate"), + ), + ( + int(EventReferenceRequestRejectionReason.untrustworthy), + lazy_gettext("EventReferenceRequestRejectionReason.untrustworthy"), + ), + ( + int(EventReferenceRequestRejectionReason.irrelevant), + lazy_gettext("EventReferenceRequestRejectionReason.irrelevant"), + ), + ( + int(EventReferenceRequestRejectionReason.illegal), + lazy_gettext("EventReferenceRequestRejectionReason.illegal"), + ), + ], + ) - rating = SelectField(lazy_gettext('Rating'), default=50, coerce=int, choices=event_rating_choices) - submit = SubmitField(lazy_gettext("Save review")) \ No newline at end of file + rating = SelectField( + lazy_gettext("Rating"), default=50, coerce=int, choices=event_rating_choices + ) + submit = SubmitField(lazy_gettext("Save review")) diff --git a/project/forms/widgets.py b/project/forms/widgets.py index b318212..c43295d 100644 --- a/project/forms/widgets.py +++ b/project/forms/widgets.py @@ -1,15 +1,16 @@ from wtforms import DateTimeField, SelectMultipleField, SelectField from wtforms.widgets import html_params, HTMLString, ListWidget, CheckboxInput from wtforms.validators import StopValidation -import pytz from datetime import datetime from flask_babelex import to_user_timezone, gettext from project.dateutils import berlin_tz + class MultiCheckboxField(SelectMultipleField): widget = ListWidget(prefix_label=False) option_widget = CheckboxInput() + def create_option_string(count, value): result = "" for i in range(count): @@ -17,10 +18,11 @@ def create_option_string(count, value): result = result + '' % (i, selected, i) return result + class CustomDateTimeWidget: def __call__(self, field, **kwargs): - id = kwargs.pop('id', field.id) - date = '' + id = kwargs.pop("id", field.id) + date = "" hour = minute = 0 if field.data: date_value = to_user_timezone(field.data) @@ -28,12 +30,24 @@ class CustomDateTimeWidget: hour = date_value.hour minute = date_value.minute - date_params = html_params(name=field.name, id=id, value=date, required=field.flags.required, **kwargs) - time_hour_params = html_params(name=field.name, id=id + '-hour', **kwargs) - time_minute_params = html_params(name=field.name, id=id + '-minute', **kwargs) - clear_button_id = id + '-clear-button' + date_params = html_params( + name=field.name, id=id, value=date, required=field.flags.required, **kwargs + ) + time_hour_params = html_params(name=field.name, id=id + "-hour", **kwargs) + time_minute_params = html_params(name=field.name, id=id + "-minute", **kwargs) + clear_button_id = id + "-clear-button" + + return HTMLString( + '