Skip to content

Commit

Permalink
BIG CHANGE (sites, taibol frontend)
Browse files Browse the repository at this point in the history
  • Loading branch information
moogoo78 committed Jun 24, 2024
1 parent 5fbf187 commit 7693e42
Show file tree
Hide file tree
Showing 53 changed files with 1,341 additions and 2,082 deletions.
35 changes: 35 additions & 0 deletions alembic/versions/318dcd16a600_dns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""dns
Revision ID: 318dcd16a600
Revises: 260e33819b5e
Create Date: 2024-06-17 18:13:43.120105
"""
from alembic import op
import sqlalchemy as sa

import geoalchemy2

# revision identifiers, used by Alembic.
revision = '318dcd16a600'
down_revision = '260e33819b5e'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('unit', sa.Column('basis_of_record', sa.String(length=50), nullable=True))
op.add_column('unit', sa.Column('material_entity_id', sa.String(length=500), nullable=True))
op.add_column('unit', sa.Column('dna_sequence', sa.Text(), nullable=True))
op.add_column('unit', sa.Column('sequencer', sa.String(length=500), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('unit', 'sequencer')
op.drop_column('unit', 'dna_sequence')
op.drop_column('unit', 'material_entity_id')
op.drop_column('unit', 'basis_of_record')
# ### end Alembic commands ###
29 changes: 29 additions & 0 deletions alembic/versions/3785ccd6eb37_site_rm_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""site-rm-code
Revision ID: 3785ccd6eb37
Revises: 3da76abfc432
Create Date: 2024-06-18 05:19:48.455171
"""
from alembic import op
import sqlalchemy as sa

import geoalchemy2

# revision identifiers, used by Alembic.
revision = '3785ccd6eb37'
down_revision = '3da76abfc432'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('site', 'code')
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('site', sa.Column('code', sa.VARCHAR(length=500), autoincrement=False, nullable=True))
# ### end Alembic commands ###
61 changes: 61 additions & 0 deletions alembic/versions/3da76abfc432_site_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""site-schema
Revision ID: 3da76abfc432
Revises: 4c228755cffb
Create Date: 2024-06-18 05:09:31.292914
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
import geoalchemy2

# revision identifiers, used by Alembic.
revision = '3da76abfc432'
down_revision = '4c228755cffb'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('organization', 'domain')
op.drop_column('organization', 'is_site')
op.drop_column('organization', 'settings')
op.drop_column('organization', 'subdomain')
op.drop_column('organization', 'description')
op.drop_column('organization', 'ark_nma')
op.drop_column('organization', 'logo_url')
op.add_column('site', sa.Column('title', sa.String(length=500), nullable=True))
op.add_column('site', sa.Column('title_en', sa.String(length=500), nullable=True))
op.add_column('site', sa.Column('logo_url', sa.String(length=500), nullable=True))
op.add_column('site', sa.Column('description', sa.Text(), nullable=True))
op.alter_column('site', 'name',
existing_type=sa.VARCHAR(length=500),
type_=sa.String(length=50),
existing_nullable=True)
op.drop_column('site', 'name_en')
op.drop_column('site', 'short_name')
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('site', sa.Column('short_name', sa.VARCHAR(length=500), autoincrement=False, nullable=True))
op.add_column('site', sa.Column('name_en', sa.VARCHAR(length=500), autoincrement=False, nullable=True))
op.alter_column('site', 'name',
existing_type=sa.String(length=50),
type_=sa.VARCHAR(length=500),
existing_nullable=True)
op.drop_column('site', 'description')
op.drop_column('site', 'logo_url')
op.drop_column('site', 'title_en')
op.drop_column('site', 'title')
op.add_column('organization', sa.Column('logo_url', sa.VARCHAR(length=500), autoincrement=False, nullable=True))
op.add_column('organization', sa.Column('ark_nma', sa.VARCHAR(length=500), autoincrement=False, nullable=True))
op.add_column('organization', sa.Column('description', sa.TEXT(), autoincrement=False, nullable=True))
op.add_column('organization', sa.Column('subdomain', sa.VARCHAR(length=100), autoincrement=False, nullable=True))
op.add_column('organization', sa.Column('settings', postgresql.JSONB(astext_type=sa.Text()), autoincrement=False, nullable=True))
op.add_column('organization', sa.Column('is_site', sa.BOOLEAN(), autoincrement=False, nullable=True))
op.add_column('organization', sa.Column('domain', sa.VARCHAR(length=500), autoincrement=False, nullable=True))
# ### end Alembic commands ###
31 changes: 31 additions & 0 deletions alembic/versions/4c228755cffb_host.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""host
Revision ID: 4c228755cffb
Revises: aef30cda76fc
Create Date: 2024-06-18 02:51:58.696708
"""
from alembic import op
import sqlalchemy as sa

import geoalchemy2

# revision identifiers, used by Alembic.
revision = '4c228755cffb'
down_revision = 'aef30cda76fc'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('site', sa.Column('host', sa.String(length=500), nullable=True))
op.drop_column('site', 'domain')
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('site', sa.Column('domain', sa.VARCHAR(length=500), autoincrement=False, nullable=True))
op.drop_column('site', 'host')
# ### end Alembic commands ###
31 changes: 31 additions & 0 deletions alembic/versions/54844ef10da8_collection_site_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""collection-site-id
Revision ID: 54844ef10da8
Revises: c80f91a5fba6
Create Date: 2024-06-19 10:11:44.863294
"""
from alembic import op
import sqlalchemy as sa

