Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: site info #340

Merged
merged 1 commit into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions pythoncms/migrations/env.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,43 @@
import logging
from logging.config import fileConfig

from alembic import context
from flask import current_app

from alembic import context

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

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


def get_engine():
try:
# this works with Flask-SQLAlchemy<3 and Alchemical
return current_app.extensions["migrate"].db.get_engine()
return current_app.extensions['migrate'].db.get_engine()
except TypeError:
# this works with Flask-SQLAlchemy>=3
return current_app.extensions["migrate"].db.engine
return current_app.extensions['migrate'].db.engine


def get_engine_url():
try:
return get_engine().url.render_as_string(hide_password=False).replace(
'%', '%%')
except AttributeError:
return str(get_engine().url).replace('%', '%%')


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

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


def get_metadata():
if hasattr(target_db, "metadatas"):
if hasattr(target_db, 'metadatas'):
return target_db.metadatas[None]
return target_db.metadata

Expand All @@ -55,7 +64,9 @@ def run_migrations_offline():

"""
url = config.get_main_option("sqlalchemy.url")
context.configure(url=url, target_metadata=get_metadata(), literal_binds=True)
context.configure(
url=url, target_metadata=get_metadata(), literal_binds=True
)

with context.begin_transaction():
context.run_migrations()
Expand All @@ -73,11 +84,11 @@ 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 = get_engine()

Expand All @@ -86,7 +97,7 @@ def process_revision_directives(context, revision, directives):
connection=connection,
target_metadata=get_metadata(),
process_revision_directives=process_revision_directives,
**current_app.extensions["migrate"].configure_args
**current_app.extensions['migrate'].configure_args
)

with context.begin_transaction():
Expand Down
87 changes: 87 additions & 0 deletions pythoncms/migrations/versions/51daebf34ad3_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
"""empty message

Revision ID: 51daebf34ad3
Revises:
Create Date: 2023-07-03 18:41:32.090382

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '51daebf34ad3'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('contact',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_date', sa.DateTime(), nullable=True),
sa.Column('name', sa.String(length=100), nullable=True),
sa.Column('email', sa.String(length=100), nullable=True),
sa.Column('message', sa.String(length=1024), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('i18n_records',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('strid', sa.String(length=1024), nullable=True),
sa.Column('lang', sa.String(length=10), nullable=True),
sa.Column('string', sa.Text(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('pages',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_date', sa.DateTime(), nullable=True),
sa.Column('title', sa.String(length=100), nullable=True),
sa.Column('slug', sa.String(length=100), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('roles',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=100), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_table('settings',
sa.Column('setting', sa.String(length=100), nullable=False),
sa.Column('value', sa.String(length=100), nullable=True),
sa.PrimaryKeyConstraint('setting')
)
op.create_table('users',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('username', sa.String(length=100), nullable=True),
sa.Column('_password', sa.String(length=128), nullable=False),
sa.Column('first_name', sa.String(length=128), nullable=True),
sa.Column('last_name', sa.String(length=128), nullable=True),
sa.Column('is_admin', sa.Boolean(), nullable=True),
sa.Column('email', sa.String(length=120), nullable=False),
sa.Column('date_registered', sa.DateTime(), nullable=False),
sa.Column('is_email_confirmed', sa.Boolean(), nullable=False),
sa.Column('email_confirm_date', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email'),
sa.UniqueConstraint('username')
)
op.create_table('role_user_bridge',
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('role_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['role_id'], ['roles.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('user_id', 'role_id')
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('role_user_bridge')
op.drop_table('users')
op.drop_table('settings')
op.drop_table('roles')
op.drop_table('pages')
op.drop_table('i18n_records')
op.drop_table('contact')
# ### end Alembic commands ###
94 changes: 0 additions & 94 deletions pythoncms/migrations/versions/7d11df1f6a08_.py

This file was deleted.

Empty file.
Empty file.
Empty file.
Empty file.
16 changes: 16 additions & 0 deletions pythoncms/modules/box__default/info/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"display_string": "Site Info",
"module_name":"info",
"type": "show",
"icons":{
"fa": "fa fa-edit",
"boxicons": "bx bx-pen"
},
"url_prefix": "/info",
"dashboard": "/dashboard",
"author": {
"name": "Abdur-Rahmaan Janhangeer",
"website": "https://www.pythonkitchen.com/about-me/",
"mail": "[email protected]"
}
}
Empty file.
31 changes: 31 additions & 0 deletions pythoncms/modules/box__default/info/templates/info/dashboard.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{%extends get_active_back_theme()+'/base.html'%}

{%block head%}
<script src="{{url_for('static', filename='jquery_3.2.1.min.js')}}"></script>

{%endblock%}
{% block content %}
<br>
<div class="container">
<div class="card">
<div class="card-body">
<form method="post">
Site title<br>
<input name="site_title" value="{{get_setting('SITE_TITLE')}}">
<br>
Site description<br>
<textarea
id=""
cols="30"
rows="10"
name="site_description"
>{{get_setting('SITE_DESCRIPTION')}}</textarea>
<br>
<input type="hidden" name="csrf_token" value="{{csrf_token()}}">
<button type="submit">Submit</button>

</form>
</div>
</div>
</div>
{% endblock %}
33 changes: 33 additions & 0 deletions pythoncms/modules/box__default/info/view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from flask import redirect
from flask import render_template
from flask import request
from flask import url_for
from flask_login import login_required
from init import db
from shopyo.api.forms import flash_errors
from shopyo.api.module import ModuleHelp

mhelp = ModuleHelp(__file__, __name__)
globals()[mhelp.blueprint_str] = mhelp.blueprint
module_blueprint = globals()[mhelp.blueprint_str]


# @module_blueprint.route(mhelp.info["dashboard"] + "/all")
# def index_all():
# context = {}
# pages = Page.query.all()

# context.update({"pages": pages})
# return render_template("page/all_pages.html", **context)

from modules.box__default.settings.helpers import set_setting
from modules.box__default.settings.helpers import get_setting

@module_blueprint.route(mhelp.info["dashboard"], methods=['POST', 'GET'])
@login_required
def index():
if request.method == 'POST':
print(request.form)
set_setting('SITE_TITLE', request.form['site_title'])
set_setting('SITE_DESCRIPTION', request.form['site_description'])
return mhelp.render('dashboard.html', get_setting=get_setting)
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" style="fill: rgb(255, 255, 255);transform: ;msFilter:;"><path d="M21 11H6.414l5.293-5.293-1.414-1.414L2.586 12l7.707 7.707 1.414-1.414L6.414 13H21z"></path></svg>
</button>
</a>
<a class="btn btn-lnk btn-primary" target="_blank" href="{{ url_for('page.view_page', slug=page.slug) }}">view</a>
<br><br>
<form action="{{url_for('{}.edit_pagecontent'.format(module_name))}}" method="POST">
{{ form.title.label }}
Expand Down
2 changes: 1 addition & 1 deletion pythoncms/modules/box__default/page/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def view_page_dashboard(slug):
return render_template("page/view_page_dashboard.html", **context)


@module_blueprint.route("/s/<slug>", methods=["GET"])
@module_blueprint.route("/<slug>", methods=["GET"])
def view_page(slug):
context = {}
page = Page.query.filter(Page.slug == slug).first()
Expand Down
Loading