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 开发人员,也可以着手 ...
随机推荐
- Redis持久化persistence
一.前言 由于Redis的数据都存放在内存中,如果没有配置持久化,redis重启后数据就全丢失了,于是需要开启redis的持久化功能,将数据保存到磁盘上,当redis重启后,可以从磁盘中恢复数据. R ...
- SpringBoot热部署
SpringBoot的热部署方式分为两种 1.SpringLoader 方式一:以maven插件方式使用SpringLoader <!-- Springloader插件 --> 1.1 ...
- vue基础5-生命周期
1.vue实例的生命周期 1.1.什么是生命周期? --从Vue实例创建.运行.销毁期间,总是伴随着各式各样的事件,这些事件,统称为生命周期! 1.2.生命周期钩子:就是生命周期事件的别名而已: ...
- python: 列表的方法
操作 函数 使用方法 备注 索引 index in: example.index(‘creative’) --- 1 in:example[1,] --- [’creative’, [’京东’,996 ...
- python 在ubuntu下安装pycurl
https://www.linuxidc.com/Linux/2016-05/131574.htm
- 20162329张旭升 2018-2019-2《网络对抗技术》第1周 Kali的安装
目录 Kali的安装 设置与主机的文件交互 Kali的安装 1.创建虚拟机 2.选择安装语言 3.设置网络 4.设置分区 5.安装完成 设置与主机的文件交互 首先在vmware workstation ...
- spring为什么推荐使用构造器注入?
闲谈 Spring框架对Java开发的重要性不言而喻,其核心特性就是IOC(Inversion of Control, 控制反转)和AOP,平时使用最多的就是其中的IOC,我们通过将组件交由Spr ...
- windows下编译SDL1.2
首先,官网下载开发库,我这里用的是tdm-gcc,因此下载mingw版的. 解压,写代码,编译…… 成功!...地出错了 这里提一下,编译命令是 g++ test.cpp -I include目录 ...
- fildder
来自 墨痕 :https://home.cnblogs.com/u/ink-marks/ FIDDLER的使用方法及技巧总结 一.FIDDLER快速入门及使用场景 Fiddler的官方网站:htt ...
- XGBoost原理和公式推导
本篇文章主要介绍下Xgboost算法的原理和公式推导.关于XGB的一些应用场景在此就不赘述了,感兴趣的同学可以自行google.下面开始: 1.模型构建 构建最优模型的方法一般是最小化训练数据的损失 ...