예제 #1
0
def create_enginecheck_by_group(request, project_id=None):
    """
    创建一个工程检查
    by:王健 at:2015-1-13
    创建时 添加一个处理意见 参数“chuli”
    by:王健 at:2015-1-16
    处理意见,不在本接口填写
    by:王健 at:2015-1-21
    增加积分
    by:王健 at:2015-2-
    修改权限校验 函数
    by:王健 at:2015-3-5
    优化settings 使用
    by:王健 at:2015-3-9
    工程检查增加极光推送
    by:尚宗凯 at:2015-4-8
    提交日志时刷新阅读时间
    by:尚宗凯 at:2015-05-06
    增加最新数据时间缓存
    by:尚宗凯 at:2015-05-20
    修复小红点bug
    by:尚宗凯 at:2015-05-27
    增加项目状态为 0 装饰器
    by:尚宗凯 at:2015-05-31
	变更极光推送方法
	by:尚宗凯 at:2015-05-31
	上传图片增加长高比例
	by:尚宗凯 at:2015-06-02
    添加用户活跃度缓存
    by:尚宗凯 at:2015-06-04
    """
    fileid = request.REQUEST.get('fileid')
    fileobj = get_object_or_404(File, pk=fileid, project_id=project_id)
    fileobj.file_status = True
    fileobj.save()

    flag = request.REQUEST.get('flag')
    # title = request.REQUEST.get('title')

    desc = request.REQUEST.get('desc')
    # path = request.REQUEST.get('path')
    enginecheck = EngineCheck()
    # enginecheck.title = title
    enginecheck.desc = desc

    enginecheck.project_id = int(project_id)
    enginecheck.user = request.user
    enginecheck.file_group = get_object_or_404(FileGroup, flag=flag)
    enginecheck.user = request.user
    # enginecheck.path = path
    enginecheck.pre_pic = fileobj
    try:
        tmp = fileobj.img_size.strip().split("x")
        x = float(tmp[0])
        y = float(tmp[1])
        enginecheck.pre_pic_scale = "%.02f" % (x/y)
    except Exception as e:
        pass
    enginecheck.save()


    from util.cache_handle import query_project_filegroup_data_
    all_flag = query_project_filegroup_data_(project_id)
    file_group_id = all_flag['flags2'][flag]

    #更新项目应用节点最新数据时间
    user_id = request.user.pk
    cache.set(RED_DOT_PROJECT_FILE_GROUP_LAST_NEW_DATA_TIMELINE % (project_id, enginecheck.file_group_id), enginecheck.timeline, settings.CACHES_TIMEOUT)
    cache.set(RED_DOT_PROJECT_LAST_NEW_DATA_TIMELINE % project_id, enginecheck.timeline, settings.CACHES_TIMEOUT)
    cache.delete(USER_ACTIVITY % (user_id, project_id, enginecheck.create_time.strftime('%Y-%m-%d')))
    # cache.delete(RED_DOT_USER_LAST_READ_TIMELINE % (project_id, enginecheck.file_group_id, user_id))
    UserLastReadTimeline.update_last_read_timeline(project_id=project_id, file_group_id=FileGroup.objects.get(flag=flag).pk, user_id=user_id)
    UserLastReadTimeline.update_last_read_timeline(project_id, 0, user_id)

    alias = get_alias_by_project_id_flag(project_id, flag, file_group_id)
    alias = list(set(alias))
    NeedPush.send_jpush(flag=flag,
                        project_id=project_id,
                        title=Project.get_project_name_by_id(project_id),
                        msg=all_flag['file_group'][file_group_id]['name'],
                        alias=alias,
                        file_group=all_flag['file_group'][file_group_id]
    )

    return getResult(True, u'创建工程检查成功', MyEncoder.default(enginecheck), jifen=create_data_jifen(request, settings.CREATE_DATA))
