Ejemplo n.º 1
0
def de_del(request):
    id = int(request.GET['id'])
    if id > 0 and util.not_empty(id):
        de = ReviewDeparment(id=id)
        de.delete()
    else:
        return util.result(request, False, '参数错误')
    return HttpResponseRedirect("/user")
Ejemplo n.º 2
0
def del_review(request):
    id = int(request.GET['id'])
    if id > 0 and util.not_empty(id):
        c = ReviewCount(id=id)
        c.delete()
        return HttpResponseRedirect('./review')
    else:
        return util.result(request, False, "参数错误!")
Ejemplo n.º 3
0
def add_review(request):
    name = request.POST['name']
    if util.not_empty(name):
        # 查询当天是否存在评选
        in_px = ReviewCount.objects.filter(
            overtime__gte=time.time()).all().values('id')
        if in_px:
            return util.result(request, False, "当天已存在评选主题,请删除后再试")
        else:
            c = ReviewCount()
            c.name = name
            c.starttime = time.time()
            # 取得当天晚24点的时间戳,确保每一次评选只能到凌晨截止
            c.overtime = time.mktime(
                time.strptime(
                    time.strftime(
                        '%Y-%m-%d 00:00:00',
                        time.localtime(time.time() + float(24 * 3600))),
                    '%Y-%m-%d %H:%M:%S'))
            c.save()
            return HttpResponseRedirect('./review')
    else:
        return util.result(request, False, "暂无评选主题")
Ejemplo n.º 4
0
def add01(request):
    department_name = request.POST['name']
    d_id = int(request.GET['d_id'])
    if util.not_empty(department_name):
        print("d_id is :", d_id)
        if d_id > 0:
            d = ReviewDeparment(id=d_id)
        else:
            d = ReviewDeparment()
        d.name = department_name
        d.save()
        # print("保存结果:", d.save(), "上传结果:", department_name)
        # 如果是新增则跳转到添加页面,修改则跳到管理页面
        if d_id > 0:
            return HttpResponseRedirect('/user')
        else:
            return HttpResponseRedirect('/add')

    else:
        return util.result(request, False, '部门名称不得为空', '')
Ejemplo n.º 5
0
def login(request):
    login_result = ''
    username = request.POST['username']
    password = request.POST['password']
    if username and password:
        password = util.md5(password)
        # 查询数据库是否可以登录

        login_res = ReviewUser.objects.filter(email=username,
                                              password=password)
        if login_res:
            request.session['user_info'] = login_res.all().values(
                'id', 'name', 'email').first()
            return HttpResponseRedirect('/home')
        else:
            login_result = "用户名或密码错误"
        request.session['login'] = login_result
    else:
        res = util.result(request, False, '用户名或密码不得为空', '', 3)
        return res
    return HttpResponseRedirect('/index')
Ejemplo n.º 6
0
def detail(request):
    if util.base(request) != False:
        return util.base(request)
    context = util.user(request)
    # 获取cid
    c_id = int(request.GET['c_id'])
    # 获取uid
    u_id = int(request.GET['u_id'])

    # 查询详情
    if util.not_empty(c_id) and util.not_empty(u_id):
        score_detail = ReviewScore.objects.filter(uid=u_id,
                                                  cid=c_id).all().values(
                                                      "did", "score", "time")
        for d in score_detail:
            u = ReviewUser.objects.filter(id=d["did"]).values("name",
                                                              "bz").first()
            d['name'] = u["name"]
            d["bz"] = u["bz"]
        context['score'] = score_detail
        return render(request, 'detail.html', context)
    else:
        return util.result(request, False, '参数错误')