diff --git a/data_static/Tag.csv b/data_static/Tag.csv new file mode 100644 index 0000000..e596e2c --- /dev/null +++ b/data_static/Tag.csv @@ -0,0 +1,20 @@ +name +English +"Български" +"политика" +politics +technology +"технологии" +hacks +"мнения" +opinions +projects +"проекти" +"есета" +essays +"лични" +personal +university +learning +life +"живот" diff --git a/data_static/_process_order b/data_static/_process_order index 942a1ea..cdf738e 100644 --- a/data_static/_process_order +++ b/data_static/_process_order @@ -1,2 +1,5 @@ +Tag +BlogPost +blog_post__tag Role User \ No newline at end of file diff --git a/data_static/blog_post__tag.csv b/data_static/blog_post__tag.csv new file mode 100644 index 0000000..0ab320e --- /dev/null +++ b/data_static/blog_post__tag.csv @@ -0,0 +1,156 @@ +blog_post_id,tag_id +1,2 +1,3 +51,2 +51,3 +50,1 +51,6 +51,8 +1,8 +2,1 +2,9 +30,1 +30,5 +30,9 +34,2 +34,12 +43,2 +43,3 +43,8 +53,2 +53,3 +44,2 +44,3 +44,12 +47,2 +47,3 +47,8 +48,1 +48,13 +45,2 +45,11 +31,1 +31,15 +4,1 +4,16 +6,1 +6,16 +9,1 +9,16 +10,1 +10,16 +11,1 +11,16 +12,1 +12,16 +15,1 +15,16 +16,1 +16,16 +17,1 +17,16 +18,1 +18,16 +19,1 +19,16 +20,1 +20,16 +23,1 +23,16 +24,1 +24,16 +25,1 +25,16 +26,1 +26,16 +27,1 +27,16 +29,1 +29,16 +32,1 +32,16 +37,1 +37,16 +39,1 +39,16 +40,1 +40,16 +41,1 +41,16 +42,1 +42,7 +50,4 +49,1 +49,17 +21,1 +21,5 +21,7 +28,2 +28,3 +3,1 +3,5 +3,13 +5,1 +5,5 +5,13 +7,1 +7,13 +7,18 +8,1 +8,5 +8,7 +13,1 +13,16 +14,1 +14,5 +14,7 +22,1 +22,13 +22,18 +33,2 +33,8 +38,1 +38,9 +35,1 +35,5 +35,10 +35,17 +36,1 +36,13 +36,15 +36,18 +46,2 +46,6 +46,8 +52,2 +54,2 +54,8 +55,2 +56,2 +57,2 +57,12 +57,14 +57,19 +58,2 +58,14 +59,2 +59,8 +59,19 +60,2 +60,3 +60,8 +61,2 +61,6 +61,8 +62,2 +62,6 +62,8 +63,2 +63,14 +64,2 +64,14 +64,19 +65,2 +65,12 +66,2 +66,8 diff --git a/data_static/media/20120322_matura/maturatest.png b/data_static/media/20120322_matura/maturatest.png new file mode 100644 index 0000000..4de8580 Binary files /dev/null and b/data_static/media/20120322_matura/maturatest.png differ diff --git a/data_static/media/20120322_matura/timeline.png b/data_static/media/20120322_matura/timeline.png new file mode 100644 index 0000000..8eef1cd Binary files /dev/null and b/data_static/media/20120322_matura/timeline.png differ diff --git a/migrations/versions/28f9ab4fc8b0_002.py b/migrations/versions/28f9ab4fc8b0_002.py deleted file mode 100644 index 1e5952b..0000000 --- a/migrations/versions/28f9ab4fc8b0_002.py +++ /dev/null @@ -1,41 +0,0 @@ -"""002 - -Revision ID: 28f9ab4fc8b0 -Revises: d08a068031c3 -Create Date: 2020-07-08 14:27:11.649888 - -""" -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '28f9ab4fc8b0' -down_revision = 'd08a068031c3' -branch_labels = None -depends_on = None - - -def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.create_table('blog_post', - sa.Column('created_dt', sa.UnicodeText(), nullable=True), - sa.Column('updated_dt', sa.UnicodeText(), nullable=True), - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('uuid', sa.Unicode(), nullable=True), - sa.Column('filename', sa.UnicodeText(), nullable=True), - sa.Column('title', sa.UnicodeText(), nullable=True), - sa.Column('body', sa.UnicodeText(), nullable=True), - sa.Column('user_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('id') - ) - op.create_index(op.f('ix_blog_post_uuid'), 'blog_post', ['uuid'], unique=False) - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.drop_index(op.f('ix_blog_post_uuid'), table_name='blog_post') - op.drop_table('blog_post') - # ### end Alembic commands ### diff --git a/migrations/versions/d08a068031c3_001.py b/migrations/versions/d091fbf48f6f_001.py similarity index 60% rename from migrations/versions/d08a068031c3_001.py rename to migrations/versions/d091fbf48f6f_001.py index fb9df37..985ea69 100644 --- a/migrations/versions/d08a068031c3_001.py +++ b/migrations/versions/d091fbf48f6f_001.py @@ -1,8 +1,8 @@ """001 -Revision ID: d08a068031c3 +Revision ID: d091fbf48f6f Revises: -Create Date: 2020-07-08 11:48:15.369556 +Create Date: 2021-05-01 11:54:58.288320 """ from alembic import op @@ -10,7 +10,7 @@ import sqlalchemy as sa # revision identifiers, used by Alembic. -revision = 'd08a068031c3' +revision = 'd091fbf48f6f' down_revision = None branch_labels = None depends_on = None @@ -53,18 +53,51 @@ def upgrade(): sa.UniqueConstraint('email') ) op.create_index(op.f('ix_user_uuid'), 'user', ['uuid'], unique=False) + op.create_table('blog_post', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('uuid', sa.Unicode(), nullable=True), + sa.Column('filename', sa.UnicodeText(), nullable=True), + sa.Column('title', sa.UnicodeText(), nullable=True), + sa.Column('body', sa.UnicodeText(), nullable=True), + sa.Column('created_dt', sa.UnicodeText(), nullable=True), + sa.Column('updated_dt', sa.UnicodeText(), nullable=True), + sa.Column('user_id', sa.Integer(), nullable=True), + sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_index(op.f('ix_blog_post_uuid'), 'blog_post', ['uuid'], unique=False) op.create_table('roles_users', 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'], ) ) + op.create_table('tag', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('uuid', sa.Unicode(), nullable=True), + sa.Column('name', sa.UnicodeText(), nullable=True), + sa.Column('user_id', sa.Integer(), nullable=True), + sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_index(op.f('ix_tag_uuid'), 'tag', ['uuid'], unique=False) + op.create_table('blog_post__tag', + sa.Column('blog_post_id', sa.Integer(), nullable=True), + sa.Column('tag_id', sa.Integer(), nullable=True), + sa.ForeignKeyConstraint(['blog_post_id'], ['blog_post.id'], ), + sa.ForeignKeyConstraint(['tag_id'], ['tag.id'], ) + ) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('blog_post__tag') + op.drop_index(op.f('ix_tag_uuid'), table_name='tag') + op.drop_table('tag') op.drop_table('roles_users') + op.drop_index(op.f('ix_blog_post_uuid'), table_name='blog_post') + op.drop_table('blog_post') op.drop_index(op.f('ix_user_uuid'), table_name='user') op.drop_table('user') op.drop_table('task') diff --git a/webapp/models/__init__.py b/webapp/models/__init__.py index 2f0e777..569feb8 100644 --- a/webapp/models/__init__.py +++ b/webapp/models/__init__.py @@ -1,2 +1,3 @@ from oshipka.persistance import db +from webapp.models.tag import Tag from webapp.models.blog_post import BlogPost diff --git a/webapp/models/_blog_post.py b/webapp/models/_blog_post.py index b008aa7..9e15c7e 100644 --- a/webapp/models/_blog_post.py +++ b/webapp/models/_blog_post.py @@ -1,5 +1,10 @@ from oshipka.persistance import db, ModelController, index_service, LiberalBoolean, Ownable +blog_post__tag = db.Table('blog_post__tag', + db.Column('blog_post_id', db.Integer(), db.ForeignKey('blog_post.id')), + db.Column('tag_id', db.Integer(), db.ForeignKey('tag.id')), + ) + class BlogPost(db.Model, ModelController, Ownable): __searchable__ = ['body', ] @@ -7,6 +12,11 @@ class BlogPost(db.Model, ModelController, Ownable): filename = db.Column(db.UnicodeText,) title = db.Column(db.UnicodeText,) body = db.Column(db.UnicodeText,) + tags = db.relationship('Tag', secondary=blog_post__tag, + backref=db.backref("blog_posts"), + ) + + _m_n_table_tags = 'Tag' created_dt = db.Column(db.UnicodeText,) updated_dt = db.Column(db.UnicodeText,) diff --git a/webapp/models/_tag.py b/webapp/models/_tag.py new file mode 100644 index 0000000..11ba1c5 --- /dev/null +++ b/webapp/models/_tag.py @@ -0,0 +1,8 @@ +from oshipka.persistance import db, ModelController, index_service, LiberalBoolean, Ownable + + +class Tag(db.Model, ModelController, Ownable): + name = db.Column(db.UnicodeText,) + + def __repr__(self): + return "{}".format(self.name) diff --git a/webapp/models/tag.py b/webapp/models/tag.py new file mode 100644 index 0000000..ddd6278 --- /dev/null +++ b/webapp/models/tag.py @@ -0,0 +1 @@ +from webapp.models._tag import Tag \ No newline at end of file diff --git a/webapp/routes/__init__.py b/webapp/routes/__init__.py index 0db7492..191e322 100644 --- a/webapp/routes/__init__.py +++ b/webapp/routes/__init__.py @@ -1 +1,2 @@ +from webapp.routes.tag import * from webapp.routes.blog_post import * diff --git a/webapp/routes/tag.py b/webapp/routes/tag.py new file mode 100644 index 0000000..320ba4b --- /dev/null +++ b/webapp/routes/tag.py @@ -0,0 +1,68 @@ +""" +!!!AUTOGENERATED: DO NOT EDIT!!! + +Edit the hooks in webapp/routes/tag_hooks.py instead +""" + +from oshipka.webapp import app +from oshipka.webapp.views import ModelView +from webapp.models import Tag +from webapp.routes.tag_hooks import * + +tag = ModelView(app, Tag) + +tag.register_verb(view_context=get_view_context, + verb="get", + methods=['GET'], + per_item=True, + is_login_required=False, + the_roles_required=[], + ) + +tag.register_verb(view_context=list_view_context, + verb="list", + methods=['GET'], + per_item=False, + is_login_required=False, + the_roles_required=[], + ) + +tag.register_verb(view_context=table_view_context, + verb="table", + methods=['GET'], + per_item=False, + is_login_required=False, + the_roles_required=[], + ) + +tag.register_verb(view_context=search_view_context, + verb="search", + methods=['GET'], + per_item=False, + is_login_required=False, + the_roles_required=[], + ) + +tag.register_verb(view_context=create_view_context, + verb="create", + methods=['GET', 'POST'], + per_item=False, + is_login_required=True, + the_roles_required=['admin'], + ) + +tag.register_verb(view_context=update_view_context, + verb="update", + methods=['GET', 'POST'], + per_item=True, + is_login_required=True, + the_roles_required=['admin'], + ) + +tag.register_verb(view_context=delete_view_context, + verb="delete", + methods=['GET', 'POST'], + per_item=True, + is_login_required=True, + the_roles_required=['admin'], + ) diff --git a/webapp/routes/tag_hooks.py b/webapp/routes/tag_hooks.py new file mode 100644 index 0000000..164439a --- /dev/null +++ b/webapp/routes/tag_hooks.py @@ -0,0 +1,71 @@ +from oshipka.webapp.views import ViewContext, default_get_args_func, default_get_func, default_list_func, \ + default_get_form_func, default_create_func, default_update_func, default_delete_func, default_search_func + + +def get_template(vc): + vc.template = "{}/get.html".format(vc.model_view.model_name) + + +def list_template(vc): + vc.template = "{}/list.html".format(vc.model_view.model_name) + + +def table_template(vc): + vc.template = "{}/table.html".format(vc.model_view.model_name) + + +def search_template(vc): + vc.template = "{}/search.html".format(vc.model_view.model_name) + + +def create_template(vc): + vc.template = "{}/create.html".format(vc.model_view.model_name) + + +def update_template(vc): + vc.template = "{}/update.html".format(vc.model_view.model_name) + + +def delete_template(vc): + vc.template = "delete_instance.html".format(vc.model_view.model_name) + + +get_view_context = ViewContext( + filter_func=default_get_func, + template_func=get_template, +) + +list_view_context = ViewContext( + filter_func=default_list_func, + template_func=list_template, +) + +table_view_context = ViewContext( + filter_func=default_list_func, + template_func=table_template, +) + +search_view_context = ViewContext( + filter_func=default_search_func, + template_func=list_template, +) + +create_view_context = ViewContext( + args_get_func=default_get_form_func, + template_func=create_template, + execute_func=default_create_func, +) + +update_view_context = ViewContext( + args_get_func=default_get_form_func, + filter_func=default_get_func, + template_func=update_template, + execute_func=default_update_func, +) + +delete_view_context = ViewContext( + args_get_func=default_get_form_func, + filter_func=default_get_func, + template_func=delete_template, + execute_func=default_delete_func, +) diff --git a/webapp/templates/blog_post/_create.html b/webapp/templates/blog_post/_create.html index 840025e..f9df3fc 100644 --- a/webapp/templates/blog_post/_create.html +++ b/webapp/templates/blog_post/_create.html @@ -25,6 +25,24 @@
{{ _("name") }} | + {% endif %} +{{ _("Actions") }} | +
---|---|
+ {{ instance.name }} + | + {% endif %} ++ e | + x + | +