Ejemplo n.º 1
0
def ding_filerecord_by_id(request, project_id=None):
    """
    对一个记录发出顶的操作
    by:王健 at:2015-2-25
    点赞
    by:王健 at:2015-05-28
    修改提示语
    by:王健 at:2015-05-28
    解决enginecheck 没有title的bug
    by:王健 at:2015-06-01
    添加typeflag 字段
    by:王健 at:2015-06-02
    """
    filerecord_id = request.REQUEST.get('id')
    flag = request.REQUEST.get('flag')
    if filerecord_id and flag:
        title = None
        typeflag = 'images'
        if flag in FILE_GROUP_FLAGS_FILES:
            typeflag = 'files'
        elif flag in FILE_GROUP_FLAGS_BGIMAGES:
            typeflag = 'bgimages'
        elif flag in FILE_GROUP_FLAGS_IMAGES:
            typeflag = 'images'
        else:
            typeflag = 'jc'

        if flag in FILE_GROUP_FLAGS:
            filerecord = get_object_or_404(FileRecord, pk=filerecord_id, project_id=project_id)
            title = filerecord.title
        elif flag in ('zhi_liang_jian_cha', 'an_quan_wen_ming_jian_cha'):
            filerecord = get_object_or_404(EngineCheck, pk=filerecord_id, project_id=project_id)
            title = filerecord.desc
        else:
            filerecord = None
            title = ''

        if filerecord:
            result = create_zan_by_filerecord(project_id, flag, filerecord_id, request.user.pk, int(time.time()), typeflag)
            if result is None or (isinstance(result, dict) and result.has_key("code")):
                return getResult(False, u'操作失败,请稍后再试')

            return getResult(True, u'成功对 %s 点了个赞。' % title, result, jifen=create_data_jifen(request, CREATE_DATA))
        return getResult(False, u'数据不存在')
    else:
        return getResult(False, u'请提供正确的参数')
Ejemplo n.º 2
0
def replay_filerecord_by_id(request, project_id=None):
    """
    对一条记录发出评论
    by:王健 at:2015-2-25
    去除 mongodb 影响
    by:王健 at:2015-3-8
    在某个节点下数据中发布评论
    by:王健 at:2015-05-28
    修改错误提示语
    by:王健 at:2015-05-28
    增加typeflag 字段
    by:王健 at:2015-06-03
    只取前一百评论内容
    by:王健 at:2015-06-04
    """
    filerecord_id = request.REQUEST.get('id')
    flag = request.REQUEST.get('flag')
    content = request.REQUEST.get('content', '')[:100]
    to_user = request.REQUEST.get('to_user', '0')
    if flag and filerecord_id and content:
        typeflag = 'images'
        if flag in FILE_GROUP_FLAGS_FILES:
            typeflag = 'files'
        elif flag in FILE_GROUP_FLAGS_BGIMAGES:
            typeflag = 'bgimages'
        elif flag in FILE_GROUP_FLAGS_IMAGES:
            typeflag = 'images'
        else:
            typeflag = 'jc'
        if flag in FILE_GROUP_FLAGS:
            filerecord = get_object_or_404(FileRecord, pk=filerecord_id, project_id=project_id)
        elif flag in ('zhi_liang_jian_cha', 'an_quan_wen_ming_jian_cha'):
            filerecord = get_object_or_404(EngineCheck, pk=filerecord_id, project_id=project_id)
        else:
            filerecord = None
        if filerecord:
            result = create_replay_by_filerecord(project_id, flag, filerecord_id, request.user.pk, int(time.time()), content, typeflag, to_user)
            if result is None or (isinstance(result, dict) and result.has_key("code")):
                return getResult(False, u'操作失败,请稍后再试')
            return getResult(True, u'发布评论成功。', result, jifen=create_data_jifen(request, CREATE_DATA))
    else:
        return getResult(False, u'请提供正确的参数')
Ejemplo n.º 3
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))
Ejemplo n.º 4
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))
Ejemplo n.º 5
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))
Ejemplo n.º 6
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))
Ejemplo n.º 7
0
def send_social_success(request):
    """
    分享社交软件获取积分
    by:王健 at:2015-2-5
    :param request:
    :return:
    """
    return getResult(True, '', None, jifen=create_data_jifen(request, FENXIANG))

