Exemplo n.º 1
0
def query_enginecheck_by_group(request, project_id=None):
    """
    查询工程检查,根据应用节点,和时间戳
    by:王健 at:2015-1-13
    优化URL参数 timeline 0 和空 一致
    by:王健 at:2015-2-26
    修改权限校验 函数
    by:王健 at:2015-3-5
    记录最后阅读时间
    by:尚宗凯 at:2015-05-06
	增加开始结束时间搜索
	by:尚宗凯 at:2015-05-06
	修改搜索结束时间逻辑
	by:尚宗凯 at:2015-05-28
    """
    flag = request.REQUEST.get('flag')
    timeline = int(request.REQUEST.get('timeline', '0'))
    start_date = request.REQUEST.get('start_date', '')
    end_date = request.REQUEST.get('end_date', '')
    if start_date and end_date:
        end_date = datetime.datetime.strptime(end_date,'%Y-%m-%d') + datetime.timedelta(days=1)
        end_date = end_date.strftime('%Y-%m-%d')
        l = EngineCheck.objects.filter(create_time__gte=start_date, create_time__lte=end_date)
    else:
        l = EngineCheck.objects.all()
    if not timeline:
        l = l.filter(project_id=project_id, file_group__flag=flag).order_by('-timeline')[:20]
    else:
        l = l.filter(project_id=project_id, file_group__flag=flag, timeline__gt=int(timeline)).order_by('timeline')[:20]
    user_id = request.user.pk
    UserLastReadTimeline.update_last_read_timeline(project_id=project_id, file_group_id=FileGroup.objects.get(flag=flag).pk, user_id=user_id)
    cache.set(RED_DOT_UNREAD_NUMBER % (flag, user_id, project_id), 0, settings.CACHES_TIMEOUT)
    return getResult(True, None, MyEncoder.default(l))
Exemplo n.º 2
0
def query_log_list_by_date(request, project_id=None):
    """
    查询项目的施工日志根据日期
    by:王健 at:2015-1-6
    datetime 进行时间点刷新
    by:王健 at:2015-1-8
    有datetime的情况下 查询日志
    by:王健 at:2015-1-12
    datetime 改为 create_time
    by:王健 at:2015-1-12
    修改Model名字,去除下划线, 优化带有日期查询的排序问题,防止隔过数据
    by:王健 at:2015-1-13
    没有时间参数时,一次获取全部数据
    by:王健 at:2015-1-20
    日志正序输出
    by:王健 at:2015-1-30
    日志也使用timeline
    by:王健 at:2015-2-10
    优化URL参数 timeline 0 和空 一致
    by:王健 at:2015-2-26
    修改权限校验 函数
    by:王健 at:2015-3-4
    增加最后阅读时间
    by:尚宗凯 at:2015-05-06
	增加根据开始时间结束时间搜索
	by:尚宗凯 at:2015-05-13
    优化查询
    by:尚宗凯 at:2015-05-20
	修改搜索结束时间逻辑
	by:尚宗凯 at:2015-05-28
    """
    sg_tq_id = request.REQUEST.get('sg_tq_id', '0')
    timeline = int(request.REQUEST.get('timeline', '0'))
    start_date = request.REQUEST.get('start_date', '')
    end_date = request.REQUEST.get('end_date', '')
    if start_date and end_date:
        end_date = datetime.datetime.strptime(
            end_date, '%Y-%m-%d') + datetime.timedelta(days=1)
        end_date = end_date.strftime('%Y-%m-%d')
        l = SGlog.objects.filter(create_time__gte=start_date,
                                 create_time__lte=end_date)
    else:
        l = SGlog.objects.all()
    if not timeline:
        l = l.filter(project_id=project_id,
                     sg_tq_log_id=sg_tq_id).order_by('timeline')
    else:
        l = l.filter(project_id=project_id,
                     sg_tq_log_id=sg_tq_id,
                     timeline__gt=int(timeline)).order_by('timeline')[:20]
    user_id = request.user.pk
    UserLastReadTimeline.update_last_read_timeline(
        project_id=project_id,
        file_group_id=FileGroup.objects.get(flag="gong_cheng_ri_zhi").pk,
        user_id=user_id)
    cache.set(
        RED_DOT_UNREAD_NUMBER % ("gong_cheng_ri_zhi", user_id, project_id), 0,
        settings.CACHES_TIMEOUT)
    return getResult(True, None, MyEncoder.default(l))
