Skip to content

Commit

Permalink
1.bug:can not sit to mysql-change Plugin model menu_id, default = Non…
Browse files Browse the repository at this point in the history
…e 2.bug:can not get blog-info-use ajax to solve
  • Loading branch information
xpleaf committed Mar 6, 2016
1 parent 351199d commit 30ed1cb
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 21 deletions.
23 changes: 19 additions & 4 deletions app/admin/views.py
Expand Up @@ -638,23 +638,38 @@ def custom_blog_info():

navbars = [(1, u'魅力黑'), (2, u'优雅白')]
form.navbar.choices = navbars
blog = BlogInfo.query.first()

if form.validate_on_submit():
blog = BlogInfo.query.first()
blog.title = form.title.data
blog.signature = form.signature.data
if form.navbar.data == 1:
blog.navbar = 'inverse'
if form.navbar.data ==2 :
if form.navbar.data == 2:
blog.navbar = 'default'
db.session.add(blog)
db.session.commit()

flash(u'修改博客基本信息成功!', 'success')
return redirect(url_for('admin.custom_blog_info'))

return render_template('admin/custom_blog_info.html',
form=form, blog=blog)
return render_template('admin/custom_blog_info.html', form=form)


@admin.route('/custom/blog-info/get')
@login_required
def get_blog_info():
if request.is_xhr:
blog = BlogInfo.query.first()
if blog.navbar == 'inverse':
navbar = 1
if blog.navbar == 'default':
navbar = 2
return jsonify({
'title': blog.title,
'signature':blog.signature,
'navbar': navbar,
})


@admin.route('/custom/blog-plugin', methods=['GET', 'POST'])
Expand Down
2 changes: 1 addition & 1 deletion app/models.py
Expand Up @@ -131,7 +131,7 @@ class ArticleType(db.Model):
name = db.Column(db.String(64), unique=True)
introduction = db.Column(db.Text, default=None)
articles = db.relationship('Article', backref='articleType', lazy='dynamic')
menu_id = db.Column(db.Integer, db.ForeignKey('menus.id'), default=-1)
menu_id = db.Column(db.Integer, db.ForeignKey('menus.id'), default=None)
setting_id = db.Column(db.Integer, db.ForeignKey('articleTypeSettings.id'))

@staticmethod
Expand Down
3 changes: 3 additions & 0 deletions app/static/css/common.css
Expand Up @@ -12,6 +12,9 @@ body {
.content {
min-height: 800px;
}
.article-entry-sum {
margin-top: 5px;
}
.entry-box {
background: #fff;
padding: 15px;
Expand Down
10 changes: 7 additions & 3 deletions app/static/js/admin.js
Expand Up @@ -149,11 +149,15 @@ function delArticleTypeNavCfm(url) {
}

//JS For editing blog info
$(document).ready(function() {
$('#editBlogInfo').click(function() {
function get_blog_info(url) {
$.getJSON(url, function(data) {
console.log(data);
$('#title').val(data.title);
$('#signature').val(data.signature);
$('#navbar').val(data.navbar);
$('#editBlogInfoFormModal').modal();
});
});
}

//JS For confirm to delete a plugin
function delPluginCfm(url) {
Expand Down
7 changes: 4 additions & 3 deletions app/templates/admin/custom_blog_info.html
Expand Up @@ -22,7 +22,8 @@ <h5 class="info-header"><strong>导航样式:</strong></h5>
{% endif %}
</i>
<div class="add-articleType-nav">
<a class="btn btn-sm btn-primary blog-info-btn" id="editBlogInfo">
<a class="btn btn-sm btn-primary blog-info-btn" id="editBlogInfo"
onclick="get_blog_info('{{ url_for('admin.get_blog_info') }}')">
<span class="glyphicon glyphicon-edit"></span>
修改
</a>
Expand All @@ -44,9 +45,9 @@ <h4 class="modal-title">修改基本信息</h4>
<div class="form-group">
{{ form.csrf_token }}
{{ form.title.label }}
{{ form.title(class='form-control', required='', value=blog.title) }}
{{ form.title(class='form-control', required='') }}
{{ form.signature.label }}
{{ form.signature(class='form-control', required='', value=blog.signature) }}
{{ form.signature(class='form-control', required='') }}
{{ form.navbar.label }}
{{ form.navbar(class='form-control', required='') }}
</div>
Expand Down
@@ -1,13 +1,13 @@
"""ready for deplying
"""fit to MySQL
Revision ID: 5e321c21ec2a
Revision ID: 051691f120e6
Revises: None
Create Date: 2016-03-05 21:49:03.285373
Create Date: 2016-03-06 19:11:38.238238
"""

# revision identifiers, used by Alembic.
revision = '5e321c21ec2a'
revision = '051691f120e6'
down_revision = None

from alembic import op
Expand All @@ -27,7 +27,7 @@ def upgrade():
op.create_table('blog_info',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('title', sa.String(length=64), nullable=True),
sa.Column('signature', sa.String(length=128), nullable=True),
sa.Column('signature', sa.Text(), nullable=True),
sa.Column('navbar', sa.String(length=64), nullable=True),
sa.PrimaryKeyConstraint('id')
)
Expand All @@ -46,8 +46,8 @@ def upgrade():
op.create_table('plugins',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('title', sa.String(length=64), nullable=True),
sa.Column('note', sa.String(length=128), nullable=True),
sa.Column('content', sa.String(), nullable=True),
sa.Column('note', sa.Text(), nullable=True),
sa.Column('content', sa.Text(), nullable=True),
sa.Column('order', sa.Integer(), nullable=True),
sa.Column('disabled', sa.Boolean(), nullable=True),
sa.PrimaryKeyConstraint('id'),
Expand All @@ -72,7 +72,7 @@ def upgrade():
op.create_table('articleTypes',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=64), nullable=True),
sa.Column('introduction', sa.String(length=128), nullable=True),
sa.Column('introduction', sa.Text(), nullable=True),
sa.Column('menu_id', sa.Integer(), nullable=True),
sa.Column('setting_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['menu_id'], ['menus.id'], ),
Expand Down Expand Up @@ -106,8 +106,8 @@ def upgrade():
sa.Column('avatar_hash', sa.String(length=32), nullable=True),
sa.Column('article_id', sa.Integer(), nullable=True),
sa.Column('disabled', sa.Boolean(), nullable=True),
sa.Column('comment_type', sa.String(), nullable=True),
sa.Column('reply_to', sa.String(), nullable=True),
sa.Column('comment_type', sa.String(length=64), nullable=True),
sa.Column('reply_to', sa.String(length=128), nullable=True),
sa.ForeignKeyConstraint(['article_id'], ['articles.id'], ),
sa.PrimaryKeyConstraint('id')
)
Expand Down

0 comments on commit 30ed1cb

Please sign in to comment.