import geoalchemy2

# revision identifiers, used by Alembic.
revision = '54844ef10da8'
down_revision = 'c80f91a5fba6'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('collection', sa.Column('site_id', sa.Integer(), nullable=True))
op.create_foreign_key(None, 'collection', 'site', ['site_id'], ['id'], ondelete='SET NULL')
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, 'collection', type_='foreignkey')
op.drop_column('collection', 'site_id')
# ### end Alembic commands ###
67 changes: 67 additions & 0 deletions alembic/versions/aef30cda76fc_site_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""site_id
Revision ID: aef30cda76fc
Revises: b5a42e695eb4
Create Date: 2024-06-18 02:48:05.528842
"""
from alembic import op
import sqlalchemy as sa

import geoalchemy2

# revision identifiers, used by Alembic.
revision = 'aef30cda76fc'
down_revision = 'b5a42e695eb4'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('article', sa.Column('site_id', sa.Integer(), nullable=True))
op.drop_constraint('article_organization_id_fkey', 'article', type_='foreignkey')
op.create_foreign_key(None, 'article', 'site', ['site_id'], ['id'], ondelete='SET NULL')
op.drop_column('article', 'organization_id')
op.add_column('article_category', sa.Column('site_id', sa.Integer(), nullable=True))
op.drop_constraint('article_category_organization_id_fkey', 'article_category', type_='foreignkey')
op.create_foreign_key(None, 'article_category', 'site', ['site_id'], ['id'], ondelete='SET NULL')
op.drop_column('article_category', 'organization_id')
op.add_column('related_link', sa.Column('site_id', sa.Integer(), nullable=True))
op.drop_constraint('related_link_organization_id_fkey', 'related_link', type_='foreignkey')
op.create_foreign_key(None, 'related_link', 'site', ['site_id'], ['id'], ondelete='SET NULL')
op.drop_column('related_link', 'organization_id')
op.add_column('related_link_category', sa.Column('site_id', sa.Integer(), nullable=True))
op.drop_constraint('related_link_category_organization_id_fkey', 'related_link_category', type_='foreignkey')
op.create_foreign_key(None, 'related_link_category', 'site', ['site_id'], ['id'], ondelete='SET NULL')
op.drop_column('related_link_category', 'organization_id')
op.add_column('user', sa.Column('site_id', sa.Integer(), nullable=True))
op.drop_constraint('user_organization_id_fkey', 'user', type_='foreignkey')
op.create_foreign_key(None, 'user', 'site', ['site_id'], ['id'], ondelete='SET NULL')
op.drop_column('user', 'organization_id')
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('user', sa.Column('organization_id', sa.INTEGER(), autoincrement=False, nullable=True))
op.drop_constraint(None, 'user', type_='foreignkey')
op.create_foreign_key('user_organization_id_fkey', 'user', 'organization', ['organization_id'], ['id'], ondelete='SET NULL')
op.drop_column('user', 'site_id')
op.add_column('related_link_category', sa.Column('organization_id', sa.INTEGER(), autoincrement=False, nullable=True))
op.drop_constraint(None, 'related_link_category', type_='foreignkey')
op.create_foreign_key('related_link_category_organization_id_fkey', 'related_link_category', 'organization', ['organization_id'], ['id'], ondelete='SET NULL')
op.drop_column('related_link_category', 'site_id')
op.add_column('related_link', sa.Column('organization_id', sa.INTEGER(), autoincrement=False, nullable=True))
op.drop_constraint(None, 'related_link', type_='foreignkey')
op.create_foreign_key('related_link_organization_id_fkey', 'related_link', 'organization', ['organization_id'], ['id'], ondelete='SET NULL')
op.drop_column('related_link', 'site_id')
op.add_column('article_category', sa.Column('organization_id', sa.INTEGER(), autoincrement=False, nullable=True))
op.drop_constraint(None, 'article_category', type_='foreignkey')
op.create_foreign_key('article_category_organization_id_fkey', 'article_category', 'organization', ['organization_id'], ['id'], ondelete='SET NULL')
op.drop_column('article_category', 'site_id')
op.add_column('article', sa.Column('organization_id', sa.INTEGER(), autoincrement=False, nullable=True))
op.drop_constraint(None, 'article', type_='foreignkey')
op.create_foreign_key('article_organization_id_fkey', 'article', 'organization', ['organization_id'], ['id'], ondelete='SET NULL')
op.drop_column('article', 'site_id')
# ### end Alembic commands ###
41 changes: 41 additions & 0 deletions alembic/versions/b5a42e695eb4_site_dep.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""site-dep
Revision ID: b5a42e695eb4
Revises: 318dcd16a600
Create Date: 2024-06-18 02:38:08.714498
"""
from alembic import op
import sqlalchemy as sa

