会议室预定demo mrbs
关于会议室的增删改查
查:
HTML:
login继承django自带的admin用户认证系统
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body> <form action="" method="post">
{% csrf_token %}
<p>姓名 <input type="text" name="user"></p>
<p>密码 <input type="password" name="pwd"></p>
<input type="submit">
</form> </body>
</html>
login
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/static/bootstrap-3.3.7/css/bootstrap.css">
<script src="/static/jquery-3.2.1.min.js"></script> <title>会议室</title>
<style >
.active {
background-color: deepskyblue !important;
color: black;
text-align: center;
font-size: 16px;
} .td_active {
background-color: greenyellow ;
} .active_other {
background-color: orange !important;
color: white;
text-align: center;
font-size: 16px;
} </style>
</head> <body>
<div class="container">
<div class="row">
<div class="col-md-11">
<h3>会议室预定</h3> <div>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>会议室</th>
{# 时间 时间元组 #}
{% for item in time_choices %}
<th>{{ item.1 }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{{ html|safe }}
</tbody> </table>
<button class="btn btn-primary pull-right keep">保存</button>
</div> </div>
</div>
</div>
<script> </script>
</body>
</html>
index.
PY:
from django.db import models # Create your models here.
from django.db import models
from django.contrib.auth.models import AbstractUser # Create your models here.
class MeetingRoom(models.Model):
'''会议室 '''
name = models.CharField(max_length=32,verbose_name="会议室名称")
num = models.IntegerField() # 最大开会人数 def __str__(self):
return self.name class UserInfo(AbstractUser):
tel=models.CharField(max_length=32) def __str__(self):
return self.username class Book(models.Model):
'''预定记录表'''
date = models.DateField(verbose_name="预定日期")
user = models.ForeignKey(to="UserInfo",verbose_name="预订用户") # 关联用户
room = models.ForeignKey(to="MeetingRoom",verbose_name="预定房间") # 关联房间
time1 = (
(1,"8.00"),
(2,"9.00"),
(3,"10.00"),
(4,"11.00"),
(5,"12.00"),
(6,"13.00"),
(7,"14.00"),
(8,"15.00"),
(9,"16.00"),
(10,"17.00"),
(11,"18.00"),
(12,"19.00"),
(13,"20.00"),
)
timeline = models.IntegerField(choices=time1,verbose_name="预定时间") # 存的是数字 class Meta:
# 联合唯一,为什么没有user,因为只有有下面3个字段,即表示有预定了
unique_together = (
('room','date','timeline'),
) def __str__(self):
return str(self.user) + "预定了" + str(self.room)
model
from django.shortcuts import render,redirect # Create your views here.
from .models import * def index(request):
# 取到所有的预定信息
book_list = Book.objects.all()
# 取所有的房间信息
room_list = MeetingRoom.objects.all()
# 房间的时间段
time_choices = Book.time1 # 渲染空的td, 有几个td,取决于有几个时间段
html=""
for room in room_list:
s = "<tr><td>{0}({1})</td>".format(room.name,room.num)
for item in time_choices: # 循环所有的时间段单元格 ((1,"8:00"))()
flag=False # 标志有否预定信息
for book in book_list: # 循环每个预定信息
print(MeetingRoom.pk)
if book.room.pk == room.pk and book.timeline == item[0]: flag=True # 通过
break
if flag:
# 最后循环出来的book是匹配的信息
if request.user.pk != book.user.pk: # 不同用户显示不同的样式
s += '<td class="active_other item" room_id="{0}" time_id="{1}">{2}</td>'.format(room.pk,item[0],book.user.username)
else:
s += '<td class="active item" room_id="{0}" time_id="{1}">{2}</td>'.format(room.pk,item[0],book.user.username)
else:
s += '<td class="item" room_id="{0}" time_id="{1}"></td>'.format(room.pk,item[0])
s += "</tr>"
html += s
return render(request,"index.html",locals()) from django.contrib import auth def login(request):
if request.method == "POST":
user = request.POST.get("user")
pwd = request.POST.get("pwd")
user = auth.authenticate(username=user, password=pwd)
if user:
auth.login(request, user) # 注册session
return redirect("/index/") return render(request, "login.html")
views
关于DATE--转化-->年月日
也可以通过CHOSEN_DATE=new Date().getFullYear()等等,各取出年月日,拼成年月日
知识点:js
自定义标签方法
-------------
datetime模块下有4个类
datetime.date---->年月日
datetime.time----->时分秒
datetime.datetime---->年月日时分秒
datetime.timedelta--->代表两个时间之间的时间差
日期加减
BUG1
使用时间插件跳转某日期,由于ajax,刷新页面导致date重新赋值 一直是当前日期。
思路:直接取url的值http://127.0.0.1:8000/index/?book_date=2018-03-29
model
from django.db import models # Create your models here.
from django.db import models
from django.contrib.auth.models import AbstractUser # Create your models here.
class MeetingRoom(models.Model):
'''会议室 '''
name = models.CharField(max_length=32,verbose_name="会议室名称")
num = models.IntegerField() # 最大开会人数 def __str__(self):
return self.name class UserInfo(AbstractUser):
tel=models.CharField(max_length=32) def __str__(self):
return self.username class Book(models.Model):
'''预定记录表'''
date = models.DateField(verbose_name="预定日期")
user = models.ForeignKey(to="UserInfo",verbose_name="预订用户") # 关联用户
room = models.ForeignKey(to="MeetingRoom",verbose_name="预定房间") # 关联房间
time1 = (
(1,"8.00"),
(2,"9.00"),
(3,"10.00"),
(4,"11.00"),
(5,"12.00"),
(6,"13.00"),
(7,"14.00"),
(8,"15.00"),
(9,"16.00"),
(10,"17.00"),
(11,"18.00"),
(12,"19.00"),
(13,"20.00"),
)
timeline = models.IntegerField(choices=time1,verbose_name="预定时间") # 存的是数字 class Meta:
# 联合唯一,为什么没有user,因为只有有下面3个字段,即表示有预定了
unique_together = (
('room','date','timeline'),
) def __str__(self):
return str(self.user) + "预定了" + str(self.room)
models
views
from django.shortcuts import render,redirect # Create your views here.
from .models import * def index(request): # 取所有的房间信息
room_list = MeetingRoom.objects.all()
# 房间的时间段
time_choices = Book.time1
# 取到当前日期的预定信息 datetime.datetime.now().date() 为默认值
choice_date = request.GET.get('book_date',datetime.datetime.now().date())
# 判断当前日期是否为字符串 datetime.datetime.now().date()为当前的对象
if isinstance(choice_date,str):
choice_date = datetime.datetime.strptime(choice_date,'%Y-%m-%d').date() # 字符串转为对象
book_list = Book.objects.filter(date=choice_date) # 渲染空的td, 有几个td,取决于有几个时间段
html=""
for room in room_list:
s = "<tr><td>{0}({1})</td>".format(room.name,room.num)
for item in time_choices: # 循环所有的时间段单元格 ((1,"8:00"))()
flag=False # 标志有否预定信息
for book in book_list: # 循环每个预定信息
if book.room.pk == room.pk and book.timeline == item[0]: flag=True # 通过
break
if flag:
# 最后循环出来的book是匹配的信息
if request.user.pk != book.user.pk: # 不同用户显示不同的样式
s += '<td class="active_other item" room_id="{0}" time_id="{1}">{2}</td>'.format(room.pk,item[0],book.user.username)
else:
s += '<td class="active item" room_id="{0}" time_id="{1}">{2}</td>'.format(room.pk,item[0],book.user.username)
else:
s += '<td class="item" room_id="{0}" time_id="{1}"></td>'.format(room.pk,item[0])
s += "</tr>"
html += s
return render(request,"index.html",locals()) from django.contrib import auth def login(request):
if request.method == "POST":
user = request.POST.get("user")
pwd = request.POST.get("pwd")
user = auth.authenticate(username=user, password=pwd)
if user:
auth.login(request, user) # 注册session
return redirect("/index/") return render(request, "login.html") import datetime
import json
def book(request):
choice_date = request.POST.get('date')
choice_date = datetime.datetime.strptime(choice_date,'%Y-%m-%d').date()
# 取的日期是字符串
post_data = json.loads(request.POST.get('data'))
print(post_data['ADD']) # response:ajax的响应 status:状态
response = {'status': True, 'msg': None, 'data': None} # 增加预定操作 room_id:会议室id time_list:存时间的id的列表
# 格式:{"2":["1","2"],"3":["1","2","3"]}
try: book_obj_list = []
for room_id,time_list in post_data['ADD'].items(): for time_id in time_list:
# print(time_id) # 8 9
obj = Book(room_id=room_id,timeline=time_id,user_id=request.user.pk,date=choice_date)
book_obj_list.append(obj)
# 使用批量处理去绑定
Book.objects.bulk_create(book_obj_list) except Exception as e:
response['status'] = False
response['msg'] = str(e) from django.http import JsonResponse
return JsonResponse(response)
View
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/static/bootstrap-3.3.7/css/bootstrap.css">
<script src="/static/jquery-3.2.1.min.js"></script> <script src="/static/datetimepicker/bootstrap-datetimepicker.min.js"></script>
<script src="/static/datetimepicker//bootstrap-datetimepicker.zh-CN.js"></script>
<title>会议室</title>
<style>
.active {
background-color: deepskyblue !important;
color: black;
text-align: center;
font-size: 16px;
} .td_active {
background-color: greenyellow;
} .active_other {
background-color: orange !important;
color: white;
text-align: center;
font-size: 16px;
} </style>
</head> <body> <h3>会议室预定</h3>
<div class="calender pull-right">
<div class='input-group' style="width: 230px;">
<input type='text' class="form-control" id='datetimepicker11' placeholder="请选择日期"/>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar">
</span>
</span>
</div>
</div> <table class="table table-bordered table-striped">
<thead>
<tr>
<th>会议室/时间</th>
{% for item in time_choices %}
<th>{{ item.1 }}</th>
{% endfor %} </tr>
</thead> <tbody>
{{ html|safe }} </tbody>
</table>
<button class="btn btn-primary pull-right keep">保存</button>
{% csrf_token %}
<script>
// Format:我们添加的方法。
// 自带Date没有我们想要的方法
Date.prototype.Format = function (fmt) { //author: "%Y-%m"
var o = {
"M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日
"h+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}; {# 自执行函数#}
$(function () {// date: $('#datetimepicker11').datetimepicker({
minView: "month",
language: "zh-CN",
sideBySide: true,
format: 'yyyy-mm-dd',
startDate: new Date(),
bootcssVer: 3,
autoclose: true
}).on('changeDate', book_query); bindTd() }); // get请求 ev.date:插件选中的当前日期对象(ev 可自定义)
function book_query(ev) { CHOSEN_DATE = ev.date.Format('yyyy-MM-dd');
location.href = "/index/?book_date=" + CHOSEN_DATE } {# 用户提交的数据集合成两种分 增,删 --> 整理成{[] } 形式 #}
var POST_DATA = {
DEL: {},
ADD: {}
}; function bindTd() {
$(".item").click(function () {
{# 判断是否登录#}
if ("{{ request.user.username }}") {
var room_id = $(this).attr('room_id');
var time_id = $(this).attr('time_id'); // 整合数据格式
if ($(this).hasClass("td_active")) {
$(this).removeClass("td_active");
POST_DATA.ADD[room_id].pop(time_id)
} else {
// 预定会议室操作 增的操作
$(this).addClass("td_active");
if (POST_DATA.ADD[room_id]){ // 当已有的房间号,为添加
POST_DATA.ADD[room_id].push(time_id);
} else { // 创建
POST_DATA.ADD[room_id] = [time_id];
}
} }
else {
location.href = "/login/"
} })
} // date日期:解决ajax页面刷新,date赋值问题
if (location.search.slice(11)) {
CHOSEN_DATE = location.search.slice(11)
} else {
CHOSEN_DATE = new Date().Format("yyyy-MM-dd"); // 取到当前的时间对象
} // 给保存按钮绑定ajax事件
$(".keep").click(function () {
$.ajax({
url: "/book/",
type: "POST",
// 上面的POSTdata缺时间及cs 前面的data是数据部分,后面的date是日期
data: {data: JSON.stringify(POST_DATA), date: CHOSEN_DATE, csrfmiddlewaretoken: '{{ csrf_token }}'},
success: function (data) {
if (data.status) {
location.href = ""
} else { alert("有问题请求") } }
})
})
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body> <form action="" method="post">
{% csrf_token %}
<p>姓名 <input type="text" name="user"></p>
<p>密码 <input type="password" name="pwd"></p>
<input type="submit">
</form> </body>
</html>
login
会议室预定demo mrbs的更多相关文章
- Python-S9—Day86-ORM项目实战之会议室预定相关
01 会议室预定1 02 会议室预定2 03 会议室预定3 04 会议室预定4 05 会议室预定5 06 会议室预定6 01 会议室预定1 1.1 项目的架构目录: 1.2 使用Pycharm创建Dj ...
- 启明星手机版安卓android会议室预定系统 V1.0发布
启明星手机版会议室预定系统 V1.0发布 在手机里输入 http://www.dotnetcms.org/e4.apk 或者扫描二维码下载 用户打开系统,可以实时查看所有会议室状态 点击会议室名称,可 ...
- 启明星会议室预定系统Outlook版开始支持Exchange2013与Office365版
版本启明星会议室预定系统支持Exchange2013与微软云服务Office365版.(注意:Exchange2007与Exchange2010也适合此版本) 1.安装 首页,安装类似启明星普通的会议 ...
- Django 会议室预定
表结构分析: from django.db import models # Create your models here. from django.db import models from dja ...
- OutLook会议室预定提醒
项目组采用敏捷开发管理,每两周一个迭代.写个工具做会议室预定. 代码下载:https://download.csdn.net/download/linmilove/10547579 Appointme ...
- 4.2 会议室预定系统,ajax参数(未完成)
参考blog https://www.cnblogs.com/alice-bj/p/9191082.html https://www.cnblogs.com/yuanchenqi/articles/7 ...
- 10.14 预订会议室的小Demo
2018-10-14 17:12:32 越努力,越幸运.永远不要高估自己! 网上修改一下博客网站样式,做个仿qq空间的! 放上github连接 :https://github.com/TrueNewB ...
- 启明星Exchange/outlook预定会议室终端显示解决方案
启明星会议室预定系统(Exchange2007及其以上版本,)终端调用说明 (一)技术原理 系统采用三级刷新方式,以尽可能减少对服务器的访问压力. (1) exe程序,每隔5分钟访问Exchange, ...
- jQuery插件实战之fullcalendar(日历插件)Demo
jQuery的插件许多,应用的场景也很丰富,今天我这里给大家介绍一款很有用的日历页面开发插件 - fullcalendar,眼下最新版本号是1.5.1,使用这款插件可以高速帮助你高速编程实现基于web ...
随机推荐
- linux下如何使用自己安装的SunJDK替换默认的OpenJDK
在linux系统中,由于涉及到版权问题,在大部分linux系统的发行版本中,默认都安装了OpenJDK,并且OpenJDK的java命令也已经加入到环境变量中了. 在刚装好的linux系统中,运行ja ...
- Spring MVC web.xml+servlet.xml
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" " ...
- 解题报告:poj2689 Prime Distance
2017-10-03 11:29:20 writer:pprp 来源:kuangbin模板 从已经筛选好的素数中筛选出规定区间的素数 /* *prime DIstance *给出一个区间[L,U],找 ...
- MU puzzle
2017-08-06 20:49:38 writer:pprp 三种操作: 1.MUI -> MUIUI 2.MUUU -> MU 3.MUIII -> MUU 分析:有两个操作:将 ...
- 拉取代码过程中遇到的:post install error,please remove node_modules before retry!
这是在git → clone 之后,安装npm intall时出现的错误,完整错误提示如下: 解决: // 1.先删除node_modules这个文件 $ rm -rf node_modules/ / ...
- MVVM架构简单使用
版权声明:本文为博主原创文章,未经博主授权不得转载. 项目github地址 https://github.com/zhangjiahuan8888/mvvmDemo/tree/master 开篇 MV ...
- Windows 10上强制Visual Studio 2017 以管理员身份运行
1. 打开VS的安装目录,找到devenv.exe,右键,选择“兼容性疑难解答”. 2. 选择“疑难解答程序” 3. 选择“该程序需要附加权限” 4. 确认用户帐户控制后,点击测试程序,不然这个对话框 ...
- MySQL相关错误汇总
Eroor 1 描述: 在启动mysql的时候出现如下问题:"ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' ...
- 在线修改Schema
1. mysql5.5 或者 Mariadb 5.5 之前不需要将数据表中的所有记录复制到临时数据表的操作: a. 修改列名 b. 修改数值类型表示的长度(由INT(2)变成INT(3 ...
- 通过网页或Serverice远程系统网站(服务)所在服务器本地的应用程序(未成功)
近日接了一个奇葩需求,内容如题. 实现过程中遇到一些问题,特将实现过程记录于此,供备忘及参考. 首先尝试了正常启动进程的方法,代码如下: public string RunSPApp() { Proc ...