BBS论坛(三十一)
31.帖子加精和取消加精功能完成
(1)apps/models.py
class HighLight(db.Model):
__tablename__='highlight_post'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
post_id=db.Column(db.Integer,db.ForeignKey('post.id'))
create_time=db.Column(db.DateTime,default=datetime.now) post=db.relationship('PostModel',backref='highlight')
(2)cms/views.py
@bp.route('/posts/')
@login_required
@permission_required(CMSPermission.POSTER)
def posts():
context = {
'posts': PostModel.query.all()
}
return render_template('cms/cms_posts.html',**context) @bp.route('/hpost/',methods=['POST'])
@login_required
@permission_required(CMSPermission.POSTER)
def hpost():
post_id=request.form.get('post_id')
if not post_id:
return restful.params_error(message='请传入帖子id')
post=PostModel.query.get(post_id)
if not post:
return restful.params_error(message='没有这篇帖子')
highlight=HighLight()
highlight.post=post
db.session.add(highlight)
db.session.commit()
return restful.success() @bp.route('/uhpost/',methods=['POST'])
@login_required
@permission_required(CMSPermission.POSTER)
def uhpost():
post_id = request.form.get('post_id')
if not post_id:
return restful.params_error(message='请传入帖子id')
post = PostModel.query.get(post_id)
if not post:
return restful.params_error(message='没有这篇帖子')
print(post_id)
highlight=HighLight.query.filter_by(post_id=post_id).first()
print(highlight)
db.session.delete(highlight)
db.session.commit()
return restful.success()
(3)cms_posts.html
{% extends 'cms/cms_base.html' %}
{% from 'common/_macros.html' import static %}
{% block title %}
帖子管理
{% endblock %} {% block head %}
<script src="{{ static('cms/js/posts.js') }}"></script>
{% endblock %} {% block page_title %}
{{ self.title() }}
{% endblock %} {% block main_content %}
<table class="table table-bordered">
<thead>
<tr>
<th>标题</th>
<th>发布时间</th>
<th>版块</th>
<th>作者</th>
<th>操作</th>
</tr>
</thead>
<tbody>
{% for post in posts %}
<tr data-id={{ post.id }} data-highlight={{ 1 if post.highlight else 0 }}>
<td><a target="_blank" href="{{ url_for('front.post_detail',post_id=post.id) }}">{{ post.title }}</a>
</td>
<td>{{ post.create_time }}</td>
<td>{{ post.board.name }}</td>
<td>{{ post.author.username }}</td>
<td>
{% if post.highlight %}
<button class="btn btn-info btn-xs highlight-btn">取消加精</button>
{% else %}
<button class="btn btn-danger btn-xs highlight-btn">加精</button>
{% endif %}
<button class="btn btn-default btn-xs">移除</button>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
(4)cms/js/posts.js
$(function(){
$('.highlight-btn').on('click',function(){
var $this=$(this);
var tr=$this.parent().parent();
var post_id=tr.attr('data-id');
var highlight=parseInt(tr.attr('data-highlight'));
var url='';
if(highlight){
url='/cms/uhpost/'
}else{
url='/cms/hpost/'
}
zlajax.post({
'url':url,
'data':{
'post_id':post_id
},
'success':function(data){
if(data['code']==200){
zlalert.alertSuccessToast('操作成功');
setTimeout(function(){
window.location.reload();
},500);
}else{
zlalert.alertInfo(data['message']);
}
}
})
});
});
BBS论坛(三十一)的更多相关文章
- BBS论坛(十一)
11.1.前台用户模型创建 (1)apps/front/models.py 首先安装:pip install shortuuid class FrontUser(db.Model): __tablen ...
- python第一百三十天 ---简单的BBS论坛
简单的BBS论坛 实现功能 git仓库地址:https://github.com/uge3/BBS 1.整体参考“抽屉新热榜” + “博客园” 2.实现不同论坛版块 3.帖子列表展示 4.个人博客主页 ...
- centos 邮件服务 腾讯企业邮箱(免费) 使用iRedmail 需要有公网的centos主机 发邮件协议:smtp 端口25 收邮件协议:pop3 端口110 iredmail安装配置 使用邮箱系统 第三十一节课
centos 邮件服务 腾讯企业邮箱(免费) 使用iRedmail 需要有公网的centos主机 发邮件协议:smtp 端口25 收邮件协议:pop3 端口110 iredmail安装配置 ...
- Django项目 BBS论坛
BBS论坛 一.项目表分析 二.自定义form组件 三.注册功能 四.BBS论坛 登录功能
- BBS论坛 注册功能
三.注册功能 # views.py文件 def register(request): back_dic = {'code': 100, 'msg': ''} form_obj = myforms.My ...
- 【FastDev4Android框架开发】RecyclerView完全解析之下拉刷新与上拉加载SwipeRefreshLayout(三十一)
转载请标明出处: http://blog.csdn.net/developer_jiangqq/article/details/49992269 本文出自:[江清清的博客] (一).前言: [好消息] ...
- Java,面试题,简历,Linux,大数据,常用开发工具类,API文档,电子书,各种思维导图资源,百度网盘资源,BBS论坛系统 ERP管理系统 OA办公自动化管理系统 车辆管理系统 各种后台管理系统
Java,面试题,简历,Linux,大数据,常用开发工具类,API文档,电子书,各种思维导图资源,百度网盘资源BBS论坛系统 ERP管理系统 OA办公自动化管理系统 车辆管理系统 家庭理财系统 各种后 ...
- Python之路【第十八篇】Django小项目简单BBS论坛部分内容知识点
开发一个简单的BBS论坛 项目需求: 整体参考“抽屉新热榜” + “虎嗅网” 实现不同论坛版块 帖子列表展示 帖子评论数.点赞数展示 在线用户展示 允许登录用户发贴.评论.点赞 允许上传文件 帖子可被 ...
- python 学习笔记二十 django项目bbs论坛
项目:开发一个简单的BBS论坛 需求: 整体参考“抽屉新热榜” + “虎嗅网” 实现不同论坛版块 帖子列表展示 帖子评论数.点赞数展示 在线用户展示 允许登录用户发贴.评论.点赞 允许上传文件 帖子可 ...
- Bootstrap <基础三十一>插件概览
在前面布局组件中所讨论到的组件仅仅是个开始.Bootstrap 自带 12 种 jQuery 插件,扩展了功能,可以给站点添加更多的互动.即使不是一名高级的 JavaScript 开发人员,也可以着手 ...
随机推荐
- python url参数转dict
from urllib import parse url='_from=R40&LH_BIN=1&_sop=13&LH_Complete=1&LH_Sold=1& ...
- 想不想在mac上玩PSP?我教你呀
OpenEmu for mac是一款针对OS X系统的原生开源游戏模拟器.有了它可以在Mac OS X 系统上玩GB.GBA.NDS.psP.PlayStation.超级任天堂(SNES).红白机(N ...
- 如何用js去判断当前是否在微信中打开的链接页面
function is_weixin() { var ua = navigator.userAgent.toLowerCase(); if (ua.match(/MicroMessenger/i) = ...
- VSTO 基础随笔
1.往组合框添加条目 With Me .ComboBox1.Items .Add( "Ports" ) .Add( "Igor" ) End With 2.文本 ...
- MonggoDB(二)
分组聚合 如果你有数据存储在MongoDB中,你想做的可能就不仅仅是将数据提取出来这么简单,可能需要对数据进行分析并加以利用. 聚合框架:可以使用多个构件创建一个管道,上一个构件的结果传给下一个构件. ...
- [CF893F] Subtree Minimum Query
Description: 给定一棵树,每次询问某点子树中到其不超过k的所有点的最小点权 强制在线 Hint: \(n,m\le 10^5\) Solution: 看到题目第一反应是以深度为下标,dfs ...
- 实现logstash6.4.3 同步mysql数据到Elasticsearch6.4.3
本文旨在实践把mysql已有的数据同步到elasticsearch中,使用的版本是6.4.3,对于其它6.x版本理应是一样的处理方式. 本文目录: 1.初始化Elasticsearch 6.4.3 1 ...
- Python(day1)
一.Python的属于解释型语言. 编译型:一次性,将全部的程序编译成二进制文件,然后再运行. 优点:运行速度快. 缺点:开发效率低,不能跨平台. 解释型:当你的程序运行时,一行一行的解释,并运行. ...
- 封装ajax原理
封装ajax原理 首先处理 用户如果不传某些参数,设置默认值 type默认get 默认url为当前页 默认async方式请求 data数据默认为{} 处理用户传进来的参数对象 遍历,拼接成key=va ...
- pymongo的操作
实例化和插入 from pymongo import MongoClient class TestMongo: def __init__(self): client = MongoClient(hos ...