import geoalchemy2

# revision identifiers, used by Alembic.
revision = 'b5a42e695eb4'
down_revision = '318dcd16a600'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('site',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=500), nullable=True),
sa.Column('name_en', sa.String(length=500), nullable=True),
sa.Column('short_name', sa.String(length=500), nullable=True),
sa.Column('code', sa.String(length=500), nullable=True),
sa.Column('domain', sa.String(length=500), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.add_column('organization', sa.Column('site_id', sa.Integer(), nullable=True))
op.create_foreign_key(None, 'organization', 'site', ['site_id'], ['id'], ondelete='SET NULL')
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, 'organization', type_='foreignkey')
op.drop_column('organization', 'site_id')
op.drop_table('site')
# ### end Alembic commands ###
29 changes: 29 additions & 0 deletions alembic/versions/c80f91a5fba6_site_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""site.data
Revision ID: c80f91a5fba6
Revises: 3785ccd6eb37
Create Date: 2024-06-18 08:42:35.128037
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
import geoalchemy2

# revision identifiers, used by Alembic.
revision = 'c80f91a5fba6'
down_revision = '3785ccd6eb37'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('site', sa.Column('data', postgresql.JSONB(astext_type=sa.Text()), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('site', 'data')
# ### end Alembic commands ###
23 changes: 9 additions & 14 deletions app/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

from app.models.site import (
User,
Organization,
Site,
)
from app.utils import find_date

Expand All @@ -57,20 +57,14 @@
'''
def apply_blueprints(app):
from app.blueprints.base import base as base_bp
from app.blueprints.frontend import frontend as frontend_bp
#from app.blueprints.data import data as data_bp
#from app.blueprints.main import main as main_bp
#from app.blueprints.page import page as page_bp
from app.blueprints.frontpage import frontpage as frontpage_bp
from app.blueprints.admin import admin as admin_bp;
from app.blueprints.api import api as api_bp;

app.register_blueprint(base_bp)
app.register_blueprint(frontend_bp)
#app.register_blueprint(main_bp)
#app.register_blueprint(page_bp)
app.register_blueprint(frontpage_bp)
app.register_blueprint(admin_bp, url_prefix='/admin')
app.register_blueprint(api_bp, url_prefix='/api/v1')
#app.register_blueprint(data_bp)

def get_locale():
#print(request.cookies.get('language'), flush=True)
Expand Down Expand Up @@ -152,16 +146,17 @@ def create_app():
def load_user(id):
return User.query.get(id)


@flask_app.route('/')
def cover():
domain = request.headers.get('Host', '')
if domain == os.getenv('PORTAL_SITE'):
host = request.headers.get('Host', '')
if host == os.getenv('PORTAL_SITE'):
return render_template('cover.html')

if site := Organization.get_site(domain):
return redirect(url_for('frontend.news', lang_code='zh'))
if site := Site.find_by_host(host):
return redirect(url_for('frontpage.index', lang_code='zh'))

return abort(404)
return 'naturedb: no site' #abort(404)

@flask_app.route('/import')
def import_data():
Expand Down
Loading

0 comments on commit 7693e42

Please sign in to comment.