Skip to content

Commit

Permalink
Merge branch 'auto-thumbnails' of https://github.com/hasgeek/funnel i…
Browse files Browse the repository at this point in the history
…nto auto-thumbnails
  • Loading branch information
anishTP committed Sep 28, 2023
2 parents 4464ee9 + 99bfe37 commit 0478091
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 116 deletions.
2 changes: 1 addition & 1 deletion funnel/views/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
db,
sa,
)
from ..signals import project_data_change, project_role_change
from ..signals import project_role_change
from ..typing import ReturnRenderWith, ReturnView
from .helpers import html_in_json, render_redirect
from .jobs import import_tickets, tag_locations
Expand Down
9 changes: 4 additions & 5 deletions funnel/views/thumnbnails.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

from flask import render_template
from html2image import Html2Image
from ..models import Project, db
from .jobs import rqjob
from ..signals import project_data_changed

from ..models import Project
from ..models import Project, db
from ..signals import project_data_change
from .jobs import rqjob

Expand All @@ -24,7 +21,9 @@ def render_thumbnail_image(project=Project) -> None:

image_html = render_template('thumbnail_preview.html.jinja2', project=project)

thumbnail_image = thumbnail.screenshot(html_str=image_html, save_as=f'{project.id}_thumbnail.png', size=(640, 360))
thumbnail_image = thumbnail.screenshot(
html_str=image_html, save_as=f'{project.id}_thumbnail.png', size=(640, 360)
)