예제 #2
0
def create_file_by_group(request, project_id=None):
    """
    根据应用标记,创建文件
    by:王健 at:2015-1-12
    修改Model名字,去除下划线
    by:王健 at:2015-1-13
    fileid字段优化为可为一个id也可为‘,’分隔的id字符串
    by:王健 at:2015-1-31
    增加积分
    by:王健 at:2015-2-5
    修改权限校验 函数
    by:王健 at:2015-3-5
    优化settings 使用
    by:王健 at:2015-3-9
    增加filetype字段
    by:尚宗凯 at:2015-3-30
    增加判断filetype
    by:尚宗凯 at:2015-3-30
    增加极光推送
    by:尚宗凯 at:2015-4-8
    逻辑修改,将update改为save,以调用save重载获取图片分辨率
    by: 范俊伟 at:2015-04-09
    优化兼容逗号分隔的列表
    by:王健 at:2015-05-19
    提交日志时刷新阅读时间
    by:尚宗凯 at:2015-05-06
    优化兼容逗号分隔的列表
    by:王健 at:2015-05-19
    增加最新数据时间缓存
    by:尚宗凯 at:2015-05-19
    增加filerecord节点的缓存管理
    by:王健 at:2015-05-21
    修复项目超级管理员新建项目出现小红点bug
    by:尚宗凯 at:2015-05-27
    增加项目状态为 0 装饰器
    by:尚宗凯 at:2015-05-31
	变更极光推送方法
	by:尚宗凯 at:2015-05-31
	上传图片增加长高比例
	by:尚宗凯 at:2015-06-02
    添加用户活跃度缓存
    by:尚宗凯 at:2015-06-04
    """
    fileids = [x for x in request.REQUEST.get('fileid', '').strip(',').split(',') if x]
    # num = File.objects.filter(project_id=project_id, pk__in=fileids).update(file_status=True)
    # if num == 0:
    #     return getResult(False, u'文件不存在', None)
    query = File.objects.filter(project_id=project_id, pk__in=fileids)
    if query.count() == 0:
        return getResult(False, u'文件不存在', None)
    for i in query:
        i.file_status = True
        i.save()

    flag = request.REQUEST.get('flag')
    title = request.REQUEST.get('title')
    text = request.REQUEST.get('text')
    filetype = request.REQUEST.get('filetype')
    id = request.REQUEST.get('id', None)
    if not id:
        filerecord = FileRecord()
        filerecord.file_group = get_object_or_404(FileGroup, flag=flag)
    else:
        filerecord = FileRecord.objects.get(pk=id)
    if request.REQUEST.has_key('title'):
        filerecord.title = title
    if request.REQUEST.has_key('text'):
        filerecord.text = text
    if request.REQUEST.has_key('filetype'):
        filerecord.filetype = filetype
    else:
        f = File.objects.get(id=int(fileids[0]))
        filerecord.filetype = find_file_type(f.name)

    filerecord.project_id = int(project_id)
    filerecord.user = request.user
    files_scale = []
    for fid in fileids:
        filerecord.append_file(fid)
        fileobj = get_object_or_404(File, pk=fid, project_id=project_id)
        try:
            tmp = fileobj.img_size.strip().split("x")
            x = float(tmp[0])
            y = float(tmp[1])
            files_scale.append(float("%.02f" % (x/y)))
        except Exception as e:
            pass
    filerecord.files_scale = str(files_scale)
    filerecord.save()

    from util.cache_handle import query_project_filegroup_data_
    all_flag = query_project_filegroup_data_(project_id)

    #更新项目应用节点最新数据时间
    user_id=request.user.pk
    cache.set(RED_DOT_PROJECT_FILE_GROUP_LAST_NEW_DATA_TIMELINE % (project_id, filerecord.file_group_id), filerecord.timeline, settings.CACHES_TIMEOUT)
    cache.set(RED_DOT_PROJECT_FILE_GROUP_LAST_NEW_DATA_TIMELINE_FILERECORD % project_id, filerecord.timeline, settings.CACHES_TIMEOUT)
    cache.set(RED_DOT_PROJECT_LAST_NEW_DATA_TIMELINE % project_id, filerecord.timeline, settings.CACHES_TIMEOUT)
    cache.delete(USER_ACTIVITY % (user_id, project_id, filerecord.create_time.strftime('%Y-%m-%d')))

    # cache.delete(RED_DOT_USER_LAST_READ_TIMELINE % (project_id, filerecord.file_group_id, user_id))
    UserLastReadTimeline.update_last_read_timeline(project_id=project_id, file_group_id=FileGroup.objects.get(flag=flag).pk, user_id=user_id)
    UserLastReadTimeline.update_last_read_timeline(project_id, 0, user_id)

    file_group_id = filerecord.file_group_id
    alias = get_alias_by_project_id_flag(project_id, flag, file_group_id)
    alias = list(set(alias))
    NeedPush.send_jpush(flag=flag,
                        project_id=project_id,
                        title=Project.get_project_name_by_id(project_id),
                        msg=all_flag['file_group'][file_group_id]['name'],
                        alias=alias,
                        file_group=all_flag['file_group'][file_group_id]
    )

    return getResult(True, None, MyEncoder.default(filerecord), jifen=create_data_jifen(request, settings.CREATE_DATA))