#
# @client_login_required
# def add_social_callback(request):
#     code = request.REQUEST.get('code')
#     state = request.REQUEST.get('state')
#     url = 'http://openapi.baidu.com/social/oauth/2.0/token'
#     values = {'grant_type': 'authorization_code',
#               'code': code,
#               'client_id': BAE_AK,
#               'client_secret': BAE_SK,
#               'redirect_uri': 'http://liyuoa.duapp.com/riliusers/add_social_callback'}
#     timeline = int(time.mktime(timezone.now().timetuple()))
#     data = urllib.urlencode(values)
#     req = urllib2.Request(url, data)
#     response = urllib2.urlopen(req)
#     html = response.read()
#     result = json.loads(html)
#     if state.find('_user_') > 0 and len(state.split('_user_')) == 2:
#         flag = state.split('_user_')[1]
#     if result.has_key("error_code"):
#         url = 'https://openapi.baidu.com/social/oauth/2.0/authorize?response_type=code&state=%s&client_id=SyeExPLiXrkTwBK9GUYFLAok&redirect_uri=http://liyuoa.duapp.com/riliusers/add_social_callback&media_type=%s&t=%s' % (
#             state, state.split('_')[0],timeline)
#         # return HttpResponse(u'请先登录账号,再绑定社交账号。<a href="%s">继续</a> %s'% (url, result.get('error_code')))
#         return HttpResponseRedirect(url)
#     try:
#         social = Social.objects.get(social_uid=result.get('social_uid'))
#     except:
#         social = Social()
#         social.user = chatlogin.person.user
#     # social, created = Social.objects.get_or_create(user_id=chatlogin.person.user_id,
#     #                                                media_type=result.get('media_type'),
#     #                                                media_uid=result.get('media_uid'),
#     #                                                social_uid=result.get('social_uid'))
#     if social.user == chatlogin.person.user:
#         user = social.user
#         social.token = result.get('access_token')
#         social.expires_in = timeline + result.get('expires_in', 0)
#         social.media_type = result.get('media_type')
#         social.media_uid = result.get('media_uid')
#         social.social_uid = result.get('social_uid')
#         social.session_key = result.get('session_key')
#         social.session_secret = result.get('session_secret')
#         social.save()
#     else:
#         return HttpResponse(u'该社交账号已经,绑定了另外一个账号。<a href="http://%s">返回首页</a>'% request.get_host())
#     if not user.icon:
#         userinfo_url = 'https://openapi.baidu.com/social/api/2.0/user/info?access_token=%s' % result.get('access_token')
#         response_userinfo = urllib2.urlopen(userinfo_url)
#         html_userinfo = response_userinfo.read()
#         result_userinfo = json.loads(html_userinfo)
#         if result_userinfo.has_key('tinyurl'):
#             user.icon = result_userinfo.get('tinyurl')
#             user.save()
#             for p in user.person_set.all():
#                 if not p.icon:
#                     p.icon = user.icon
#                     p.save()
#     from util.jsonresult import cache
#     import uuid
#     uuid_flag = str(uuid.uuid4())
#     cache.set(uuid_flag, social.social_uid, 60 * 10)
#     return HttpResponseRedirect('/?uuid_flag=%s' % uuid_flag)

#
# @client_login_required
# def add_social_code(request):
#     media_type = request.REQUEST.get('media_type')
#     from util.jsonresult import cache
#     import uuid
#
#     uuid_flag = str(uuid.uuid4())
#     cache.set(uuid_flag, request.user.id, 60 * 10)
#     url = 'https://openapi.baidu.com/social/oauth/2.0/authorize?response_type=code&state=%s_user_%s&client_id=SyeExPLiXrkTwBK9GUYFLAok&redirect_uri=http://liyuoa.duapp.com/riliusers/add_social_callback&media_type=%s' % (
#         media_type, uuid_flag, media_type)
#     return HttpResponseRedirect(url)

#
# def assk_callback(request):
#     return getResult(True, '', "assk_callback")
#
#
# def third_callback(request):
#     return getResult(True, '', "third_callback")
#
#
# def yanzheng(request):
#     return HttpResponse('87407z1pWYlOEwXaITaLuFVzBlA')
Ejemplo n.º 8
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))
Ejemplo n.º 9
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))
Ejemplo n.º 10
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))
Ejemplo n.º 11
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))
Ejemplo n.º 12
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))
Ejemplo n.º 13
0
def send_social_success(request):
    """
    分享社交软件获取积分
    by:王健 at:2015-2-5
    :param request:
    :return:
    """
    return getResult(True,
                     '',
                     None,
                     jifen=create_data_jifen(request, FENXIANG))


