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 开发人员,也可以着手 ...
随机推荐
- c/c++再学习:查找算法了解
1.顺序查找 说明:顺序查找适合于存储结构为顺序存储或链接存储的线性表. 基本思想:顺序查找也称为线形查找,属于无序查找算法.从数据结构线形表的一端开始,顺序扫描,依次将扫描到的结点关键字与给定值k相 ...
- android调试工具 adb命令学习
查看Android版本号 adb shell getprop ro.build.version.release getprop ro.build.version.release 5.1 查看Andro ...
- pycharm远程debug(内网环境,跳板机)
1.设置隧道 工具: secureCRT 1.新建跳板机连接session 2.选择刚建好的session --> Properties --> Port Forwarding --> ...
- Codeforces 446A. DZY Loves Sequences (线性DP)
<题目链接> 题目大意: 给定一个长度为$n$的序列,现在最多能够改变其中的一个数字,使其变成任意值.问你这个序列的最长严格上升子段的长度是多少. #include <bits/st ...
- Array库
/** * 查找元素在数组中出现的所有位置 * @param {要查找的数组} array * @param {要查找的元素} ele * @param {回调函数} callback */ func ...
- tensorflow 使用 3 模型学习
模型学习 import tensorflow as tf import numpy as np # 生成 100 个随机的点 x_data = np.random.rand( 100 ) y_data ...
- webpack 4+ vue-loader 配置 (完善中...)
webpack 4+ vue-loader 配置 写的demo,clone下来后,npm run dev即可,(此demo并未加入router) 可能会由于版本问题,配置会有些许改动,暂时都是可用的 ...
- [POJ2259]Team Queue (队列,模拟)
2559是栈,2259是队列,真的是巧啊 题意 模拟队列 思路 水题 代码 因为太水,不想打,发博客只是为了与2559照应,于是附上lyd的std #include <queue> #in ...
- 解决Idea无法提示代码、不检查语法的方法
今天打开Idea做项目的时候,java代码图标出现异常(不是以前的C图标),所有java文件都只有两种颜色,百度查了一下,Idea有一个叫power save mode,在file -> Pow ...
- mysql 水平分表
新建10张表,user_0,user_1,...user_9,方法不可串用,采用hash或取余法,获取要操作的表名,取值用对应存值的方法 1.hash取余法 public function part_ ...