예제 #3
0
def update_log_by_date(request, project_id=None):
    """
    更新或添加新的施工日志根据日期、天气
    by:王健 at:2015-1-6
    修改属性名
    by:王健 at:2015-1-8
    修改属性名,天气和风力
    by:王健 at:2015-1-12
    修改Model名字,去除下划线
    by:王健 at:2015-1-13
    天气表增加 timeline、num、create_time 字段
    by:王健 at:2015-1-20
    返回的数据,包括施工天气信息
    by:王健 at:2015-1-28
    增加积分
    by:王健 at:2015-2-5
    记录日志最后上传人
    by:王健 at:2015-2-10
    修改权限校验 函数
    by:王健 at:2015-3-4
    提交日志时刷新阅读时间
    by:尚宗凯 at:2015-05-06
    增加最新数据时间缓存
    by:尚宗凯 at:2015-05-20
    修复小红点bug
    by:尚宗凯 at:2015-05-27
    增加项目状态为 0 装饰器
    by:尚宗凯 at:2015-05-31
	变更极光推送方法
	by:尚宗凯 at:2015-05-31
	添加用户活跃度缓存
    by:尚宗凯 at:2015-06-04
    """
    if not request.REQUEST.get('text'):
        return getResult(False, u'日志内容不能为空', None)
    sg_tq_id = request.REQUEST.get('sg_tq_id', '')
    if not sg_tq_id:
        sg_tq_log, create = SGTQlog.objects.get_or_create(
            project_id=project_id,
            file_group=FileGroup.objects.get(flag='gong_cheng_ri_zhi'),
            date=timezone.now())

    else:
        sg_tq_log = SGTQlog.objects.get(pk=sg_tq_id)
    f = False
    if not sg_tq_log.weather:
        sg_tq_log.weather = request.REQUEST.get('weather', '')
        f = True
    if not sg_tq_log.wind:
        sg_tq_log.wind = request.REQUEST.get('wind')
        f = True
    if not sg_tq_log.qiwen:
        sg_tq_log.qiwen = request.REQUEST.get('qiwen')
        f = True
    if f:
        sg_tq_log.save()
    pk = request.REQUEST.get('id')
    if pk:
        sg_log = SGlog.objects.get(pk=pk)
        if sg_log.project_id != int(
                project_id) or sg_log.user_id != request.user.pk:
            return getResult(False, u'不是一个项目的日志', status_code=2)
    else:
        sg_log = SGlog()
        sg_tq_log.create_time = timezone.now()
        sg_tq_log.num += 1
        sg_tq_log.last_create_user = request.user
        sg_tq_log.save()
    sgtqlog = MyEncoder.default(sg_tq_log)
    sg_log.project_id = int(project_id)
    sg_log.sg_tq_log = sg_tq_log
    sg_log.text = request.REQUEST.get('text', '')
    sg_log.user = request.user
    sg_log.save()
    sgtqlog.update(MyEncoder.default(sg_log))

    #更新项目应用节点最新数据时间
    user_id = request.user.pk
    flag = "gong_cheng_ri_zhi"
    from util.cache_handle import query_project_filegroup_data_
    all_flag = query_project_filegroup_data_(project_id)

    # file_group_id = get_file_group_id_by_flag_from_cache(project_id=project_id, flag="gong_cheng_ri_zhi")
    file_group_id = all_flag['flags2'][flag]
    cache.set(
        RED_DOT_PROJECT_FILE_GROUP_LAST_NEW_DATA_TIMELINE %
        (project_id, file_group_id), sg_log.timeline, settings.CACHES_TIMEOUT)
    cache.set(RED_DOT_PROJECT_LAST_NEW_DATA_TIMELINE % project_id,
              sg_log.timeline, settings.CACHES_TIMEOUT)
    # cache.delete(RED_DOT_USER_LAST_READ_TIMELINE % (project_id, file_group_id, user_id))
    UserLastReadTimeline.update_last_read_timeline(project_id, file_group_id,
                                                   user_id)
    UserLastReadTimeline.update_last_read_timeline(project_id, 0, user_id)

    alias = get_alias_by_project_id_flag(project_id, flag, file_group_id)
    alias = list(set(alias))
    NeedPush.send_jpush(flag=flag,
                        project_id=project_id,
                        title=Project.get_project_name_by_id(project_id),
                        msg=all_flag['file_group'][file_group_id]['name'],
                        alias=alias,
                        file_group=all_flag['file_group'][file_group_id])
    cache.delete(
        USER_ACTIVITY %
        (user_id, project_id, sg_log.create_time.strftime('%Y-%m-%d')))
    return getResult(True,
                     u'保存日志成功',
                     sgtqlog,
                     jifen=create_data_jifen(request, CREATE_DATA))
예제 #4
0
def create_gysaddress_by_group(request, project_id=None):
    """
    创建一个供应商名录
    by:王健 at:2015-1-14
    增加积分
    by:王健 at:2015-2-5
    修改权限校验 函数
    by:王健 at:2015-3-5
    增加修改时判断是否是当前用户创建的逻辑
    by:尚宗凯 at:2015-3-26
    增加极光推送
    by:尚宗凯 at:2015-4-8
    极光推送别名
    by:尚宗凯 at:2015-4-13
	极光推送IOS增加字段
	by:尚宗凯 at:2015-4-23
    提交日志时刷新阅读时间
    by:尚宗凯 at:2015-05-06
    增加最新数据时间缓存
    by:尚宗凯 at:2015-05-20
    修复小红点bug
    by:尚宗凯 at:2015-05-27
    增加项目状态为 0 装饰器
    by:尚宗凯 at:2015-05-31
    变更极光推送方法
    by:尚宗凯 at:2015-05-31
    添加用户活跃度缓存
    by:尚宗凯 at:2015-06-04
    """
    flag = request.REQUEST.get('flag')
    id = request.REQUEST.get('id')
    if id:
        ghsform = GYSAddressForm(request.POST, instance=GYSAddress.objects.get(pk=id))
        if ghsform.instance.user.pk != request.user.pk:
            return getResult(False, u'不是您发布的数据,不能修改', status_code=2)
    else:
        ghsform = GYSAddressForm(request.POST)
    if not ghsform.is_valid():
        return getErrorFormResult(ghsform)
    ghsform.instance.project_id = int(project_id)
    ghsform.instance.file_group = get_object_or_404(FileGroup, flag=flag)
    ghsform.instance.user = request.user
    gys = ghsform.save()
    # if flag:
    #     alias = list(set(get_alias_by_project_id_flag(project_id, flag)))
    #     NeedPush.send_jpush(flag=flag,
    #                     project_id=project_id,
    #                     title=Project.get_project_name_by_id(project_id),
    #                     msg=FileGroup.objects.get(flag=flag).name,
    #                     alias=alias,
    #                     file_group=FileGroup.objects.get(flag=flag).toJSON()
    #                     )

    from util.cache_handle import query_project_filegroup_data_
    all_flag = query_project_filegroup_data_(project_id)
    file_group_id = all_flag['flags2'][flag]
    alias = get_alias_by_project_id_flag(project_id, flag, file_group_id)
    alias = list(set(alias))
    NeedPush.send_jpush(flag=flag,
                        project_id=project_id,
                        title=Project.get_project_name_by_id(project_id),
                        msg=all_flag['file_group'][file_group_id]['name'],
                        alias=alias,
                        file_group=all_flag['file_group'][file_group_id]
    )

    # UserLastReadTimeline.update_last_read_timeline(project_id=project_id, file_group_id=FileGroup.objects.get(flag=flag).pk, user_id=request.user.pk)
    #更新项目应用节点最新数据时间
    user_id = request.user.pk
    cache.set(RED_DOT_PROJECT_FILE_GROUP_LAST_NEW_DATA_TIMELINE % (project_id, ghsform.instance.file_group_id), gys.timeline, settings.CACHES_TIMEOUT)
    cache.set(RED_DOT_PROJECT_LAST_NEW_DATA_TIMELINE % project_id, gys.timeline, settings.CACHES_TIMEOUT)
    cache.delete(USER_ACTIVITY % (user_id, project_id, ghsform.instance.create_time.strftime('%Y-%m-%d')))

    # cache.delete(RED_DOT_USER_LAST_READ_TIMELINE % (project_id, ghsform.instance.file_group_id, user_id))
    UserLastReadTimeline.update_last_read_timeline(project_id=project_id, file_group_id=FileGroup.objects.get(flag=flag).pk, user_id=user_id)
    UserLastReadTimeline.update_last_read_timeline(project_id, 0, user_id)
    return getResult(True, u'创建供应商名录成功', MyEncoder.default(gys), jifen=create_data_jifen(request, CREATE_DATA))