Exemplo n.º 3
0
def query_file_by_group(request, project_id=None):
    """
    根据应用标记,查询应用内容
    by:王健 at:2015-1-12
    修改Model名字,去除下划线, 优化带有日期查询的排序问题,防止隔过数据
    by:王健 at:2015-1-13
    优化URL参数 timeline 0 和空 一致
    by:王健 at:2015-2-26
    修改权限校验 函数
    by:王健 at:2015-3-5
    过滤is_active字段
    by:尚宗凯 at:2015-3-30
    去掉过滤is_active字段
    by:尚宗凯 at:2015-3-30
    记录最后阅读时间
    by:尚宗凯 at:2015-05-06
    增加开始结束时间搜索
    by:尚宗凯 at:2015-05-14
    更新用户项目应用节点未读数量缓存
    by:尚宗凯 at:2105-05-20
	修改搜索结束时间逻辑
	by:尚宗凯 at:2015-05-28
    """
    flag = request.REQUEST.get('flag')
    dt = int(request.REQUEST.get('timeline', '0'))
    start_date = request.REQUEST.get('start_date', '')
    end_date = request.REQUEST.get('end_date', '')
    if start_date and end_date:
        end_date = datetime.datetime.strptime(
            end_date, '%Y-%m-%d') + datetime.timedelta(days=1)
        end_date = end_date.strftime('%Y-%m-%d')
        l = FileRecord.objects.filter(create_time__gte=start_date,
                                      create_time__lte=end_date)
    else:
        l = FileRecord.objects.all()
    if not dt:
        l = l.filter(project_id=project_id,
                     file_group__flag=flag).order_by('-timeline')[:20]
    else:
        l = l.filter(project_id=project_id,
                     file_group__flag=flag,
                     timeline__gt=int(dt)).order_by('timeline')[:20]
    user_id = request.user.pk
    UserLastReadTimeline.update_last_read_timeline(
        project_id=project_id,
        file_group_id=FileGroup.objects.get(flag=flag).pk,
        user_id=user_id)
    cache.set(RED_DOT_UNREAD_NUMBER % (flag, user_id, project_id), 0,
              settings.CACHES_TIMEOUT)
    return getResult(True, None, MyEncoder.default(l))
Exemplo n.º 4
0
def query_log_list_by_date(request, project_id=None):
    """
    查询项目的施工日志根据日期
    by:王健 at:2015-1-6
    datetime 进行时间点刷新
    by:王健 at:2015-1-8
    有datetime的情况下 查询日志
    by:王健 at:2015-1-12
    datetime 改为 create_time
    by:王健 at:2015-1-12
    修改Model名字,去除下划线, 优化带有日期查询的排序问题,防止隔过数据
    by:王健 at:2015-1-13
    没有时间参数时,一次获取全部数据
    by:王健 at:2015-1-20
    日志正序输出
    by:王健 at:2015-1-30
    日志也使用timeline
    by:王健 at:2015-2-10
    优化URL参数 timeline 0 和空 一致
    by:王健 at:2015-2-26
    修改权限校验 函数
    by:王健 at:2015-3-4
    增加最后阅读时间
    by:尚宗凯 at:2015-05-06
	增加根据开始时间结束时间搜索
	by:尚宗凯 at:2015-05-13
    优化查询
    by:尚宗凯 at:2015-05-20
	修改搜索结束时间逻辑
	by:尚宗凯 at:2015-05-28
    """
    sg_tq_id = request.REQUEST.get('sg_tq_id', '0')
    timeline = int(request.REQUEST.get('timeline', '0'))
    start_date = request.REQUEST.get('start_date', '')
    end_date = request.REQUEST.get('end_date', '')
    if start_date and end_date:
        end_date = datetime.datetime.strptime(end_date,'%Y-%m-%d') + datetime.timedelta(days=1)
        end_date = end_date.strftime('%Y-%m-%d')
        l = SGlog.objects.filter(create_time__gte=start_date, create_time__lte=end_date)
    else:
        l = SGlog.objects.all()
    if not timeline:
        l = l.filter(project_id=project_id, sg_tq_log_id=sg_tq_id).order_by('timeline')
    else:
        l = l.filter(project_id=project_id, sg_tq_log_id=sg_tq_id, timeline__gt=int(timeline)).order_by('timeline')[:20]
    user_id = request.user.pk
    UserLastReadTimeline.update_last_read_timeline(project_id=project_id, file_group_id=FileGroup.objects.get(flag="gong_cheng_ri_zhi").pk, user_id=user_id)
    cache.set(RED_DOT_UNREAD_NUMBER % ("gong_cheng_ri_zhi", user_id, project_id), 0, settings.CACHES_TIMEOUT)
    return getResult(True, None, MyEncoder.default(l))
