Skip to content

Commit 1f4fd84

Browse files
Merge pull request #340 from shopyo/feat/site-info
feat: site info
2 parents 754b14e + 396fd5b commit 1f4fd84

16 files changed

Lines changed: 207 additions & 115 deletions

File tree

pythoncms/migrations/env.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,43 @@
11
import logging
22
from logging.config import fileConfig
33

4-
from alembic import context
54
from flask import current_app
65

6+
from alembic import context
7+
78
# this is the Alembic Config object, which provides
89
# access to the values within the .ini file in use.
910
config = context.config
1011

1112
# Interpret the config file for Python logging.
1213
# This line sets up loggers basically.
1314
fileConfig(config.config_file_name)
14-
logger = logging.getLogger("alembic.env")
15+
logger = logging.getLogger('alembic.env')
1516

1617

1718
def get_engine():
1819
try:
1920
# this works with Flask-SQLAlchemy<3 and Alchemical
20-
return current_app.extensions["migrate"].db.get_engine()
21+
return current_app.extensions['migrate'].db.get_engine()
2122
except TypeError:
2223
# this works with Flask-SQLAlchemy>=3
23-
return current_app.extensions["migrate"].db.engine
24+
return current_app.extensions['migrate'].db.engine
25+
26+
27+
def get_engine_url():
28+
try:
29+
return get_engine().url.render_as_string(hide_password=False).replace(
30+
'%', '%%')
31+
except AttributeError:
32+
return str(get_engine().url).replace('%', '%%')
2433

2534

2635
# add your model's MetaData object here
2736
# for 'autogenerate' support
2837
# from myapp import mymodel
2938
# target_metadata = mymodel.Base.metadata
30-
config.set_main_option("sqlalchemy.url", str(get_engine().url).replace("%", "%%"))
31-
target_db = current_app.extensions["migrate"].db
39+
config.set_main_option('sqlalchemy.url', get_engine_url())
40+
target_db = current_app.extensions['migrate'].db
3241

3342
# other values from the config, defined by the needs of env.py,
3443
# can be acquired:
@@ -37,7 +46,7 @@ def get_engine():
3746

3847

3948
def get_metadata():
40-
if hasattr(target_db, "metadatas"):
49+
if hasattr(target_db, 'metadatas'):
4150
return target_db.metadatas[None]
4251
return target_db.metadata
4352