예제 #5
0
def update_log_by_date(request, project_id=None):
    """
    更新或添加新的施工日志根据日期、天气
    by:王健 at:2015-1-6
    修改属性名
    by:王健 at:2015-1-8
    修改属性名,天气和风力
    by:王健 at:2015-1-12
    修改Model名字,去除下划线
    by:王健 at:2015-1-13
    天气表增加 timeline、num、create_time 字段
    by:王健 at:2015-1-20
    返回的数据,包括施工天气信息
    by:王健 at:2015-1-28
    增加积分
    by:王健 at:2015-2-5
    记录日志最后上传人
    by:王健 at:2015-2-10
    修改权限校验 函数
    by:王健 at:2015-3-4
    提交日志时刷新阅读时间
    by:尚宗凯 at:2015-05-06
    增加最新数据时间缓存
    by:尚宗凯 at:2015-05-20
    修复小红点bug
    by:尚宗凯 at:2015-05-27
    增加项目状态为 0 装饰器
    by:尚宗凯 at:2015-05-31
	变更极光推送方法
	by:尚宗凯 at:2015-05-31
	添加用户活跃度缓存
    by:尚宗凯 at:2015-06-04
    """
    if not request.REQUEST.get('text'):
        return getResult(False, u'日志内容不能为空', None)
    sg_tq_id = request.REQUEST.get('sg_tq_id', '')
    if not sg_tq_id:
        sg_tq_log, create = SGTQlog.objects.get_or_create(project_id=project_id, file_group=FileGroup.objects.get(flag='gong_cheng_ri_zhi'), date=timezone.now())

    else:
        sg_tq_log = SGTQlog.objects.get(pk=sg_tq_id)
    f = False
    if not sg_tq_log.weather:
        sg_tq_log.weather = request.REQUEST.get('weather', '')
        f = True
    if not sg_tq_log.wind:
        sg_tq_log.wind = request.REQUEST.get('wind')
        f = True
    if not sg_tq_log.qiwen:
        sg_tq_log.qiwen = request.REQUEST.get('qiwen')
        f = True
    if f:
        sg_tq_log.save()
    pk = request.REQUEST.get('id')
    if pk:
        sg_log = SGlog.objects.get(pk=pk)
        if sg_log.project_id != int(project_id) or sg_log.user_id != request.user.pk:
            return getResult(False, u'不是一个项目的日志', status_code=2)
    else:
        sg_log = SGlog()
        sg_tq_log.create_time = timezone.now()
        sg_tq_log.num += 1
        sg_tq_log.last_create_user = request.user
        sg_tq_log.save()
    sgtqlog = MyEncoder.default(sg_tq_log)
    sg_log.project_id = int(project_id)
    sg_log.sg_tq_log = sg_tq_log
    sg_log.text = request.REQUEST.get('text', '')
    sg_log.user = request.user
    sg_log.save()
    sgtqlog.update(MyEncoder.default(sg_log))

    #更新项目应用节点最新数据时间
    user_id = request.user.pk
    flag = "gong_cheng_ri_zhi"
    from util.cache_handle import query_project_filegroup_data_
    all_flag = query_project_filegroup_data_(project_id)

    # file_group_id = get_file_group_id_by_flag_from_cache(project_id=project_id, flag="gong_cheng_ri_zhi")
    file_group_id = all_flag['flags2'][flag]
    cache.set(RED_DOT_PROJECT_FILE_GROUP_LAST_NEW_DATA_TIMELINE % (project_id, file_group_id), sg_log.timeline, settings.CACHES_TIMEOUT)
    cache.set(RED_DOT_PROJECT_LAST_NEW_DATA_TIMELINE % project_id, sg_log.timeline, settings.CACHES_TIMEOUT)
    # cache.delete(RED_DOT_USER_LAST_READ_TIMELINE % (project_id, file_group_id, user_id))
    UserLastReadTimeline.update_last_read_timeline(project_id, file_group_id, user_id)
    UserLastReadTimeline.update_last_read_timeline(project_id, 0, user_id)

    alias = get_alias_by_project_id_flag(project_id, flag, file_group_id)
    alias = list(set(alias))
    NeedPush.send_jpush(flag=flag,
                        project_id=project_id,
                        title=Project.get_project_name_by_id(project_id),
                        msg=all_flag['file_group'][file_group_id]['name'],
                        alias=alias,
                        file_group=all_flag['file_group'][file_group_id]
    )
    cache.delete(USER_ACTIVITY % (user_id, project_id, sg_log.create_time.strftime('%Y-%m-%d')))
    return getResult(True, u'保存日志成功', sgtqlog, jifen=create_data_jifen(request, CREATE_DATA))