Exemplo n.º 5
0
def query_gysaddress_by_group(request, project_id=None):
    """
    查询供应商名录,根据应用节点,和时间戳
    by:王健 at:2015-1-14
    优化URL参数 timeline 0 和空 一致
    by:王健 at:2015-2-26
    修改权限校验 函数
    by:王健 at:2015-3-5
    记录最后阅读时间
    by:尚宗凯 at:2015-05-06
	增加根据开始时间结束时间搜索
	by:尚宗凯 at:2015-05-13
    优化查询
    by:尚宗凯 at:2015-05-20
	修改搜索结束时间逻辑
	by:尚宗凯 at:2015-05-28
    """
    flag = request.REQUEST.get('flag')
    timeline = int(request.REQUEST.get('timeline', '0'))
    start_date = request.REQUEST.get('start_date', '')
    end_date = request.REQUEST.get('end_date', '')
    if start_date and end_date:
        end_date = datetime.datetime.strptime(
            end_date, '%Y-%m-%d') + datetime.timedelta(days=1)
        end_date = end_date.strftime('%Y-%m-%d')
        l = GYSAddress.objects.filter(create_time__gte=start_date,
                                      create_time__lte=end_date)
    else:
        l = GYSAddress.objects.all()
    if not timeline:
        l = l.filter(project_id=project_id,
                     file_group__flag=flag).order_by('-timeline')[:20]
    else:
        l = l.filter(project_id=project_id,
                     file_group__flag=flag,
                     timeline__gt=int(timeline)).order_by('timeline')[:20]
    user_id = request.user.pk
    UserLastReadTimeline.update_last_read_timeline(
        project_id=project_id,
        file_group_id=FileGroup.objects.get(flag=flag).pk,
        user_id=user_id)
    cache.set(RED_DOT_UNREAD_NUMBER % (flag, user_id, project_id), 0,
              settings.CACHES_TIMEOUT)
    return getResult(True, None, MyEncoder.default(l))
Exemplo n.º 6
0
def query_file_by_group(request, project_id=None):
    """
    根据应用标记,查询应用内容
    by:王健 at:2015-1-12
    修改Model名字,去除下划线, 优化带有日期查询的排序问题,防止隔过数据
    by:王健 at:2015-1-13
    优化URL参数 timeline 0 和空 一致
    by:王健 at:2015-2-26
    修改权限校验 函数
    by:王健 at:2015-3-5
    过滤is_active字段
    by:尚宗凯 at:2015-3-30
    去掉过滤is_active字段
    by:尚宗凯 at:2015-3-30
    记录最后阅读时间
    by:尚宗凯 at:2015-05-06
    增加开始结束时间搜索
    by:尚宗凯 at:2015-05-14
    更新用户项目应用节点未读数量缓存
    by:尚宗凯 at:2105-05-20
	修改搜索结束时间逻辑
	by:尚宗凯 at:2015-05-28
    """
    flag = request.REQUEST.get('flag')
    dt = int(request.REQUEST.get('timeline', '0'))
    start_date = request.REQUEST.get('start_date', '')
    end_date = request.REQUEST.get('end_date', '')
    if start_date and end_date:
        end_date = datetime.datetime.strptime(end_date,'%Y-%m-%d') + datetime.timedelta(days=1)
        end_date = end_date.strftime('%Y-%m-%d')
        l = FileRecord.objects.filter(create_time__gte=start_date, create_time__lte=end_date)
    else:
        l = FileRecord.objects.all()
    if not dt:
        l = l.filter(project_id=project_id, file_group__flag=flag).order_by('-timeline')[:20]
    else:
        l = l.filter(project_id=project_id, file_group__flag=flag, timeline__gt=int(dt)).order_by('timeline')[:20]
    user_id = request.user.pk
    UserLastReadTimeline.update_last_read_timeline(project_id=project_id, file_group_id=FileGroup.objects.get(flag=flag).pk, user_id=user_id)
    cache.set(RED_DOT_UNREAD_NUMBER % (flag, user_id, project_id), 0, settings.CACHES_TIMEOUT)
    return getResult(True, None, MyEncoder.default(l))
Exemplo n.º 7
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))
Exemplo n.º 8
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))
Exemplo n.º 9
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))
Exemplo n.º 10
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))
Exemplo n.º 11
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))
Exemplo n.º 12
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))
Exemplo n.º 13
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))
Exemplo n.º 14
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))
Exemplo n.º 15
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))
Exemplo n.º 16
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))