@@ -55,7 +64,9 @@ def run_migrations_offline():
5564
5665
"""
5766
url = config.get_main_option("sqlalchemy.url")
58-
context.configure(url=url, target_metadata=get_metadata(), literal_binds=True)
67+
context.configure(
68+
url=url, target_metadata=get_metadata(), literal_binds=True
69+
)
5970

6071
with context.begin_transaction():
6172
context.run_migrations()
@@ -73,11 +84,11 @@ def run_migrations_online():
7384
# when there are no changes to the schema
7485
# reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
7586
def process_revision_directives(context, revision, directives):
76-
if getattr(config.cmd_opts, "autogenerate", False):
87+
if getattr(config.cmd_opts, 'autogenerate', False):
7788
script = directives[0]
7889
if script.upgrade_ops.is_empty():
7990
directives[:] = []
80-
logger.info("No changes in schema detected.")
91+
logger.info('No changes in schema detected.')
8192

8293
connectable = get_engine()
8394

@@ -86,7 +97,7 @@ def process_revision_directives(context, revision, directives):
8697
connection=connection,
8798
target_metadata=get_metadata(),
8899
process_revision_directives=process_revision_directives,
89-
**current_app.extensions["migrate"].configure_args
100+
**current_app.extensions['migrate'].configure_args
90101
)
91102

92103
with context.begin_transaction():
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
"""empty message
2+
3+
Revision ID: 51daebf34ad3
4+
Revises:
5+
Create Date: 2023-07-03 18:41:32.090382
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
# revision identifiers, used by Alembic.
13+
revision = '51daebf34ad3'
14+
down_revision = None
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
op.create_table('contact',
22+
sa.Column('id', sa.Integer(), nullable=False),
23+
sa.Column('created_date', sa.DateTime(), nullable=True),
24+
sa.Column('name', sa.String(length=100), nullable=True),
25+
sa.Column('email', sa.String(length=100), nullable=True),
26+
sa.Column('message', sa.String(length=1024), nullable=True),
27+
sa.PrimaryKeyConstraint('id')
28+
)
29+
op.create_table('i18n_records',
30+
sa.Column('id', sa.Integer(), nullable=False),
31+
sa.Column('strid', sa.String(length=1024), nullable=True),
32+
sa.Column('lang', sa.String(length=10), nullable=True),
33+
sa.Column('string', sa.Text(), nullable=True),
34+
sa.PrimaryKeyConstraint('id')
35+
)
36+
op.create_table('pages',
37+
sa.Column('id', sa.Integer(), nullable=False),
38+
sa.Column('created_date', sa.DateTime(), nullable=True),
39+
sa.Column('title', sa.String(length=100), nullable=True),
40+
sa.Column('slug', sa.String(length=100), nullable=True),
41+
sa.PrimaryKeyConstraint('id')
42+
)
43+
op.create_table('roles',
44+
sa.Column('id', sa.Integer(), nullable=False),
45+
sa.Column('name', sa.String(length=100), nullable=False),
46+
sa.PrimaryKeyConstraint('id')
47+
)
48+
op.create_table('settings',
49+
sa.Column('setting', sa.String(length=100), nullable=False),
50+
sa.Column('value', sa.String(length=100), nullable=True),
51+
sa.PrimaryKeyConstraint('setting')
52+
)
53+
op.create_table('users',
54+
sa.Column('id', sa.Integer(), nullable=False),
55+
sa.Column('username', sa.String(length=100), nullable=True),
56+
sa.Column('_password', sa.String(length=128), nullable=False),
57+
sa.Column('first_name', sa.String(length=128), nullable=True),
58+
sa.Column('last_name', sa.String(length=128), nullable=True),
59+
sa.Column('is_admin', sa.Boolean(), nullable=True),
60+
sa.Column('email', sa.String(length=120), nullable=False),
61+
sa.Column('date_registered', sa.DateTime(), nullable=False),
62+
sa.Column('is_email_confirmed', sa.Boolean(), nullable=False),
63+
sa.Column('email_confirm_date', sa.DateTime(), nullable=True),
64+
sa.PrimaryKeyConstraint('id'),
65+
sa.UniqueConstraint('email'),
66+
sa.UniqueConstraint('username')
67+
)
68+
op.create_table('role_user_bridge',
69+
sa.Column('user_id', sa.Integer(), nullable=False),
70+
sa.Column('role_id', sa.Integer(), nullable=False),
71+
sa.ForeignKeyConstraint(['role_id'], ['roles.id'], ondelete='CASCADE'),
72+
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'),
73+
sa.PrimaryKeyConstraint('user_id', 'role_id')
74+
)
75+
# ### end Alembic commands ###
76+
77+
78+
def downgrade():
79+
# ### commands auto generated by Alembic - please adjust! ###
80+
op.drop_table('role_user_bridge')
81+
op.drop_table('users')
82+
op.drop_table('settings')
83+
op.drop_table('roles')
84+
op.drop_table('pages')
85+
op.drop_table('i18n_records')
86+
op.drop_table('contact')
87+
# ### end Alembic commands ###

pythoncms/migrations/versions/7d11df1f6a08_.py

Lines changed: 0 additions & 94 deletions
This file was deleted.

pythoncms/modules/box__default/base/models.py

Whitespace-only changes.

pythoncms/modules/box__default/info/forms.py

Whitespace-only changes.

pythoncms/modules/box__default/info/global.py

Whitespace-only changes.

pythoncms/modules/box__default/info/helpers.py

Whitespace-only changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"display_string": "Site Info",
3+
"module_name":"info",
4+
"type": "show",
5+
"icons":{
6+
"fa": "fa fa-edit",
7+
"boxicons": "bx bx-pen"
8+
},
9+
"url_prefix": "/info",
10+
"dashboard": "/dashboard",
11+
"author": {
12+
"name": "Abdur-Rahmaan Janhangeer",
13+
"website": "https://www.pythonkitchen.com/about-me/",
14+
"mail": "arj.python@gmail.com"
15+
}
16+
}

pythoncms/modules/box__default/info/models.py

Whitespace-only changes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{%extends get_active_back_theme()+'/base.html'%}
2+
3+
{%block head%}
4+
<script src="{{url_for('static', filename='jquery_3.2.1.min.js')}}"></script>
5+
6+
{%endblock%}
7+
{% block content %}
8+
<br>
9+
<div class="container">
10+
<div class="card">
11+
<div class="card-body">
12+
<form method="post">
13+
Site title<br>
14+
<input name="site_title" value="{{get_setting('SITE_TITLE')}}">
15+
<br>
16+
Site description<br>
17+
<textarea
18+
id=""
19+
cols="30"
20+
rows="10"
21+
name="site_description"
22+
>{{get_setting('SITE_DESCRIPTION')}}</textarea>
23+
<br>
24+
<input type="hidden" name="csrf_token" value="{{csrf_token()}}">
25+
<button type="submit">Submit</button>
26+
27+
</form>
28+
</div>
29+
</div>
30+
</div>
31+
{% endblock %}

0 commit comments

Comments
 (0)