예제 #6
0
def create_wuzirecord_by_group(request, project_id=None):
    """
    创建一个物资记录
    by:王健 at:2015-1-14
    num bug修复
    by:王健 at:2015-2-3
    增加积分
    by:王健 at:2015-2-5
    优化物资记录 增加方法
    by:王健 at:2015-2-10
    修改权限校验 函数
    by:王健 at:2015-3-5
    增加采购出库入库修改记录
    by:尚宗凯 at:2015-3-26
    添加极光推送
    by:尚宗凯 at:2015-4-8
	极光推送别名
	by:尚宗凯 at:2015-4-13
	极光推送IOS增加字段
	by:尚宗凯 at:2015-4-23
    提交日志时刷新阅读时间
    by:尚宗凯 at:2015-05-06
    优化查询
    by:尚宗凯 at:2015-05-20
    增加项目状态为 0 装饰器
    by:尚宗凯 at:2015-05-31
    添加用户活跃度缓存
    by:尚宗凯 at:2015-06-04
    """
    flag = request.REQUEST.get('flag')
    id = request.REQUEST.get('id')
    create = False
    if id:
        ghsform = WuZiRecordForm(request.POST, instance=WuZiRecord.objects.get(pk=id))
        record = ghsform.instance.record_date
        if ghsform.instance.user.pk != request.user.pk:
            return getResult(False, u'不是您发布的数据,不能修改', status_code=2)
        now = datetime.datetime.now().date()
        if record.date + datetime.timedelta(days=1) < now:
             return getResult(False, u'已超过24小时,不能修改', status_code=2)
    else:
        ghsform = WuZiRecordForm(request.POST)
        record, create = RecordDate.objects.get_or_create(project_id=project_id, file_group=FileGroup.objects.get(flag=flag), date=timezone.now())
        ghsform.instance.record_date = record
        record.num += 1
        record.last_create_user = request.user

    if not ghsform.is_valid():
        if create:
            record.delete()
        return getErrorFormResult(ghsform)
    ghsform.instance.project_id = int(project_id)
    ghsform.instance.file_group = get_object_or_404(FileGroup, flag=flag)
    ghsform.instance.user = request.user
    gys = ghsform.save()

    record.save()
    result = MyEncoder.default(record)
    result.update(MyEncoder.default(gys))

    # if flag:
        # alias = list(set(get_alias_by_project_id_flag(project_id, flag)))
        # NeedPush.send_jpush(flag=flag,
        #                 project_id=project_id,
        #                 title=Project.get_project_name_by_id(project_id),
        #                 msg=FileGroup.objects.get(flag=flag).name,
        #                 alias=alias,
        #                 file_group=FileGroup.objects.get(flag=flag).toJSON()
        #                 )
    from util.cache_handle import query_project_filegroup_data_
    all_flag = query_project_filegroup_data_(project_id)
    file_group_id = all_flag['flags2'][flag]
    alias = get_alias_by_project_id_flag(project_id, flag, file_group_id)
    alias = list(set(alias))
    NeedPush.send_jpush(flag=flag,
                        project_id=project_id,
                        title=Project.get_project_name_by_id(project_id),
                        msg=all_flag['file_group'][file_group_id]['name'],
                        alias=alias,
                        file_group=all_flag['file_group'][file_group_id]
    )

    # UserLastReadTimeline.update_last_read_timeline(project_id=project_id, file_group_id=FileGroup.objects.get(flag=flag).pk, user_id=request.user.pk)
    #更新项目应用节点最新数据时间
    user_id = request.user.pk
    cache.set(RED_DOT_PROJECT_FILE_GROUP_LAST_NEW_DATA_TIMELINE % (project_id, ghsform.instance.file_group_id), record.timeline, settings.CACHES_TIMEOUT)
    cache.set(RED_DOT_PROJECT_LAST_NEW_DATA_TIMELINE % project_id, record.timeline, settings.CACHES_TIMEOUT)
    cache.delete(USER_ACTIVITY % (user_id, project_id, ghsform.instance.create_time.strftime('%Y-%m-%d')))

    # cache.delete(RED_DOT_USER_LAST_READ_TIMELINE % (project_id, ghsform.instance.file_group_id, user_id))
    UserLastReadTimeline.update_last_read_timeline(project_id=project_id, file_group_id=FileGroup.objects.get(flag=flag).pk, user_id=user_id)
    UserLastReadTimeline.update_last_read_timeline(project_id, 0, user_id)
    return getResult(True, u'创建物资记录成功', result, jifen=create_data_jifen(request, CREATE_DATA))
