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 开发人员,也可以着手 ...
随机推荐
- 单机千万级MQTT连接服务器测试报告
目标:测试创建1000万客户端连接到服务器端,服务器操作系统 Linux(任意一款发行版服务器版本).分别在两台硬件一样的服务器,其中一台用于服务器端运行,另一台用于创建千万客户端连接客户端机器.在硬 ...
- Solr的配置和在java中的使用
Solr是一个全局站内搜索引擎,可以快速的搜索出结果. Solr依赖于tomcat,把Solr的war包放到tomcat中即可运行. 使用solr,需要在solr的schema.xml中配置solr与 ...
- iOS 9之后Url链接的NSUTF8StringEncoding转码实现
在iOS中通过WebView加载Url或者请求HTTP时,若是链接中包含中文.特殊符号&%或是空格等都需要预先进行一下转码才可正常访问. 许久没编码,原先的方法已废弃了都,在此对应当前最新的方 ...
- 短网址API
http://tao.tf/open/ API简介 API允许第三方自由调用URL缩短,基于text/json/jsonp/js模式,支持post.get提交. 支持缩短网址: 淘宝网(*.taoba ...
- 1.3 正则表达式和Python语言-1.3.5使用 search()在一个字符串中查找模式(搜索与匹配 的对比)
1.3.5 使用 search()在一个字符串中查找模式(搜索与匹配的对比) 其实,想要搜索的模式出现在一个字符串中间部分的概率,远大于出现在字符串起始部分的概率.这也就是 search()派上用场的 ...
- BZOJ1431 : MLand
考虑任意一棵生成树,它的代价是一个一次函数. 因此所有生成树的最小值随着时间变化呈现出的是一个上凸壳. 三分查找最大值即可. 时间复杂度$O(m\log m\log w)$. #include< ...
- MyBatis(10)使用association进行分步查询
(1)接口中编写方法 public Emp getEmpByStep(Integer id); public Dept getDeptById(Integer id); (2)Mapper文件 < ...
- [LeetCode] Backspace String Compare 退格字符串比较
Given two strings S and T, return if they are equal when both are typed into empty text editors. # m ...
- C++ struct结构体定义构造函数和析构函数,构造函数参数从VS2017平台转换到Qt5平台下构建出错,采用字符集转换函数将string类型转换为wstring,构建仍然出错!
调试win硬件驱动,需要利用VS编译的win驱动构建自己的Qt5GUI程序: 其中部分win驱动源码如下 device_file::device_file(const std::string& ...
- 使用jQuery.form库中ajaxSubmit提交表单时遇到的一些问题
初入前端,网上找的很多资料都不够详细,导致遇到很多问题,现记录如下: 1.首先引入 <script src="~/Scripts/jquery-1.10.2.js">& ...