#
# @client_login_required
# def add_social_callback(request):
#     code = request.REQUEST.get('code')
#     state = request.REQUEST.get('state')
#     url = 'http://openapi.baidu.com/social/oauth/2.0/token'
#     values = {'grant_type': 'authorization_code',
#               'code': code,
#               'client_id': BAE_AK,
#               'client_secret': BAE_SK,
#               'redirect_uri': 'http://liyuoa.duapp.com/riliusers/add_social_callback'}
#     timeline = int(time.mktime(timezone.now().timetuple()))
#     data = urllib.urlencode(values)
#     req = urllib2.Request(url, data)
#     response = urllib2.urlopen(req)
#     html = response.read()
#     result = json.loads(html)
#     if state.find('_user_') > 0 and len(state.split('_user_')) == 2:
#         flag = state.split('_user_')[1]
#     if result.has_key("error_code"):
#         url = 'https://openapi.baidu.com/social/oauth/2.0/authorize?response_type=code&state=%s&client_id=SyeExPLiXrkTwBK9GUYFLAok&redirect_uri=http://liyuoa.duapp.com/riliusers/add_social_callback&media_type=%s&t=%s' % (
#             state, state.split('_')[0],timeline)
#         # return HttpResponse(u'请先登录账号,再绑定社交账号。<a href="%s">继续</a> %s'% (url, result.get('error_code')))
#         return HttpResponseRedirect(url)
#     try:
#         social = Social.objects.get(social_uid=result.get('social_uid'))
#     except:
#         social = Social()
#         social.user = chatlogin.person.user
#     # social, created = Social.objects.get_or_create(user_id=chatlogin.person.user_id,
#     #                                                media_type=result.get('media_type'),
#     #                                                media_uid=result.get('media_uid'),
#     #                                                social_uid=result.get('social_uid'))
#     if social.user == chatlogin.person.user:
#         user = social.user
#         social.token = result.get('access_token')
#         social.expires_in = timeline + result.get('expires_in', 0)
#         social.media_type = result.get('media_type')
#         social.media_uid = result.get('media_uid')
#         social.social_uid = result.get('social_uid')
#         social.session_key = result.get('session_key')
#         social.session_secret = result.get('session_secret')
#         social.save()
#     else:
#         return HttpResponse(u'该社交账号已经,绑定了另外一个账号。<a href="http://%s">返回首页</a>'% request.get_host())
#     if not user.icon:
#         userinfo_url = 'https://openapi.baidu.com/social/api/2.0/user/info?access_token=%s' % result.get('access_token')
#         response_userinfo = urllib2.urlopen(userinfo_url)
#         html_userinfo = response_userinfo.read()
#         result_userinfo = json.loads(html_userinfo)
#         if result_userinfo.has_key('tinyurl'):
#             user.icon = result_userinfo.get('tinyurl')
#             user.save()
#             for p in user.person_set.all():
#                 if not p.icon:
#                     p.icon = user.icon
#                     p.save()
#     from util.jsonresult import cache
#     import uuid
#     uuid_flag = str(uuid.uuid4())
#     cache.set(uuid_flag, social.social_uid, 60 * 10)
#     return HttpResponseRedirect('/?uuid_flag=%s' % uuid_flag)

#
# @client_login_required
# def add_social_code(request):
#     media_type = request.REQUEST.get('media_type')
#     from util.jsonresult import cache
#     import uuid
#
#     uuid_flag = str(uuid.uuid4())
#     cache.set(uuid_flag, request.user.id, 60 * 10)
#     url = 'https://openapi.baidu.com/social/oauth/2.0/authorize?response_type=code&state=%s_user_%s&client_id=SyeExPLiXrkTwBK9GUYFLAok&redirect_uri=http://liyuoa.duapp.com/riliusers/add_social_callback&media_type=%s' % (
#         media_type, uuid_flag, media_type)
#     return HttpResponseRedirect(url)

#
# def assk_callback(request):
#     return getResult(True, '', "assk_callback")
#
#
# def third_callback(request):
#     return getResult(True, '', "third_callback")
#
#
# def yanzheng(request):
#     return HttpResponse('87407z1pWYlOEwXaITaLuFVzBlA')
Ejemplo n.º 14
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))