예제 #7
0
파일: views_wzgl.py 프로젝트: cash2one/ESNS
def create_gysaddress_by_group(request, project_id=None):
    """
    创建一个供应商名录
    by:王健 at:2015-1-14
    增加积分
    by:王健 at:2015-2-5
    修改权限校验 函数
    by:王健 at:2015-3-5
    增加修改时判断是否是当前用户创建的逻辑
    by:尚宗凯 at:2015-3-26
    增加极光推送
    by:尚宗凯 at:2015-4-8
    极光推送别名
    by:尚宗凯 at:2015-4-13
	极光推送IOS增加字段
	by:尚宗凯 at:2015-4-23
    提交日志时刷新阅读时间
    by:尚宗凯 at:2015-05-06
    增加最新数据时间缓存
    by:尚宗凯 at:2015-05-20
    修复小红点bug
    by:尚宗凯 at:2015-05-27
    增加项目状态为 0 装饰器
    by:尚宗凯 at:2015-05-31
    变更极光推送方法
    by:尚宗凯 at:2015-05-31
    添加用户活跃度缓存
    by:尚宗凯 at:2015-06-04
    """
    flag = request.REQUEST.get('flag')
    id = request.REQUEST.get('id')
    if id:
        ghsform = GYSAddressForm(request.POST,
                                 instance=GYSAddress.objects.get(pk=id))
        if ghsform.instance.user.pk != request.user.pk:
            return getResult(False, u'不是您发布的数据,不能修改', status_code=2)
    else:
        ghsform = GYSAddressForm(request.POST)
    if not ghsform.is_valid():
        return getErrorFormResult(ghsform)
    ghsform.instance.project_id = int(project_id)
    ghsform.instance.file_group = get_object_or_404(FileGroup, flag=flag)
    ghsform.instance.user = request.user
    gys = ghsform.save()
    # if flag:
    #     alias = list(set(get_alias_by_project_id_flag(project_id, flag)))
    #     NeedPush.send_jpush(flag=flag,
    #                     project_id=project_id,
    #                     title=Project.get_project_name_by_id(project_id),
    #                     msg=FileGroup.objects.get(flag=flag).name,
    #                     alias=alias,
    #                     file_group=FileGroup.objects.get(flag=flag).toJSON()
    #                     )

    from util.cache_handle import query_project_filegroup_data_
    all_flag = query_project_filegroup_data_(project_id)
    file_group_id = all_flag['flags2'][flag]
    alias = get_alias_by_project_id_flag(project_id, flag, file_group_id)
    alias = list(set(alias))
    NeedPush.send_jpush(flag=flag,
                        project_id=project_id,
                        title=Project.get_project_name_by_id(project_id),
                        msg=all_flag['file_group'][file_group_id]['name'],
                        alias=alias,
                        file_group=all_flag['file_group'][file_group_id])

    # UserLastReadTimeline.update_last_read_timeline(project_id=project_id, file_group_id=FileGroup.objects.get(flag=flag).pk, user_id=request.user.pk)
    #更新项目应用节点最新数据时间
    user_id = request.user.pk
    cache.set(
        RED_DOT_PROJECT_FILE_GROUP_LAST_NEW_DATA_TIMELINE %
        (project_id, ghsform.instance.file_group_id), gys.timeline,
        settings.CACHES_TIMEOUT)
    cache.set(RED_DOT_PROJECT_LAST_NEW_DATA_TIMELINE % project_id,
              gys.timeline, settings.CACHES_TIMEOUT)
    cache.delete(USER_ACTIVITY %
                 (user_id, project_id,
                  ghsform.instance.create_time.strftime('%Y-%m-%d')))

    # cache.delete(RED_DOT_USER_LAST_READ_TIMELINE % (project_id, ghsform.instance.file_group_id, user_id))
    UserLastReadTimeline.update_last_read_timeline(
        project_id=project_id,
        file_group_id=FileGroup.objects.get(flag=flag).pk,
        user_id=user_id)
    UserLastReadTimeline.update_last_read_timeline(project_id, 0, user_id)
    return getResult(True,
                     u'创建供应商名录成功',
                     MyEncoder.default(gys),
                     jifen=create_data_jifen(request, CREATE_DATA))
예제 #8
0
파일: views_wzgl.py 프로젝트: cash2one/ESNS
def create_wuzirecord_by_group(request, project_id=None):
    """
    创建一个物资记录
    by:王健 at:2015-1-14
    num bug修复
    by:王健 at:2015-2-3
    增加积分
    by:王健 at:2015-2-5
    优化物资记录 增加方法
    by:王健 at:2015-2-10
    修改权限校验 函数
    by:王健 at:2015-3-5
    增加采购出库入库修改记录
    by:尚宗凯 at:2015-3-26
    添加极光推送
    by:尚宗凯 at:2015-4-8
	极光推送别名
	by:尚宗凯 at:2015-4-13
	极光推送IOS增加字段
	by:尚宗凯 at:2015-4-23
    提交日志时刷新阅读时间
    by:尚宗凯 at:2015-05-06
    优化查询
    by:尚宗凯 at:2015-05-20
    增加项目状态为 0 装饰器
    by:尚宗凯 at:2015-05-31
    添加用户活跃度缓存
    by:尚宗凯 at:2015-06-04
    """
    flag = request.REQUEST.get('flag')
    id = request.REQUEST.get('id')
    create = False
    if id:
        ghsform = WuZiRecordForm(request.POST,
                                 instance=WuZiRecord.objects.get(pk=id))
        record = ghsform.instance.record_date
        if ghsform.instance.user.pk != request.user.pk:
            return getResult(False, u'不是您发布的数据,不能修改', status_code=2)
        now = datetime.datetime.now().date()
        if record.date + datetime.timedelta(days=1) < now:
            return getResult(False, u'已超过24小时,不能修改', status_code=2)
    else:
        ghsform = WuZiRecordForm(request.POST)
        record, create = RecordDate.objects.get_or_create(
            project_id=project_id,
            file_group=FileGroup.objects.get(flag=flag),
            date=timezone.now())
        ghsform.instance.record_date = record
        record.num += 1
        record.last_create_user = request.user

    if not ghsform.is_valid():
        if create:
            record.delete()
        return getErrorFormResult(ghsform)
    ghsform.instance.project_id = int(project_id)
    ghsform.instance.file_group = get_object_or_404(FileGroup, flag=flag)
    ghsform.instance.user = request.user
    gys = ghsform.save()

    record.save()
    result = MyEncoder.default(record)
    result.update(MyEncoder.default(gys))

    # if flag:
    # alias = list(set(get_alias_by_project_id_flag(project_id, flag)))
    # NeedPush.send_jpush(flag=flag,
    #                 project_id=project_id,
    #                 title=Project.get_project_name_by_id(project_id),
    #                 msg=FileGroup.objects.get(flag=flag).name,
    #                 alias=alias,
    #                 file_group=FileGroup.objects.get(flag=flag).toJSON()
    #                 )
    from util.cache_handle import query_project_filegroup_data_
    all_flag = query_project_filegroup_data_(project_id)
    file_group_id = all_flag['flags2'][flag]
    alias = get_alias_by_project_id_flag(project_id, flag, file_group_id)
    alias = list(set(alias))
    NeedPush.send_jpush(flag=flag,
                        project_id=project_id,
                        title=Project.get_project_name_by_id(project_id),
                        msg=all_flag['file_group'][file_group_id]['name'],
                        alias=alias,
                        file_group=all_flag['file_group'][file_group_id])

    # UserLastReadTimeline.update_last_read_timeline(project_id=project_id, file_group_id=FileGroup.objects.get(flag=flag).pk, user_id=request.user.pk)
    #更新项目应用节点最新数据时间
    user_id = request.user.pk
    cache.set(
        RED_DOT_PROJECT_FILE_GROUP_LAST_NEW_DATA_TIMELINE %
        (project_id, ghsform.instance.file_group_id), record.timeline,
        settings.CACHES_TIMEOUT)
    cache.set(RED_DOT_PROJECT_LAST_NEW_DATA_TIMELINE % project_id,
              record.timeline, settings.CACHES_TIMEOUT)
    cache.delete(USER_ACTIVITY %
                 (user_id, project_id,
                  ghsform.instance.create_time.strftime('%Y-%m-%d')))

    # cache.delete(RED_DOT_USER_LAST_READ_TIMELINE % (project_id, ghsform.instance.file_group_id, user_id))
    UserLastReadTimeline.update_last_read_timeline(
        project_id=project_id,
        file_group_id=FileGroup.objects.get(flag=flag).pk,
        user_id=user_id)
    UserLastReadTimeline.update_last_read_timeline(project_id, 0, user_id)
    return getResult(True,
                     u'创建物资记录成功',
                     result,
                     jifen=create_data_jifen(request, CREATE_DATA))
