new entries schema
This commit is contained in:
BIN
cao_blogr.sqlite
BIN
cao_blogr.sqlite
Binary file not shown.
@@ -1,26 +0,0 @@
|
|||||||
"""init
|
|
||||||
|
|
||||||
Revision ID: bbacde35234d
|
|
||||||
Revises: e7889eab89c0
|
|
||||||
Create Date: 2022-04-19 17:09:50.728285
|
|
||||||
|
|
||||||
"""
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision = 'bbacde35234d'
|
|
||||||
down_revision = 'e7889eab89c0'
|
|
||||||
branch_labels = None
|
|
||||||
depends_on = None
|
|
||||||
|
|
||||||
def upgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.add_column('entries', sa.Column('body_html', sa.UnicodeText(), nullable=True))
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
def downgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.drop_column('entries', 'body_html')
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
"""init
|
|
||||||
|
|
||||||
Revision ID: e7889eab89c0
|
|
||||||
Revises: 5899f27f265f
|
|
||||||
Create Date: 2022-04-19 16:21:57.531003
|
|
||||||
|
|
||||||
"""
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision = 'e7889eab89c0'
|
|
||||||
down_revision = '5899f27f265f'
|
|
||||||
branch_labels = None
|
|
||||||
depends_on = None
|
|
||||||
|
|
||||||
def upgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.add_column('entries', sa.Column('tag', sa.Unicode(), nullable=True))
|
|
||||||
op.add_column('entries', sa.Column('topic', sa.Unicode(), nullable=True))
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
def downgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.drop_column('entries', 'topic')
|
|
||||||
op.drop_column('entries', 'tag')
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
"""init
|
|
||||||
|
|
||||||
Revision ID: 7cfe6f79c819
|
|
||||||
Revises: b6095fa68edc
|
|
||||||
Create Date: 2022-12-08 16:30:41.529957
|
|
||||||
|
|
||||||
"""
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision = '7cfe6f79c819'
|
|
||||||
down_revision = 'b6095fa68edc'
|
|
||||||
branch_labels = None
|
|
||||||
depends_on = None
|
|
||||||
|
|
||||||
def upgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.add_column('users', sa.Column('groups', sa.Unicode(), nullable=True))
|
|
||||||
op.drop_column('users', 'group')
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
def downgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.add_column('users', sa.Column('group', sa.VARCHAR(), nullable=True))
|
|
||||||
op.drop_column('users', 'groups')
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
"""init
|
|
||||||
|
|
||||||
Revision ID: 86d2844ace15
|
|
||||||
Revises: bbacde35234d
|
|
||||||
Create Date: 2022-12-08 15:53:57.291157
|
|
||||||
|
|
||||||
"""
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision = '86d2844ace15'
|
|
||||||
down_revision = 'bbacde35234d'
|
|
||||||
branch_labels = None
|
|
||||||
depends_on = None
|
|
||||||
|
|
||||||
def upgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.add_column('users', sa.Column('group', sa.Unicode(), nullable=True))
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
def downgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.drop_column('users', 'group')
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
"""init
|
|
||||||
|
|
||||||
Revision ID: b6095fa68edc
|
|
||||||
Revises: 86d2844ace15
|
|
||||||
Create Date: 2022-12-08 16:22:49.206993
|
|
||||||
|
|
||||||
"""
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision = 'b6095fa68edc'
|
|
||||||
down_revision = '86d2844ace15'
|
|
||||||
branch_labels = None
|
|
||||||
depends_on = None
|
|
||||||
|
|
||||||
def upgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
pass
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
def downgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
pass
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
"""init
|
"""init
|
||||||
|
|
||||||
Revision ID: 5899f27f265f
|
Revision ID: d335bb2cb9da
|
||||||
Revises:
|
Revises:
|
||||||
Create Date: 2018-12-23 16:39:13.677058
|
Create Date: 2023-01-21 08:05:36.719719
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from alembic import op
|
from alembic import op
|
||||||
@@ -10,21 +10,18 @@ import sqlalchemy as sa
|
|||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
# revision identifiers, used by Alembic.
|
||||||
revision = '5899f27f265f'
|
revision = 'd335bb2cb9da'
|
||||||
down_revision = None
|
down_revision = None
|
||||||
branch_labels = None
|
branch_labels = None
|
||||||
depends_on = None
|
depends_on = None
|
||||||
|
|
||||||
def upgrade():
|
def upgrade():
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
op.create_table('entries',
|
op.create_table('tags',
|
||||||
sa.Column('id', sa.Integer(), nullable=False),
|
sa.Column('id', sa.Integer(), nullable=False),
|
||||||
sa.Column('title', sa.Unicode(length=255), nullable=False),
|
sa.Column('tag', sa.Unicode(length=25), nullable=True),
|
||||||
sa.Column('body', sa.UnicodeText(), nullable=True),
|
sa.Column('tag_name', sa.Unicode(length=25), nullable=False),
|
||||||
sa.Column('created', sa.DateTime(), nullable=True),
|
sa.PrimaryKeyConstraint('id', name=op.f('pk_tags'))
|
||||||
sa.Column('edited', sa.DateTime(), nullable=True),
|
|
||||||
sa.PrimaryKeyConstraint('id', name=op.f('pk_entries')),
|
|
||||||
sa.UniqueConstraint('title', name=op.f('uq_entries_title'))
|
|
||||||
)
|
)
|
||||||
op.create_table('users',
|
op.create_table('users',
|
||||||
sa.Column('id', sa.Integer(), nullable=False),
|
sa.Column('id', sa.Integer(), nullable=False),
|
||||||
@@ -34,10 +31,25 @@ def upgrade():
|
|||||||
sa.PrimaryKeyConstraint('id', name=op.f('pk_users')),
|
sa.PrimaryKeyConstraint('id', name=op.f('pk_users')),
|
||||||
sa.UniqueConstraint('name', name=op.f('uq_users_name'))
|
sa.UniqueConstraint('name', name=op.f('uq_users_name'))
|
||||||
)
|
)
|
||||||
|
op.create_table('entries',
|
||||||
|
sa.Column('id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('title', sa.Unicode(length=255), nullable=False),
|
||||||
|
sa.Column('body', sa.UnicodeText(), nullable=True),
|
||||||
|
sa.Column('created', sa.DateTime(), nullable=True),
|
||||||
|
sa.Column('creator', sa.Unicode(length=50), nullable=True),
|
||||||
|
sa.Column('edited', sa.DateTime(), nullable=True),
|
||||||
|
sa.Column('editor', sa.Unicode(length=50), nullable=True),
|
||||||
|
sa.Column('tag', sa.Unicode(length=25), nullable=True),
|
||||||
|
sa.Column('author', sa.Unicode(length=50), nullable=True),
|
||||||
|
sa.Column('status', sa.Unicode(length=50), nullable=True),
|
||||||
|
sa.PrimaryKeyConstraint('id', name=op.f('pk_entries')),
|
||||||
|
sa.UniqueConstraint('title', name=op.f('uq_entries_title'))
|
||||||
|
)
|
||||||
# ### end Alembic commands ###
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
op.drop_table('users')
|
|
||||||
op.drop_table('entries')
|
op.drop_table('entries')
|
||||||
|
op.drop_table('users')
|
||||||
|
op.drop_table('tags')
|
||||||
# ### end Alembic commands ###
|
# ### end Alembic commands ###
|
||||||
@@ -15,12 +15,14 @@ class BlogRecord(Base):
|
|||||||
__tablename__ = 'entries'
|
__tablename__ = 'entries'
|
||||||
id = Column(Integer, primary_key=True)
|
id = Column(Integer, primary_key=True)
|
||||||
title = Column(Unicode(255), unique=True, nullable=False)
|
title = Column(Unicode(255), unique=True, nullable=False)
|
||||||
body = Column(UnicodeText, default=u'')
|
body = Column(UnicodeText, default='')
|
||||||
body_html = Column(UnicodeText, default=u'')
|
created = Column(DateTime, default=datetime.datetime.now)
|
||||||
tag = Column(Unicode, default='pyramid')
|
creator = Column(Unicode(50), default='')
|
||||||
topic = Column(Unicode, default='blog')
|
edited = Column(DateTime, default=datetime.datetime.now)
|
||||||
created = Column(DateTime, default=datetime.datetime.utcnow)
|
editor = Column(Unicode(50), default='')
|
||||||
edited = Column(DateTime, default=datetime.datetime.utcnow)
|
tag = Column(Unicode(25))
|
||||||
|
author = Column(Unicode(50), default='')
|
||||||
|
status = Column(Unicode(50), default='brouillon')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def slug(self):
|
def slug(self):
|
||||||
@@ -31,3 +33,8 @@ class BlogRecord(Base):
|
|||||||
return distance_of_time_in_words(self.created,
|
return distance_of_time_in_words(self.created,
|
||||||
datetime.datetime.utcnow())
|
datetime.datetime.utcnow())
|
||||||
|
|
||||||
|
|
||||||
|
class Tags(Base):
|
||||||
|
__tablename__ = 'tags'
|
||||||
|
id = Column(Integer, primary_key=True)
|
||||||
|
tag = Column(Unicode(25))
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import datetime #<- will be used to set default dates on models
|
|||||||
|
|
||||||
from sqlalchemy import or_
|
from sqlalchemy import or_
|
||||||
from ..models.blog_record import BlogRecord
|
from ..models.blog_record import BlogRecord
|
||||||
from markdown2 import Markdown
|
|
||||||
|
|
||||||
|
|
||||||
class BlogRecordService(object):
|
class BlogRecordService(object):
|
||||||
@@ -32,26 +32,3 @@ class BlogRecordService(object):
|
|||||||
query = query.order_by(sa.desc(BlogRecord.created)).limit(10).all()
|
query = query.order_by(sa.desc(BlogRecord.created)).limit(10).all()
|
||||||
return query
|
return query
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def proc_after_create(cls, request, _id):
|
|
||||||
entry = request.dbsession.query(BlogRecord).get(_id)
|
|
||||||
# set default values
|
|
||||||
if entry.tag == '':
|
|
||||||
entry.tag = 'pyramid'
|
|
||||||
if entry.topic == '':
|
|
||||||
entry.topic = 'blog'
|
|
||||||
# convertir mardown en HTML
|
|
||||||
markdowner = Markdown()
|
|
||||||
entry.body_html = markdowner.convert(entry.body)
|
|
||||||
return
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def proc_after_update(cls, request, _id):
|
|
||||||
entry = request.dbsession.query(BlogRecord).get(_id)
|
|
||||||
entry.edited = datetime.datetime.now()
|
|
||||||
# convertir mardown en HTML
|
|
||||||
markdowner = Markdown()
|
|
||||||
entry.body_html = markdowner.convert(entry.body)
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<hr/>
|
<hr/>
|
||||||
<p>{{ entry.body_html | safe }}</p>
|
<p>{{ body_html | safe }}</p>
|
||||||
<hr/>
|
<hr/>
|
||||||
{% if request.authenticated_userid %}
|
{% if request.authenticated_userid %}
|
||||||
<p>
|
<p>
|
||||||
|
|||||||
@@ -19,6 +19,8 @@
|
|||||||
<td>{{ entry.tag }}</td>
|
<td>{{ entry.tag }}</td>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{% else %}
|
||||||
|
<p class="text-danger">Aucun post trouvé</p>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ from pyramid.httpexceptions import HTTPNotFound, HTTPFound
|
|||||||
from ..models.blog_record import BlogRecord
|
from ..models.blog_record import BlogRecord
|
||||||
from ..services.blog_record import BlogRecordService
|
from ..services.blog_record import BlogRecordService
|
||||||
from ..forms import BlogCreateForm, BlogUpdateForm, BlogSearchForm
|
from ..forms import BlogCreateForm, BlogUpdateForm, BlogSearchForm
|
||||||
|
import markdown
|
||||||
|
import datetime #<- will be used to set default dates on models
|
||||||
|
|
||||||
@view_config(route_name='blog',
|
@view_config(route_name='blog',
|
||||||
renderer='cao_blogr:templates/blog.jinja2')
|
renderer='cao_blogr:templates/blog.jinja2')
|
||||||
@@ -12,22 +13,23 @@ def blog(request):
|
|||||||
blog_id = request.matchdict['id']
|
blog_id = request.matchdict['id']
|
||||||
entry = BlogRecordService.by_id(request, blog_id)
|
entry = BlogRecordService.by_id(request, blog_id)
|
||||||
|
|
||||||
# just created ? convert body to html
|
|
||||||
if entry.body_html == '':
|
|
||||||
BlogRecordService.proc_after_create(request, blog_id)
|
|
||||||
|
|
||||||
if not entry:
|
if not entry:
|
||||||
request.session.flash(u"Page non trouvée : %s" % blog_id, 'warning')
|
request.session.flash(u"Page non trouvée : %s" % blog_id, 'warning')
|
||||||
return HTTPFound(location=request.route_url('home'))
|
return HTTPFound(location=request.route_url('home'))
|
||||||
|
|
||||||
|
# insèrer le path de static/img
|
||||||
|
body = entry.body.replace('static/', "%s/static/" % request.application_url)
|
||||||
|
# convertir de markdown en HTML
|
||||||
|
body_html = markdown.markdown(body, extensions=['footnotes'])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'page_title': entry.title,
|
'page_title': entry.title,
|
||||||
'entry': entry
|
'entry': entry,
|
||||||
|
'body_html': body_html,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@view_config(route_name='blog_edit',
|
@view_config(route_name='blog_edit', renderer='cao_blogr:templates/blog_edit.jinja2', permission='view')
|
||||||
renderer='cao_blogr:templates/blog_edit.jinja2',
|
|
||||||
permission='view')
|
|
||||||
def blog_edit(request):
|
def blog_edit(request):
|
||||||
# get post id from request
|
# get post id from request
|
||||||
blog_id = request.matchdict['id']
|
blog_id = request.matchdict['id']
|
||||||
@@ -51,15 +53,14 @@ def blog_edit(request):
|
|||||||
if 'form.submitted' in request.params and form.validate():
|
if 'form.submitted' in request.params and form.validate():
|
||||||
if blog_id == '0':
|
if blog_id == '0':
|
||||||
form.populate_obj(entry)
|
form.populate_obj(entry)
|
||||||
|
import pdb;pdb.set_trace()
|
||||||
request.dbsession.add(entry)
|
request.dbsession.add(entry)
|
||||||
|
|
||||||
return HTTPFound(location=request.route_url('home'))
|
return HTTPFound(location=request.route_url('home'))
|
||||||
else:
|
else:
|
||||||
del form.id # SECURITY: prevent overwriting of primary key
|
del form.id # SECURITY: prevent overwriting of primary key
|
||||||
form.populate_obj(entry)
|
form.populate_obj(entry)
|
||||||
|
entry.edited = datetime.datetime.now()
|
||||||
# after update procedure
|
|
||||||
BlogRecordService.proc_after_update(request, blog_id)
|
|
||||||
|
|
||||||
return HTTPFound(location=request.route_url('blog', id=entry.id, slug=entry.slug))
|
return HTTPFound(location=request.route_url('blog', id=entry.id, slug=entry.slug))
|
||||||
|
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -24,7 +24,7 @@ requires = [
|
|||||||
'wtforms', # form library 2.2.1
|
'wtforms', # form library 2.2.1
|
||||||
'webhelpers2', # various web building related helpers 2.0
|
'webhelpers2', # various web building related helpers 2.0
|
||||||
'passlib',
|
'passlib',
|
||||||
'markdown2',
|
'markdown',
|
||||||
]
|
]
|
||||||
|
|
||||||
tests_require = [
|
tests_require = [
|
||||||
|
|||||||
Reference in New Issue
Block a user