project.thumbnail_image = thumbnail_image
db.session.add(project)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@
"""

from typing import Optional, Tuple, Union

from alembic import op
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision: str = '8750fd8f82de'
down_revision: str = '4f9ca10b7b9d'
branch_labels: Optional[Union[str, Tuple[str, ...]]] = None
depends_on: Optional[Union[str, Tuple[str, ...]]] = None
branch_labels: str | tuple[str, ...] | None = None
depends_on: str | tuple[str, ...] | None = None


def upgrade(engine_name: str = '') -> None:
Expand All @@ -31,14 +30,13 @@ def downgrade(engine_name: str = '') -> None:
globals().get(f'downgrade_{engine_name}', lambda: None)()





def upgrade_() -> None:
"""Upgrade default database."""
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('project', schema=None) as batch_op:
batch_op.add_column(sa.Column('thumbnail_image', sa.LargeBinary(), nullable=True))
batch_op.add_column(
sa.Column('thumbnail_image', sa.LargeBinary(), nullable=True)
)

# ### end Alembic commands ###

Expand All @@ -55,111 +53,162 @@ def downgrade_() -> None:
def upgrade_geoname() -> None:
"""Upgrade geoname database."""
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('geo_country_info',
sa.Column('iso_alpha2', sa.CHAR(length=2), nullable=True),
sa.Column('iso_alpha3', sa.CHAR(length=3), nullable=True),
sa.Column('iso_numeric', sa.Integer(), nullable=True),
sa.Column('fips_code', sa.Unicode(length=3), nullable=True),
sa.Column('capital', sa.String(), nullable=True),
sa.Column('area_in_sqkm', sa.Numeric(), nullable=True),
sa.Column('population', sa.BigInteger(), nullable=True),
sa.Column('continent', sa.CHAR(length=2), nullable=True),
sa.Column('tld', sa.Unicode(length=3), nullable=True),
sa.Column('currency_code', sa.CHAR(length=3), nullable=True),
sa.Column('currency_name', sa.String(), nullable=True),
sa.Column('phone', sa.Unicode(length=16), nullable=True),
sa.Column('postal_code_format', sa.Unicode(), nullable=True),
sa.Column('postal_code_regex', sa.Unicode(), nullable=True),
sa.Column('languages', postgresql.ARRAY(sa.Unicode(), dimensions=1), nullable=True),
sa.Column('neighbours', postgresql.ARRAY(sa.CHAR(length=2), dimensions=1), nullable=True),
sa.Column('equivalent_fips_code', sa.Unicode(length=3), nullable=False),
sa.Column('name', sa.Unicode(length=250), nullable=False),
sa.Column('title', sa.Unicode(length=250), nullable=False),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.TIMESTAMP(timezone=True), nullable=False),
sa.Column('updated_at', sa.TIMESTAMP(timezone=True), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('iso_alpha2'),
sa.UniqueConstraint('iso_alpha3'),
sa.UniqueConstraint('name')
op.create_table(
'geo_country_info',
sa.Column('iso_alpha2', sa.CHAR(length=2), nullable=True),
sa.Column('iso_alpha3', sa.CHAR(length=3), nullable=True),
sa.Column('iso_numeric', sa.Integer(), nullable=True),
sa.Column('fips_code', sa.Unicode(length=3), nullable=True),
sa.Column('capital', sa.String(), nullable=True),
sa.Column('area_in_sqkm', sa.Numeric(), nullable=True),
sa.Column('population', sa.BigInteger(), nullable=True),
sa.Column('continent', sa.CHAR(length=2), nullable=True),
sa.Column('tld', sa.Unicode(length=3), nullable=True),
sa.Column('currency_code', sa.CHAR(length=3), nullable=True),
sa.Column('currency_name', sa.String(), nullable=True),
sa.Column('phone', sa.Unicode(length=16), nullable=True),
sa.Column('postal_code_format', sa.Unicode(), nullable=True),
sa.Column('postal_code_regex', sa.Unicode(), nullable=True),
sa.Column(
'languages', postgresql.ARRAY(sa.Unicode(), dimensions=1), nullable=True
),
sa.Column(
'neighbours',
postgresql.ARRAY(sa.CHAR(length=2), dimensions=1),
nullable=True,
),
sa.Column('equivalent_fips_code', sa.Unicode(length=3), nullable=False),
sa.Column('name', sa.Unicode(length=250), nullable=False),
sa.Column('title', sa.Unicode(length=250), nullable=False),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.TIMESTAMP(timezone=True), nullable=False),
sa.Column('updated_at', sa.TIMESTAMP(timezone=True), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('iso_alpha2'),
sa.UniqueConstraint('iso_alpha3'),
sa.UniqueConstraint('name'),
)
with op.batch_alter_table('geo_country_info', schema=None) as batch_op:
batch_op.create_index('ix_geo_country_info_title', [sa.text("lower('title')")], unique=False, postgresql_ops={'title_lower': 'varchar_pattern_ops'})

op.create_table('geo_admin1_code',
sa.Column('title', sa.Unicode(), nullable=True),
sa.Column('ascii_title', sa.Unicode(), nullable=True),
sa.Column('country', sa.CHAR(length=2), nullable=True),
sa.Column('admin1_code', sa.Unicode(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.TIMESTAMP(timezone=True), nullable=False),
sa.Column('updated_at', sa.TIMESTAMP(timezone=True), nullable=False),
sa.ForeignKeyConstraint(['country'], ['geo_country_info.iso_alpha2'], ),
sa.PrimaryKeyConstraint('id')
batch_op.create_index(
'ix_geo_country_info_title',
[sa.text("lower('title')")],
unique=False,
postgresql_ops={'title_lower': 'varchar_pattern_ops'},
)

op.create_table(
'geo_admin1_code',
sa.Column('title', sa.Unicode(), nullable=True),
sa.Column('ascii_title', sa.Unicode(), nullable=True),
sa.Column('country', sa.CHAR(length=2), nullable=True),
sa.Column('admin1_code', sa.Unicode(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.TIMESTAMP(timezone=True), nullable=False),
sa.Column('updated_at', sa.TIMESTAMP(timezone=True), nullable=False),
sa.ForeignKeyConstraint(
['country'],
['geo_country_info.iso_alpha2'],
),
sa.PrimaryKeyConstraint('id'),
)
op.create_table('geo_admin2_code',
sa.Column('title', sa.Unicode(), nullable=True),
sa.Column('ascii_title', sa.Unicode(), nullable=True),
sa.Column('country', sa.CHAR(length=2), nullable=True),
sa.Column('admin1_code', sa.Unicode(), nullable=True),
sa.Column('admin2_code', sa.Unicode(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.TIMESTAMP(timezone=True), nullable=False),
sa.Column('updated_at', sa.TIMESTAMP(timezone=True), nullable=False),
sa.ForeignKeyConstraint(['country'], ['geo_country_info.iso_alpha2'], ),
sa.PrimaryKeyConstraint('id')
op.create_table(
'geo_admin2_code',
sa.Column('title', sa.Unicode(), nullable=True),
sa.Column('ascii_title', sa.Unicode(), nullable=True),
sa.Column('country', sa.CHAR(length=2), nullable=True),
sa.Column('admin1_code', sa.Unicode(), nullable=True),
sa.Column('admin2_code', sa.Unicode(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.TIMESTAMP(timezone=True), nullable=False),
sa.Column('updated_at', sa.TIMESTAMP(timezone=True), nullable=False),
sa.ForeignKeyConstraint(
['country'],
['geo_country_info.iso_alpha2'],
),
sa.PrimaryKeyConstraint('id'),
)
op.create_table('geo_name',
sa.Column('ascii_title', sa.Unicode(), nullable=True),
sa.Column('latitude', sa.Numeric(), nullable=True),
sa.Column('longitude', sa.Numeric(), nullable=True),
sa.Column('fclass', sa.CHAR(length=1), nullable=True),
sa.Column('fcode', sa.Unicode(), nullable=True),
sa.Column('country', sa.CHAR(length=2), nullable=True),
sa.Column('cc2', sa.Unicode(), nullable=True),
sa.Column('admin1', sa.Unicode(), nullable=True),
sa.Column('admin1_id', sa.Integer(), nullable=True),
sa.Column('admin2', sa.Unicode(), nullable=True),
sa.Column('admin2_id', sa.Integer(), nullable=True),
sa.Column('admin4', sa.Unicode(), nullable=True),
sa.Column('admin3', sa.Unicode(), nullable=True),
sa.Column('population', sa.BigInteger(), nullable=True),
sa.Column('elevation', sa.Integer(), nullable=True),
sa.Column('dem', sa.Integer(), nullable=True),
sa.Column('timezone', sa.Unicode(), nullable=True),
sa.Column('moddate', sa.Date(), nullable=True),
sa.Column('name', sa.Unicode(length=250), nullable=False),
sa.Column('title', sa.Unicode(length=250), nullable=False),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.TIMESTAMP(timezone=True), nullable=False),
sa.Column('updated_at', sa.TIMESTAMP(timezone=True), nullable=False),
sa.ForeignKeyConstraint(['admin1_id'], ['geo_admin1_code.id'], ),
sa.ForeignKeyConstraint(['admin2_id'], ['geo_admin2_code.id'], ),
sa.ForeignKeyConstraint(['country'], ['geo_country_info.iso_alpha2'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name')
op.create_table(
'geo_name',
sa.Column('ascii_title', sa.Unicode(), nullable=True),
sa.Column('latitude', sa.Numeric(), nullable=True),
sa.Column('longitude', sa.Numeric(), nullable=True),
sa.Column('fclass', sa.CHAR(length=1), nullable=True),
sa.Column('fcode', sa.Unicode(), nullable=True),
sa.Column('country', sa.CHAR(length=2), nullable=True),
sa.Column('cc2', sa.Unicode(), nullable=True),
sa.Column('admin1', sa.Unicode(), nullable=True),
sa.Column('admin1_id', sa.Integer(), nullable=True),
sa.Column('admin2', sa.Unicode(), nullable=True),
sa.Column('admin2_id', sa.Integer(), nullable=True),
sa.Column('admin4', sa.Unicode(), nullable=True),
sa.Column('admin3', sa.Unicode(), nullable=True),
sa.Column('population', sa.BigInteger(), nullable=True),
sa.Column('elevation', sa.Integer(), nullable=True),
sa.Column('dem', sa.Integer(), nullable=True),
sa.Column('timezone', sa.Unicode(), nullable=True),
sa.Column('moddate', sa.Date(), nullable=True),
sa.Column('name', sa.Unicode(length=250), nullable=False),
sa.Column('title', sa.Unicode(length=250), nullable=False),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.TIMESTAMP(timezone=True), nullable=False),
sa.Column('updated_at', sa.TIMESTAMP(timezone=True), nullable=False),
sa.ForeignKeyConstraint(
['admin1_id'],
['geo_admin1_code.id'],
),
sa.ForeignKeyConstraint(
['admin2_id'],
['geo_admin2_code.id'],
),
sa.ForeignKeyConstraint(
['country'],
['geo_country_info.iso_alpha2'],
),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name'),
)
with op.batch_alter_table('geo_name', schema=None) as batch_op:
batch_op.create_index('ix_geo_name_ascii_title', [sa.text('lower(ascii_title)')], unique=False, postgresql_ops={'ascii_title_lower': 'varchar_pattern_ops'})
batch_op.create_index('ix_geo_name_title', [sa.text("lower('title')")], unique=False, postgresql_ops={'title_lower': 'varchar_pattern_ops'})

op.create_table('geo_alt_name',
sa.Column('geonameid', sa.Integer(), nullable=False),
sa.Column('lang', sa.Unicode(), nullable=True),
sa.Column('title', sa.Unicode(), nullable=False),
sa.Column('is_preferred_name', sa.Boolean(), nullable=False),
sa.Column('is_short_name', sa.Boolean(), nullable=False),
sa.Column('is_colloquial', sa.Boolean(), nullable=False),
sa.Column('is_historic', sa.Boolean(), nullable=False),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.TIMESTAMP(timezone=True), nullable=False),
sa.Column('updated_at', sa.TIMESTAMP(timezone=True), nullable=False),
sa.ForeignKeyConstraint(['geonameid'], ['geo_name.id'], ),
sa.PrimaryKeyConstraint('id')
batch_op.create_index(
'ix_geo_name_ascii_title',
[sa.text('lower(ascii_title)')],
unique=False,
postgresql_ops={'ascii_title_lower': 'varchar_pattern_ops'},
)
batch_op.create_index(
'ix_geo_name_title',
[sa.text("lower('title')")],
unique=False,
postgresql_ops={'title_lower': 'varchar_pattern_ops'},
)

op.create_table(
'geo_alt_name',
sa.Column('geonameid', sa.Integer(), nullable=False),
sa.Column('lang', sa.Unicode(), nullable=True),
sa.Column('title', sa.Unicode(), nullable=False),
sa.Column('is_preferred_name', sa.Boolean(), nullable=False),
sa.Column('is_short_name', sa.Boolean(), nullable=False),
sa.Column('is_colloquial', sa.Boolean(), nullable=False),
sa.Column('is_historic', sa.Boolean(), nullable=False),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.TIMESTAMP(timezone=True), nullable=False),
sa.Column('updated_at', sa.TIMESTAMP(timezone=True), nullable=False),
sa.ForeignKeyConstraint(
['geonameid'],
['geo_name.id'],
),
sa.PrimaryKeyConstraint('id'),
)
with op.batch_alter_table('geo_alt_name', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_geo_alt_name_lang'), ['lang'], unique=False)
batch_op.create_index('ix_geo_alt_name_title', [sa.text("lower('title')")], unique=False, postgresql_ops={'title_lower': 'varchar_pattern_ops'})
batch_op.create_index(
batch_op.f('ix_geo_alt_name_lang'), ['lang'], unique=False
)
batch_op.create_index(
'ix_geo_alt_name_title',
[sa.text("lower('title')")],
unique=False,
postgresql_ops={'title_lower': 'varchar_pattern_ops'},
)

# ### end Alembic commands ###

Expand All @@ -168,20 +217,30 @@ def downgrade_geoname() -> None:
"""Downgrade geoname database."""
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('geo_alt_name', schema=None) as batch_op:
batch_op.drop_index('ix_geo_alt_name_title', postgresql_ops={'title_lower': 'varchar_pattern_ops'})
batch_op.drop_index(
'ix_geo_alt_name_title',
postgresql_ops={'title_lower': 'varchar_pattern_ops'},
)
batch_op.drop_index(batch_op.f('ix_geo_alt_name_lang'))

op.drop_table('geo_alt_name')
with op.batch_alter_table('geo_name', schema=None) as batch_op:
batch_op.drop_index('ix_geo_name_title', postgresql_ops={'title_lower': 'varchar_pattern_ops'})
batch_op.drop_index('ix_geo_name_ascii_title', postgresql_ops={'ascii_title_lower': 'varchar_pattern_ops'})
batch_op.drop_index(
'ix_geo_name_title', postgresql_ops={'title_lower': 'varchar_pattern_ops'}
)
batch_op.drop_index(
'ix_geo_name_ascii_title',
postgresql_ops={'ascii_title_lower': 'varchar_pattern_ops'},
)

op.drop_table('geo_name')
op.drop_table('geo_admin2_code')
op.drop_table('geo_admin1_code')
with op.batch_alter_table('geo_country_info', schema=None) as batch_op:
batch_op.drop_index('ix_geo_country_info_title', postgresql_ops={'title_lower': 'varchar_pattern_ops'})
batch_op.drop_index(
'ix_geo_country_info_title',
postgresql_ops={'title_lower': 'varchar_pattern_ops'},
)

op.drop_table('geo_country_info')
# ### end Alembic commands ###

0 comments on commit 0478091

Please sign in to comment.