예제 #9
0
파일: views_gcjc.py 프로젝트: cash2one/ESNS
def create_enginecheck_by_group(request, project_id=None):
    """
    创建一个工程检查
    by:王健 at:2015-1-13
    创建时 添加一个处理意见 参数“chuli”
    by:王健 at:2015-1-16
    处理意见,不在本接口填写
    by:王健 at:2015-1-21
    增加积分
    by:王健 at:2015-2-
    修改权限校验 函数
    by:王健 at:2015-3-5
    优化settings 使用
    by:王健 at:2015-3-9
    工程检查增加极光推送
    by:尚宗凯 at:2015-4-8
    提交日志时刷新阅读时间
    by:尚宗凯 at:2015-05-06
    增加最新数据时间缓存
    by:尚宗凯 at:2015-05-20
    修复小红点bug
    by:尚宗凯 at:2015-05-27
    增加项目状态为 0 装饰器
    by:尚宗凯 at:2015-05-31
	变更极光推送方法
	by:尚宗凯 at:2015-05-31
	上传图片增加长高比例
	by:尚宗凯 at:2015-06-02
    添加用户活跃度缓存
    by:尚宗凯 at:2015-06-04
    """
    fileid = request.REQUEST.get('fileid')
    fileobj = get_object_or_404(File, pk=fileid, project_id=project_id)
    fileobj.file_status = True
    fileobj.save()

    flag = request.REQUEST.get('flag')
    # title = request.REQUEST.get('title')

    desc = request.REQUEST.get('desc')
    # path = request.REQUEST.get('path')
    enginecheck = EngineCheck()
    # enginecheck.title = title
    enginecheck.desc = desc

    enginecheck.project_id = int(project_id)
    enginecheck.user = request.user
    enginecheck.file_group = get_object_or_404(FileGroup, flag=flag)
    enginecheck.user = request.user
    # enginecheck.path = path
    enginecheck.pre_pic = fileobj
    try:
        tmp = fileobj.img_size.strip().split("x")
        x = float(tmp[0])
        y = float(tmp[1])
        enginecheck.pre_pic_scale = "%.02f" % (x / y)
    except Exception as e:
        pass
    enginecheck.save()

    from util.cache_handle import query_project_filegroup_data_
    all_flag = query_project_filegroup_data_(project_id)
    file_group_id = all_flag['flags2'][flag]

    #更新项目应用节点最新数据时间
    user_id = request.user.pk
    cache.set(
        RED_DOT_PROJECT_FILE_GROUP_LAST_NEW_DATA_TIMELINE %
        (project_id, enginecheck.file_group_id), enginecheck.timeline,
        settings.CACHES_TIMEOUT)
    cache.set(RED_DOT_PROJECT_LAST_NEW_DATA_TIMELINE % project_id,
              enginecheck.timeline, settings.CACHES_TIMEOUT)
    cache.delete(
        USER_ACTIVITY %
        (user_id, project_id, enginecheck.create_time.strftime('%Y-%m-%d')))
    # cache.delete(RED_DOT_USER_LAST_READ_TIMELINE % (project_id, enginecheck.file_group_id, user_id))
    UserLastReadTimeline.update_last_read_timeline(
        project_id=project_id,
        file_group_id=FileGroup.objects.get(flag=flag).pk,
        user_id=user_id)
    UserLastReadTimeline.update_last_read_timeline(project_id, 0, user_id)

    alias = get_alias_by_project_id_flag(project_id, flag, file_group_id)
    alias = list(set(alias))
    NeedPush.send_jpush(flag=flag,
                        project_id=project_id,
                        title=Project.get_project_name_by_id(project_id),
                        msg=all_flag['file_group'][file_group_id]['name'],
                        alias=alias,
                        file_group=all_flag['file_group'][file_group_id])

    return getResult(True,
                     u'创建工程检查成功',
                     MyEncoder.default(enginecheck),
                     jifen=create_data_jifen(request, settings.CREATE_DATA))
예제 #10
0
파일: views_app.py 프로젝트: cash2one/ESNS
def create_file_by_group(request, project_id=None):
    """
    根据应用标记,创建文件
    by:王健 at:2015-1-12
    修改Model名字,去除下划线
    by:王健 at:2015-1-13
    fileid字段优化为可为一个id也可为‘,’分隔的id字符串
    by:王健 at:2015-1-31
    增加积分
    by:王健 at:2015-2-5
    修改权限校验 函数
    by:王健 at:2015-3-5
    优化settings 使用
    by:王健 at:2015-3-9
    增加filetype字段
    by:尚宗凯 at:2015-3-30
    增加判断filetype
    by:尚宗凯 at:2015-3-30
    增加极光推送
    by:尚宗凯 at:2015-4-8
    逻辑修改,将update改为save,以调用save重载获取图片分辨率
    by: 范俊伟 at:2015-04-09
    优化兼容逗号分隔的列表
    by:王健 at:2015-05-19
    提交日志时刷新阅读时间
    by:尚宗凯 at:2015-05-06
    优化兼容逗号分隔的列表
    by:王健 at:2015-05-19
    增加最新数据时间缓存
    by:尚宗凯 at:2015-05-19
    增加filerecord节点的缓存管理
    by:王健 at:2015-05-21
    修复项目超级管理员新建项目出现小红点bug
    by:尚宗凯 at:2015-05-27
    增加项目状态为 0 装饰器
    by:尚宗凯 at:2015-05-31
	变更极光推送方法
	by:尚宗凯 at:2015-05-31
	上传图片增加长高比例
	by:尚宗凯 at:2015-06-02
    添加用户活跃度缓存
    by:尚宗凯 at:2015-06-04
    """
    fileids = [
        x for x in request.REQUEST.get('fileid', '').strip(',').split(',') if x
    ]
    # num = File.objects.filter(project_id=project_id, pk__in=fileids).update(file_status=True)
    # if num == 0:
    #     return getResult(False, u'文件不存在', None)
    query = File.objects.filter(project_id=project_id, pk__in=fileids)
    if query.count() == 0:
        return getResult(False, u'文件不存在', None)
    for i in query:
        i.file_status = True
        i.save()

    flag = request.REQUEST.get('flag')
    title = request.REQUEST.get('title')
    text = request.REQUEST.get('text')
    filetype = request.REQUEST.get('filetype')
    id = request.REQUEST.get('id', None)
    if not id:
        filerecord = FileRecord()
        filerecord.file_group = get_object_or_404(FileGroup, flag=flag)
    else:
        filerecord = FileRecord.objects.get(pk=id)
    if request.REQUEST.has_key('title'):
        filerecord.title = title
    if request.REQUEST.has_key('text'):
        filerecord.text = text
    if request.REQUEST.has_key('filetype'):
        filerecord.filetype = filetype
    else:
        f = File.objects.get(id=int(fileids[0]))
        filerecord.filetype = find_file_type(f.name)

    filerecord.project_id = int(project_id)
    filerecord.user = request.user
    files_scale = []
    for fid in fileids:
        filerecord.append_file(fid)
        fileobj = get_object_or_404(File, pk=fid, project_id=project_id)
        try:
            tmp = fileobj.img_size.strip().split("x")
            x = float(tmp[0])
            y = float(tmp[1])
            files_scale.append(float("%.02f" % (x / y)))
        except Exception as e:
            pass
    filerecord.files_scale = str(files_scale)
    filerecord.save()

    from util.cache_handle import query_project_filegroup_data_
    all_flag = query_project_filegroup_data_(project_id)

    #更新项目应用节点最新数据时间
    user_id = request.user.pk
    cache.set(
        RED_DOT_PROJECT_FILE_GROUP_LAST_NEW_DATA_TIMELINE %
        (project_id, filerecord.file_group_id), filerecord.timeline,
        settings.CACHES_TIMEOUT)
    cache.set(
        RED_DOT_PROJECT_FILE_GROUP_LAST_NEW_DATA_TIMELINE_FILERECORD %
        project_id, filerecord.timeline, settings.CACHES_TIMEOUT)
    cache.set(RED_DOT_PROJECT_LAST_NEW_DATA_TIMELINE % project_id,
              filerecord.timeline, settings.CACHES_TIMEOUT)
    cache.delete(
        USER_ACTIVITY %
        (user_id, project_id, filerecord.create_time.strftime('%Y-%m-%d')))

    # cache.delete(RED_DOT_USER_LAST_READ_TIMELINE % (project_id, filerecord.file_group_id, user_id))
    UserLastReadTimeline.update_last_read_timeline(
        project_id=project_id,
        file_group_id=FileGroup.objects.get(flag=flag).pk,
        user_id=user_id)
    UserLastReadTimeline.update_last_read_timeline(project_id, 0, user_id)

    file_group_id = filerecord.file_group_id
    alias = get_alias_by_project_id_flag(project_id, flag, file_group_id)
    alias = list(set(alias))
    NeedPush.send_jpush(flag=flag,
                        project_id=project_id,
                        title=Project.get_project_name_by_id(project_id),
                        msg=all_flag['file_group'][file_group_id]['name'],
                        alias=alias,
                        file_group=all_flag['file_group'][file_group_id])

    return getResult(True,
                     None,
                     MyEncoder.default(filerecord),
                     jifen=create_data_jifen(request, settings.CREATE_DATA))