Ejemplo n.º 1
0
def update_user_icon_url(request):
    """
    获取上传项目图标的url
    by:王健 at:2015-1-28
    解决用户被删除的bug
    by:王健 at:2015-2-5
    解决用户被删除的bug
    by:范俊伟 at:2015-2-9
    :param request:
    :param project_id:
    :return:
    """
    fileid = request.REQUEST.get('fileid')
    if fileid:
        fileobj = get_object_or_404(BaseFile, pk=fileid)
        fileobj.file_status = True
        fileobj.save()
        old_icon = None
        if fileobj.user.icon_url:
            old_icon = fileobj.user.icon_url
        fileobj.user.icon_url = fileobj
        fileobj.user.save()
        if old_icon:
            old_icon.delete()
        return getResult(True, u'上传成功', None)
    else:
        return getResult(False, u'没有上传文件id', None)
Ejemplo n.º 2
0
def getMessageByUser(request):
    '''
    type 为信息查询条件 all 为按时间倒序,n条; read 为按时间倒序,已读的 n条;unread 为按时间倒序 未读的n条
    '''
    user = request.user
    type = request.REQUEST.get('type', 'all')
    limit = int(request.REQUEST.get('limit', '30'))
    start = int(request.REQUEST.get('start', '0'))

    messagequery = ReceiveMessage.objects.filter(user=user).order_by('-id')
    if type == 'unread':
        messagequery = messagequery.filter(is_read=False)
    elif type == 'read':
        messagequery = messagequery.filter(is_read=True)
    elif type == 'saved':
        messagequery = OAMessage.objects.filter(flag=True,f=request.user).order_by('-id')
        resultlist = []
        for m in messagequery:

            s = {'id': m.pk,'rid':m.pk, 'title': m.title, 'mfid': m.fatherMessage_id, 'authorname':m.f.first_name, 'author':m.f.username,
                  'datetime': m.createtime.strftime("%Y/%m/%d %H:%M"),'flag':m.flag,'desc':m.desc}
            s['to'] = [{'username': u.username, 'nickname': u.first_name} for u in m.t.all()]
            resultlist.append(s)
        return getResult(True, u'获取信息成功', {'limit': limit, 'start': start, 'total': 0, 'list': resultlist})

    totalnum = messagequery.count()
    resultlist = []
    messageids=[]
    msgread={}
    for m in messagequery[start:limit]:

        s = {'id': m.message_id,'rid':m.pk, 'title': m.message.title, 'mfid': m.message.fatherMessage_id, 'authorname':m.message.f.first_name, 'author':m.message.f.username,
             'is_read': m.is_read, 'datetime': m.message.createtime.strftime("%Y/%m/%d %H:%M")}
        resultlist.append(s)
    return getResult(True, u'获取信息成功', {'limit': limit, 'start': start, 'total': totalnum, 'list': resultlist})
Ejemplo n.º 3
0
def submit_user_tel(request):
    """
    提交手机号
    by:王健 at:2015-1-15
    提交手机号,只需要登录过,不需要已经有手机号,排除登陆者自己的手机号
    by:王健 at:2015-1-16
    改下提示内容
    by:尚宗凯 at:2015-05-12
    短信验证码使用后从session中删除
    by: 范俊伟 at:2015-07-01
    """
    user = request.user
    code = request.REQUEST.get('code', '')
    tel = request.REQUEST.get('tel', '')
    smsdebug = request.REQUEST.get('smsdebug', '')
    if not smsdebug and code != request.session.get('smscode', '1234'):
        return getResult(False, u'手机验证码不对,请重新输入。', None)
    if not smsdebug and tel != request.session.get('smstel', ''):
        return getResult(False, u'发送验证码的手机号,和注册的手机号不符合。请重新输入', None)
    user.tel = tel
    if get_user_model().objects.filter(tel=user.tel).exclude(
            id=user.id).exists():
        return getResult(False, u'手机号已经存在。请更换手机号', None)
    name = request.REQUEST.get('name', u'游客')
    if name:
        user.name = name
    user.save()
    request.session['smscode'] = None
    return getResult(True, u'验证手机号成功', None)
Ejemplo n.º 4
0
def set_user_type(request):
    """
    设置用户类型
    by: 范俊伟 at:2015-06-12
    :param request:
    :return:
    """
    ids = request.REQUEST.getlist('id')
    user_type = request.REQUEST.get('user_type')
    if user_type == None:
        return getResult(False, '未提供用户类型')
    if not ids:
        return getResult(False, '未选择用户')
    for id in ids:
        try:
            user = get_user_model().objects.get(id=id)
            if hasattr(user, 'backuserinfo'):
                backuserinfo = user.backuserinfo
            else:
                backuserinfo = BackUserInfo()
                backuserinfo.need_user = user
            backuserinfo.user_type = user_type
            backuserinfo.save()
        except get_user_model().DoesNotExist:
            pass

    return getResult(True, '设置成功')
Ejemplo n.º 5
0
def del_log_by_id(request, project_id=None):
    """
    不超过24小时的日志,可以由发布者 删除
    by:王健 at:2015-2-10
    清除最新数据事件缓存
    by:尚宗凯 at:2015-05-20
    删除时间改为30日之内
    by:尚宗凯 at:2015-05-27
    """
    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)
        if (sg_log.create_time + datetime.timedelta(days=30)) < timezone.now():
            return getResult(False, u'超过30日的数据,不能删除')
        sg_log.sg_tq_log.num -= 1
        sg_log.sg_tq_log.save()
        sg_log.is_active = False
        sg_log.create_time = timezone.now()
        sg_log.save()
        #删除项目应用节点最新数据时间
        cache.delete(RED_DOT_PROJECT_FILE_GROUP_LAST_NEW_DATA_TIMELINE % (project_id, get_file_group_id_by_flag_from_cache(project_id=project_id, flag="gong_cheng_ri_zhi")))
        cache.delete(RED_DOT_PROJECT_LAST_NEW_DATA_TIMELINE % project_id)
        return getResult(True, u'删除日志成功', pk)
    else:
        return getResult(False, u'参数不正确')
Ejemplo n.º 6
0
def delete_ding_news_by_id(request, company_id=''):
    """
    对一个记录发出顶的操作
    by:王健 at:2015-2-25
    删除点赞
    by:王健 at:2015-05-28
    修改错误提示语
    by:王健 at:2015-05-28
    解决enginecheck 没有title的bug
    by:王健 at:2015-06-01
    删除赞
    by:王健 at:2015-06-25
    适应性优化,公司id 从None改为''
    by:王健 at:2015-06-26
    """
    news_id = request.REQUEST.get('id')
    if news_id:
        if company_id:
            news = CompanyNews.objects.get(pk=news_id)
        else:
            news = SysNews.objects.get(pk=news_id)
        if news:
            if company_id:
                result = del_zan_news_by_id(request.user.id, news_id, False)
            else:
                result = del_zan_news_by_id(request.user.id, news_id, True)
            news.add_zan_num(-1)
            if result is None or (isinstance(result, dict)
                                  and result.has_key("code")):
                return getResult(False, u'操作失败,请稍后再试')
            return getResult(True, u'成功对 %s 取消了赞。' % news.title, result)
        return getResult(False, u'数据不存在')
    else:
        return getResult(False, u'请提供正确的参数')
Ejemplo n.º 7
0
def query_group(request, project_id=None):
    """
    获取所有分组
    by:王健 at:2015-1-16
    排除root 组
    by:王健 at:2015-2-2
    不排除 root 组,方便客户端 组织“未分组” 。
    by:王健 at:2015-2-3
    优化URL参数 timeline 0 和空 一致
    by:王健 at:2015-2-26
    使用缓存
    by:王健 at:2015-3-9
    优化缓存结果的非空判断
    by:王健 at:2015-05-21
    修改控制校验
    by:王健 at:2015-05-21
    """
    timeline = int(request.REQUEST.get('timeline', '0'))
    if not timeline:
        l = cache.get(PROJECT_GROUP_LIST % project_id)
        if l is None:
            l = Group.objects.filter(project_id=project_id).filter(
                is_active=True).order_by('-timeline')
        else:
            return getResult(True, None, l)
    else:
        l = Group.objects.filter(project_id=project_id,
                                 timeline__gt=int(timeline)).filter(
                                     is_active=True).order_by('timeline')
    ul = []
    for person in l:
        ul.append(group_2_dict(person))
    if not timeline:
        cache.set(PROJECT_GROUP_LIST % project_id, ul, settings.CACHES_TIMEOUT)
    return getResult(True, None, ul)
Ejemplo n.º 8
0
def query_app_list(request, project_id=None):
    """
    根据缓存的json串,输出
    by:王健 at:2015-1-11
    组装成带有包含关系的json数据
    by:王健 at:2015-1-12
    组装成不带有包含关系的json数据,填充上project、timeline字段
    by:王健 at:2015-1-13
    修改Model名字,去除下划线
    by:王健 at:2015-1-13
    修改为网络图
    by:王健 at:2015-2-12
    优化URL参数 timeline 0 和空 一致
    by:王健 at:2015-2-26
    修改权限校验 函数
    by:王健 at:2015-3-5
    """
    timeline = int(request.REQUEST.get('timeline', '0'))
    if timeline:
        if FileGroupJSON.objects.filter(project_id=project_id, timeline=timeline).exists():
            return getResult(True, u'已经是最新的数据了')

    fgroupjson, create = FileGroupJSON.objects.get_or_create(project_id=project_id)
    if create:
        fgroupjson.timeline = int(time.time())
        filegroup = FileGroup.objects.filter(Q(project_id=project_id) | Q(project_id=None)).order_by('sorted')
        jsongroup = MyEncoder.default(filegroup)
        for g in jsongroup:
            if not g['project'] or not g['icon_url']:
                g['icon_url'] = 'http://needserver.duapp.com/static/icon/%s' % g['icon']
            g['project']=int(project_id)
            g['timeline'] = fgroupjson.timeline
        fgroupjson.jsontext = json.dumps(jsongroup)
        fgroupjson.save()
    return getResult(True, None, json.loads(fgroupjson.jsontext))
Ejemplo n.º 9
0
def create_project_message(request, project_id=None):
    """
    创建项目公告,根据分组
    by:王健 at:2015-2-26
    标题和内容不能为空
    by:尚宗凯 at:2015-05-04
    创建项目公告时刷新最后一次阅读时间
    by: 尚宗凯 at:2015-05-08
    创建项目公告更新最后阅读时间
    by:尚宗凯 at:2105-05-21
    """
    group_id = request.REQUEST.get('group_id')
    text = request.REQUEST.get('text')
    title = request.REQUEST.get('title')
    if title == "":
        return getResult(False, u'标题不能为空', status_code=2)
    if text == "":
        return getResult(False, u'内容不能为空', status_code=2)

    group = Group.objects.get(pk=group_id, project_id=project_id)
    if group.say_members.filter(id=request.user.id).exists():
        msg = ProjectMessage()
        msg.project_id = int(project_id)
        msg.to_group = group
        msg.user = request.user
        msg.title = title
        msg.text = text
        msg.save()
        LastReadTimeProjectSysMessage.update_last_read_timeline(type="project_message", user_id=request.user.pk, project_id=project_id,group_id=group_id)
        cache.set(RED_DOT_PROJECT_SYS_MESSAGE_LAST_NEW_DATA_TIMELINE % ("project_message", project_id, group_id), msg.timeline, settings.CACHES_TIMEOUT)
        return getResult(True, u'发布公告成功', MyEncoder.default(msg))
    else:
        return getResult(False, u'您不具有发布公告的权限', status_code=8)
Ejemplo n.º 10
0
def set_user_type(request):
    """
    设置用户类型
    by: 范俊伟 at:2015-06-12
    :param request:
    :return:
    """
    ids = request.REQUEST.getlist('id')
    user_type = request.REQUEST.get('user_type')
    if user_type == None:
        return getResult(False, '未提供用户类型')
    if not ids:
        return getResult(False, '未选择用户')
    for id in ids:
        try:
            user = get_user_model().objects.get(id=id)
            if hasattr(user, 'backuserinfo'):
                backuserinfo = user.backuserinfo
            else:
                backuserinfo = BackUserInfo()
                backuserinfo.need_user = user
            backuserinfo.user_type = user_type
            backuserinfo.save()
        except get_user_model().DoesNotExist:
            pass

    return getResult(True, '设置成功')
Ejemplo n.º 11
0
def updateTask(request):
    id = request.REQUEST.get('id', '')
    title = request.REQUEST.get('title', '')
    desc = request.REQUEST.get('desc', '')
    startdate = request.REQUEST.get('startdate', '')
    enddate = request.REQUEST.get('enddate', '')

    color = request.REQUEST.get('color', '')

    warning_email = request.REQUEST.get('warning_email', '')
    warning_sms = request.REQUEST.get('warning_sms', '')
    warning_rtx = request.REQUEST.get('warning_rtx', '')
    wl = []
    if warning_email.lower() == 'true':
        wl.append('email')
    if warning_rtx.lower() == 'true':
        wl.append('rtx')
    if warning_sms.lower() == 'true':
        wl.append('sms')
    warning_time1 = request.REQUEST.get('warning_time1', '')
    warning_time2 = request.REQUEST.get('warning_time2', '')
    wtl = [warning_time1, warning_time2]


    if not title or not startdate :
        return getResult(False, u'请完善信息', None)
    if id:
        task = Task.objects.get(pk=id)
        RiLiWarning.objects.filter(warning_type__in=wl).filter(type='Task', fatherid=task.pk).delete()
    else:
        task = Task()
    task.title = title
    task.desc = desc
    with c:
        task.startdate = datetime.datetime.strptime(startdate, "%Y%m%d")
        task.enddate = datetime.datetime.strptime(enddate, "%Y%m%d")


    task.color = int(color)
    task.author = request.user
    task.warning_type = ','.join(wl)
    task.warning_time = ','.join(wtl)
    task.save()



    #
    # for wt in wl:
    #     for w in wtl:
    #         if w:
    #             rw = RiLiWarning()
    #             rw.fatherid = task.pk
    #             rw.type = 'Task'
    #             rw.warning_type = wt
    #             rw.timenum = int(w)
    #             rw.is_repeat = True
    #             rw.is_ok = True
    #             rw.save()
    # task.save()
    return getResult(True, u'保存成功', task.pk)
Ejemplo n.º 12
0
    def test(request, *args, **kwargs):
        project_id = int(kwargs.get('project_id'))
        if project_id:
            if project_id == settings.SHOW_PROJECT_ID:
                return func(request, *args, **kwargs)

            timeline = int(time.time())
            if not request.session.has_key('my_project'):
                project_list = []

                project_dict = {}
                my_project = {'project_list': project_list, 'project_dict': project_dict}
            else:
                my_project = request.session['my_project']
                project_list = my_project['project_list']
                project_dict = my_project['project_dict']
            if project_id in project_list and project_dict[str(project_id)] > timeline:
                return func(request, *args, **kwargs)
            elif project_id in project_list and project_dict[str(project_id)] == 0:
                return getResult(False, u'您不是 %s 的成员。' % Project.objects.get(pk=project_id).total_name, None, 6)
            else:
                try:
                    person = Person.objects.get(user=request.user, project_id=project_id)
                    project_list.append(project_id)
                    if person.is_active:
                        project_dict[str(project_id)] = timeline + settings.CACHES_TIMEOUT
                    else:
                        project_dict[str(project_id)] = 0
                    request.session['my_project'] = my_project
                    return func(request, *args, **kwargs)
                except Person.DoesNotExist:
                    return getResult(False, u'您不是 %s 的成员。' % Project.objects.get(pk=project_id).total_name, None, 6)
        else:
            return getResult(False, u'请选择正确的项目', {'name': request.user.name}, 2)
Ejemplo n.º 13
0
def query_favorite_zan_count_news_by_id(request, company_id=''):
    """
    查询新闻关注、赞、评论数量
    by:王健 at:2015-06-18
    查询用户是否赞过、收藏过和评论数量
    by:王健 at:2015-06-22
    增加company_id默认参数
    by:尚宗凯 at:2015-06-22
    适应性优化,公司id 从None改为''
    by:王健 at:2015-06-26
    :param request:
    :param company_id:
    :return:
    """
    news_id = request.REQUEST.get('id')
    if news_id:
        if company_id:
            news = CompanyNews.objects.get(pk=news_id)
        else:
            news = SysNews.objects.get(pk=news_id)
        if news:
            if company_id:
                result = query_news_favorite_zan(request.user.id, news_id, False)
            else:
                result = query_news_favorite_zan(request.user.id, news_id, True)

            if result is None or (isinstance(result, dict) and result.has_key("code")):
                return getResult(False, u'操作失败,请稍后再试')
            return getResult(True, u'获取评论数量成功。', result)
        return getResult(False, u'数据不存在')
    else:
        return getResult(False, u'请提供正确的参数')
Ejemplo n.º 14
0
def ding_favorite_by_id(request, company_id=''):
    """
    赞系统新闻
    by:王健 at:2015-06-18
    修复一个bug
    by:尚宗凯 at:2015-06-22
    修复栏目id错误的bug
    by:王健 at:2015-06-22
    修复dict 栏目id的bug
    by:王健 at:2015-06-23
    修复column_id
    by:王健 at:2015-06-25
    适应性优化,公司id 从None改为''
    by:王健 at:2015-06-26
    """
    news_id = request.REQUEST.get('id')
    if news_id:
        if company_id:
            news = CompanyNews.objects.get(pk=news_id).toJSON()
        else:
            news = SysNews.objects.get(pk=news_id).toJSON()
        if news:
            if company_id:
                result = favorite_news_by_id(request.user.id, company_id, news_id, news['company_column'], int(time.time()), False, news['title'], news['news_url'], news['icon_url'])
            else:
                result = favorite_news_by_id(request.user.id, company_id, news_id, news['sys_column'], int(time.time()), True, news['title'], news['news_url'], news['icon_url'])
            if result is None or (isinstance(result, dict) and result.has_key("code")):
                return getResult(False, u'操作失败,请稍后再试')
            return getResult(True, u'成功收藏了新闻 %s 。' % news['title'], result)
        return getResult(False, u'数据不存在')
    else:
        return getResult(False, u'请提供正确的参数')
Ejemplo n.º 15
0
def updateSubject(request):
    pk = request.REQUEST.get('id', '')
    if pk:
        kindForm = SubjectForm(request.POST, instance = Subject.objects.get(pk=pk))
    else:
        kindForm = SubjectForm(request.POST)

    if not kindForm.is_valid():
        msg = kindForm.json_error()
        return getResult(False,msg,None)
    if not kindForm.instance.accuracy:
        kindForm.instance.accuracy=0.0
    kind = kindForm.save()
    for i in range(20):
        id = request.REQUEST.get("option_id_%s"%i,None)
        content = request.REQUEST.get("option_content_%s"%i,None)
        is_right = request.REQUEST.get("option_is_right_%s"%i,None)
        if id or content or is_right:
            if is_right=='true':
                is_right=True
            else:
                is_right = False
            if id:
                option = Option.objects.get(pk=id)
            else:
                option = Option()
            option.content = content
            option.is_right = is_right
            option.subject = kind
            option.save()


    return getResult(True,u'保存试题信息成功', kind.pk)
Ejemplo n.º 16
0
def count_replay_by_news_id(request, company_id=''):
    """
    获取评论数量
    适应性优化,公司id 从None改为''
    by:王健 at:2015-06-26
    :param request:
    :param company_id:
    :return:
    """
    news_id = request.REQUEST.get('id')
    if news_id:
        if company_id:
            news = CompanyNews.objects.get(pk=news_id)
        else:
            news = SysNews.objects.get(pk=news_id)
        if news:
            if company_id:
                result = query_replay_num_by_news_id(news_id, False)
            else:
                result = query_replay_num_by_news_id(news_id, True)

            if result is None or (isinstance(result, dict) and result.has_key("code")):
                return getResult(False, u'操作失败,请稍后再试')
            return getResult(True, u'获取评论数量成功。', result)
        return getResult(False, u'数据不存在')
    else:
        return getResult(False, u'请提供正确的参数')
Ejemplo n.º 17
0
def query_replay_news_by_id(request, company_id=''):
    """
    查询查询记录的评论信息
    by:王健 at:2015-2-25
    去除 mongodb 影响
    by:王健 at:2015-3-8
    获取某个节点数据下的所有评论
    by:王健 at:2015-05-28
    修改错误提示语
    by:王健 at:2015-05-28
    添加分页属性
    by:王健 at:2015-06-24
    适应性优化,公司id 从None改为''
    by:王健 at:2015-06-26
    """
    news_id = request.REQUEST.get('id')
    start = int(request.REQUEST.get('start', 0))
    if news_id:
        if company_id:
            news = CompanyNews.objects.get(pk=news_id)
        else:
            news = SysNews.objects.get(pk=news_id)
        if news:
            if company_id:
                result = query_replay_by_news_id(news_id, False, start)
            else:
                result = query_replay_by_news_id(news_id, True, start)

            if result is None or (isinstance(result, dict)
                                  and result.has_key("code")):
                return getResult(False, u'操作失败,请稍后再试')
            return getResult(True, u'获取评论成功。', result)
        return getResult(False, u'数据不存在')
    else:
        return getResult(False, u'请提供正确的参数')
Ejemplo n.º 18
0
def get_userinfo(request, project_id):
    """
    根据id获取用户基础信息
    by:王健 at:2015-1-16
    修改个人信息返回值
    by:王健 at:2015-1-20
    修复id值不对的bug
    by:王健 at:2015-2-17
    查询视图替代查询表
    by:尚宗凯 at:2015-3-6
    查询表替代视图
    by:尚宗凯 at:2015-3-8
    :param request:
    :return:
    """
    userid = request.REQUEST.get('user_id')
    if Person.objects.filter(user_id=userid, project_id=project_id).exists():
        person = Person.objects.get(user_id=userid, project_id=project_id)
        user = person.user
        p = user.get_user_map()
        if hasattr(user, 'userinfo') and user.userinfo:
            p.update(MyEncoder.default(user.userinfo))
        p['id'] = user.pk
        return getResult(True, '', p)
    else:
        return getResult(False, u'不是项目组内成员')
Ejemplo n.º 19
0
def update_user_icon_url(request):
    """
    获取上传项目图标的url
    by:王健 at:2015-1-28
    解决用户被删除的bug
    by:王健 at:2015-2-5
    解决用户被删除的bug
    by:范俊伟 at:2015-2-9
    :param request:
    :param project_id:
    :return:
    """
    fileid = request.REQUEST.get('fileid')
    if fileid:
        fileobj = get_object_or_404(BaseFile, pk=fileid)
        fileobj.file_status = True
        fileobj.save()
        old_icon = None
        if fileobj.user.icon_url:
            old_icon = fileobj.user.icon_url
        fileobj.user.icon_url = fileobj
        fileobj.user.save()
        if old_icon:
            old_icon.delete()
        return getResult(True, u'上传成功', None)
    else:
        return getResult(False, u'没有上传文件id', None)
Ejemplo n.º 20
0
def submit_user_tel(request):
    """
    提交手机号
    by:王健 at:2015-1-15
    提交手机号,只需要登录过,不需要已经有手机号,排除登陆者自己的手机号
    by:王健 at:2015-1-16
    改下提示内容
    by:尚宗凯 at:2015-05-12
    短信验证码使用后从session中删除
    by: 范俊伟 at:2015-07-01
    """
    user = request.user
    code = request.REQUEST.get('code', '')
    tel = request.REQUEST.get('tel', '')
    smsdebug = request.REQUEST.get('smsdebug', '')
    if not smsdebug and code != request.session.get('smscode', '1234'):
        return getResult(False, u'手机验证码不对,请重新输入。', None)
    if not smsdebug and tel != request.session.get('smstel', ''):
        return getResult(False, u'发送验证码的手机号,和注册的手机号不符合。请重新输入', None)
    user.tel = tel
    if get_user_model().objects.filter(tel=user.tel).exclude(id=user.id).exists():
        return getResult(False, u'手机号已经存在。请更换手机号', None)
    name = request.REQUEST.get('name', u'游客')
    if name:
        user.name = name
    user.save()
    request.session['smscode'] = None
    return getResult(True, u'验证手机号成功', None)
Ejemplo n.º 21
0
def query_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
    """
    filerecord_id = request.REQUEST.get('id')
    flag = request.REQUEST.get('flag')
    if flag and filerecord_id:
        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 = query_replay_by_filerecord_id(flag, filerecord_id, project_id)
            if result is None or (isinstance(result, dict) and result.has_key("code")):
                return getResult(False, u'操作失败,请稍后再试')
            return getResult(True, u'获取评论成功。', {'pinglun': result, 'filerecord': filerecord.toJSON()})
    else:
        return getResult(False, u'请提供正确的参数')
Ejemplo n.º 22
0
def delete_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
    """
    filerecord_id = request.REQUEST.get('id')
    flag = request.REQUEST.get('flag')
    if filerecord_id and flag:
        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 = delete_zan_by_filerecord(project_id, flag, filerecord_id, request.user.pk)
            if result is None or (isinstance(result, dict) and result.has_key("code")):
                return getResult(False, u'操作失败,请稍后再试')
            return getResult(True, u'成功 %s 取消了赞。' % title, result)
        return getResult(False, u'数据不存在')
    else:
        return getResult(False, u'请提供正确的参数')
Ejemplo n.º 23
0
 def process_exception(self, request,e):
     import time
     errorid = time.time()
     log=logging.getLogger()
     s = [u'错误码:%s'%errorid]
     s.append(u'%s:%s'%(request.method,request.path))
     user = getattr(request, 'user', None)
     if user.username:
         s.append(u'用户:%s'%user.username)
     else:
         s.append(u'未登录用户')
     s.append(u'出现以下错误:')
     etype, value, tb = sys.exc_info()
     s.append(value.message)
     s.append(u'错误代码位置如下:')
     while tb is not None:
         f = tb.tb_frame
         lineno = tb.tb_lineno
         co = f.f_code
         filename = co.co_filename
         name = co.co_name
         s.append(u'File "%s", line %d, in %s' % (filename, lineno, name))
         tb = tb.tb_next
     if not settings.DEBUG:
         log.error('\n    '.join(s))
         return getResult(False,u'服务器端错误,请联系管理员,错误标记码:%s'%errorid)
     else:
         m = '\n    '.join(s)
         log.error(m)
         return getResult(False,u'服务器端错误,错误如下:\n%s'%(m))
Ejemplo n.º 24
0
def del_gysaddress_by_id(request, project_id):
    """
    删除供应商地址
    by:尚宗凯 at:2015-3-26
    删除项目应用节点最新数据时间
    by:尚宗凯 at:2015-05-20
    修复一个bug
    by:尚宗凯 at:2015-05-20
    删除时间改为30日之内
    by:尚宗凯 at:2015-05-27
    """
    # 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 or ghsform.instance.project_id != int(
                project_id):
            return getResult(False, u'不是您发布的数据,不能删除', status_code=2)
        if (ghsform.instance.create_time +
                datetime.timedelta(days=1)) < timezone.now():
            return getResult(False, u'超过30日的数据,不能删除', status_code=2)
        ghsform.instance.delete()
        #删除项目应用节点最新数据时间
        cache.delete(RED_DOT_PROJECT_FILE_GROUP_LAST_NEW_DATA_TIMELINE %
                     (project_id, ghsform.instance.file_group_id))
        cache.delete(RED_DOT_PROJECT_LAST_NEW_DATA_TIMELINE % project_id)
        return getResult(True, u'删除供应商记录成功', id)
    else:
        return getResult(False, u'参数不正确')
Ejemplo n.º 25
0
def del_wuzirecord_by_id(request, project_id=None):
    """
    不超过24小时的日志,可以由发布者 删除
    by:王健 at:2015-2-10
    修改权限校验 函数
    by:王健 at:2015-3-5
    删除项目应用节点最新数据时间
    by:尚宗凯 at:2015-05-20
    删除时间改为30日之内
    by:尚宗凯 at:2015-05-27
    """
    pk = request.REQUEST.get('id')
    if pk:
        wuzirecord = WuZiRecord.objects.get(pk=pk)
        if wuzirecord.project_id != int(
                project_id) or wuzirecord.user_id != request.user.pk:
            return getResult(False, u'不是您发布的数据,不能删除', status_code=2)
        if (wuzirecord.create_time +
                datetime.timedelta(days=30)) < timezone.now():
            return getResult(False, u'超过30日的数据,不能删除')
        wuzirecord.record_date.num -= 1
        wuzirecord.record_date.save()
        wuzirecord.is_active = False
        wuzirecord.save()
        #删除项目应用节点最新数据时间
        cache.delete(RED_DOT_PROJECT_FILE_GROUP_LAST_NEW_DATA_TIMELINE %
                     (project_id, wuzirecord.file_group_id))
        cache.delete(RED_DOT_PROJECT_LAST_NEW_DATA_TIMELINE % project_id)
        return getResult(True, u'删除物资记录成功', pk)
    else:
        return getResult(False, u'参数不正确')
Ejemplo n.º 26
0
def ding_news_by_id(request, company_id=''):
    """
    赞系统新闻
    by:王健 at:2015-06-18
    增加赞数量+1
    by:尚宗凯 at:2015-06-22
    修复栏目id错误的bug
    by:王健 at:2015-06-22
    适应性优化,公司id 从None改为''
    by:王健 at:2015-06-26
    """
    news_id = request.REQUEST.get('id')
    if news_id:
        if company_id:
            news = CompanyNews.objects.get(pk=news_id)
        else:
            news = SysNews.objects.get(pk=news_id)
        if news:
            if company_id:
                result = zan_news_by_id(request.user.id, company_id,
                                        news_id, news.company_column_id,
                                        int(time.time()), False)
            else:
                result = zan_news_by_id(request.user.id, company_id,
                                        news_id, news.sys_column_id,
                                        int(time.time()), True)
            news.add_zan_num()
            if result is None or (isinstance(result, dict)
                                  and result.has_key("code")):
                return getResult(False, u'操作失败,请稍后再试')
            return getResult(True, u'成功对 %s 点了个赞。' % news.title, result)
        return getResult(False, u'数据不存在')
    else:
        return getResult(False, u'请提供正确的参数')
Ejemplo n.º 27
0
def get_userinfo(request, project_id):
    """
    根据id获取用户基础信息
    by:王健 at:2015-1-16
    修改个人信息返回值
    by:王健 at:2015-1-20
    修复id值不对的bug
    by:王健 at:2015-2-17
    查询视图替代查询表
    by:尚宗凯 at:2015-3-6
    查询表替代视图
    by:尚宗凯 at:2015-3-8
    :param request:
    :return:
    """
    userid = request.REQUEST.get('user_id')
    if Person.objects.filter(user_id=userid, project_id=project_id).exists():
        person = Person.objects.get(user_id=userid, project_id=project_id)
        user = person.user
        p = user.get_user_map()
        if hasattr(user, 'userinfo') and user.userinfo:
            p.update(MyEncoder.default(user.userinfo))
        p['id'] = user.pk
        return getResult(True, '', p)
    else:
        return getResult(False, u'不是项目组内成员')
Ejemplo n.º 28
0
def regUser(request):
    '''
    注册新用户
    '''
    flag = request.REQUEST.has_key('flag')
    user = get_user_model()()
    if request.REQUEST.has_key('password'):
        user.set_password(request.REQUEST.get('password'))
    user.username = request.REQUEST.get('username', '')
    user.name = request.REQUEST.get('truename', u'游客')
    if not user.username or get_user_model().objects.filter(username=user.username).count() > 0:
        return getResult(True, u'邮箱已经存在', None, 201)
        # {'success': True, 'message': u'用户名已经存在', 'result': None}
    user.save()

    person = Person()
    person.user = user
    person.name = user.name
    if flag:
        orgquery = Organization.objects.filter(flag=flag)
        if orgquery.count() > 0:
            org = orgquery[0]
            person.org = org
            person.save()
            department = Department.objects.get(org=org, flag='free')
            department.members.add(person)
    else:
        createOrganization(request, person)

    return getResult(True, u'注册成功', {'username': user.get_username(), 'truename': user.name, 'id': user.pk})
Ejemplo n.º 29
0
def query_person(request, project_id=None):
    """
    获取所有联系人
    by:王健 at:2015-1-16
    优化URL参数 timeline 0 和空 一致
    by:王健 at:2015-2-26
    使用缓存
    by:王健 at:2015-3-9
    针对示例项目优化,获取成员接口
    by:王健 at:2015-3-25
    优化缓存结果的非空判断
    by:王健 at:2015-05-21
    """
    timeline = int(request.REQUEST.get('timeline', '0'))
    if not timeline:
        l = cache.get(PROJECT_PERSON_LIST % project_id)
        if l is None:
            l = Person.objects.filter(project_id=project_id).order_by('-timeline')
        else:
            if int(project_id) == settings.SHOW_PROJECT_ID:
                l.append(person_show_project_2_dict(request.user))
            return getResult(True, None, l)
    else:
        l = Person.objects.filter(project_id=project_id, timeline__gt=int(timeline)).order_by('timeline')
    ul = []
    for person in l:
        ul.append(person_2_dict(person))

    if not timeline:
        cache.set(PROJECT_PERSON_LIST % project_id, ul, settings.CACHES_TIMEOUT)
        if int(project_id) == settings.SHOW_PROJECT_ID:
                ul.append(person_show_project_2_dict(request.user))
    return getResult(True, None, ul)
Ejemplo n.º 30
0
def query_favorite_zan_count_news_by_id(request, company_id=''):
    """
    查询新闻关注、赞、评论数量
    by:王健 at:2015-06-18
    查询用户是否赞过、收藏过和评论数量
    by:王健 at:2015-06-22
    增加company_id默认参数
    by:尚宗凯 at:2015-06-22
    适应性优化,公司id 从None改为''
    by:王健 at:2015-06-26
    :param request:
    :param company_id:
    :return:
    """
    news_id = request.REQUEST.get('id')
    if news_id:
        if company_id:
            news = CompanyNews.objects.get(pk=news_id)
        else:
            news = SysNews.objects.get(pk=news_id)
        if news:
            if company_id:
                result = query_news_favorite_zan(request.user.id, news_id,
                                                 False)
            else:
                result = query_news_favorite_zan(request.user.id, news_id,
                                                 True)

            if result is None or (isinstance(result, dict)
                                  and result.has_key("code")):
                return getResult(False, u'操作失败,请稍后再试')
            return getResult(True, u'获取评论数量成功。', result)
        return getResult(False, u'数据不存在')
    else:
        return getResult(False, u'请提供正确的参数')
Ejemplo n.º 31
0
def query_group(request, project_id=None):
    """
    获取所有分组
    by:王健 at:2015-1-16
    排除root 组
    by:王健 at:2015-2-2
    不排除 root 组,方便客户端 组织“未分组” 。
    by:王健 at:2015-2-3
    优化URL参数 timeline 0 和空 一致
    by:王健 at:2015-2-26
    使用缓存
    by:王健 at:2015-3-9
    优化缓存结果的非空判断
    by:王健 at:2015-05-21
    修改控制校验
    by:王健 at:2015-05-21
    """
    timeline = int(request.REQUEST.get('timeline', '0'))
    if not timeline:
        l = cache.get(PROJECT_GROUP_LIST % project_id)
        if l is None:
            l = Group.objects.filter(project_id=project_id).filter(is_active=True).order_by('-timeline')
        else:
            return getResult(True, None, l)
    else:
        l = Group.objects.filter(project_id=project_id, timeline__gt=int(timeline)).filter(is_active=True).order_by('timeline')
    ul = []
    for person in l:
        ul.append(group_2_dict(person))
    if not timeline:
        cache.set(PROJECT_GROUP_LIST % project_id, ul, settings.CACHES_TIMEOUT)
    return getResult(True, None, ul)
Ejemplo n.º 32
0
def del_log_by_id(request, project_id=None):
    """
    不超过24小时的日志,可以由发布者 删除
    by:王健 at:2015-2-10
    清除最新数据事件缓存
    by:尚宗凯 at:2015-05-20
    删除时间改为30日之内
    by:尚宗凯 at:2015-05-27
    """
    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)
        if (sg_log.create_time + datetime.timedelta(days=30)) < timezone.now():
            return getResult(False, u'超过30日的数据,不能删除')
        sg_log.sg_tq_log.num -= 1
        sg_log.sg_tq_log.save()
        sg_log.is_active = False
        sg_log.create_time = timezone.now()
        sg_log.save()
        #删除项目应用节点最新数据时间
        cache.delete(RED_DOT_PROJECT_FILE_GROUP_LAST_NEW_DATA_TIMELINE %
                     (project_id,
                      get_file_group_id_by_flag_from_cache(
                          project_id=project_id, flag="gong_cheng_ri_zhi")))
        cache.delete(RED_DOT_PROJECT_LAST_NEW_DATA_TIMELINE % project_id)
        return getResult(True, u'删除日志成功', pk)
    else:
        return getResult(False, u'参数不正确')
Ejemplo n.º 33
0
def count_replay_by_news_id(request, company_id=''):
    """
    获取评论数量
    适应性优化,公司id 从None改为''
    by:王健 at:2015-06-26
    :param request:
    :param company_id:
    :return:
    """
    news_id = request.REQUEST.get('id')
    if news_id:
        if company_id:
            news = CompanyNews.objects.get(pk=news_id)
        else:
            news = SysNews.objects.get(pk=news_id)
        if news:
            if company_id:
                result = query_replay_num_by_news_id(news_id, False)
            else:
                result = query_replay_num_by_news_id(news_id, True)

            if result is None or (isinstance(result, dict)
                                  and result.has_key("code")):
                return getResult(False, u'操作失败,请稍后再试')
            return getResult(True, u'获取评论数量成功。', result)
        return getResult(False, u'数据不存在')
    else:
        return getResult(False, u'请提供正确的参数')
Ejemplo n.º 34
0
def query_replay_news_by_id(request, company_id=''):
    """
    查询查询记录的评论信息
    by:王健 at:2015-2-25
    去除 mongodb 影响
    by:王健 at:2015-3-8
    获取某个节点数据下的所有评论
    by:王健 at:2015-05-28
    修改错误提示语
    by:王健 at:2015-05-28
    添加分页属性
    by:王健 at:2015-06-24
    适应性优化,公司id 从None改为''
    by:王健 at:2015-06-26
    """
    news_id = request.REQUEST.get('id')
    start = int(request.REQUEST.get('start', 0))
    if news_id:
        if company_id:
            news = CompanyNews.objects.get(pk=news_id)
        else:
            news = SysNews.objects.get(pk=news_id)
        if news:
            if company_id:
                result = query_replay_by_news_id(news_id, False, start)
            else:
                result = query_replay_by_news_id(news_id, True, start)

            if result is None or (isinstance(result, dict) and result.has_key("code")):
                return getResult(False, u'操作失败,请稍后再试')
            return getResult(True, u'获取评论成功。', result)
        return getResult(False, u'数据不存在')
    else:
        return getResult(False, u'请提供正确的参数')
Ejemplo n.º 35
0
def login(request):
    username = request.REQUEST.get('username')
    if username:
        userlist = get_user_model().objects.filter(username=username)[:1]
        if len(userlist) > 0:
            user = userlist[0]
            if not user.is_active:
                return getResult(False, u'用户已经停止使用。')
    form = AuthenticationForm(data=request.POST)
    if form.is_valid():


        # Okay, security checks complete. Log the user in.
        auth_login(request, form.get_user())

        if request.session.test_cookie_worked():
            request.session.delete_test_cookie()
        org_num = request.user.person_set.filter(is_action=True).count()
        if org_num == 1:
            request.session['person'] = request.user.paper_set.filter(is_action=True)[0]
            request.session['org'] = request.session['person'].org
        if not request.user.email_active:
            return getResult(True, u'登录成功,请完成邮箱验证', None, 202)
        return getResult(True, u'登录成功', None)
    else:
        return getResult(False, u'用户名密码错误', request.session.session_key, 500)
Ejemplo n.º 36
0
def ding_news_by_id(request, company_id=''):
    """
    赞系统新闻
    by:王健 at:2015-06-18
    增加赞数量+1
    by:尚宗凯 at:2015-06-22
    修复栏目id错误的bug
    by:王健 at:2015-06-22
    适应性优化,公司id 从None改为''
    by:王健 at:2015-06-26
    """
    news_id = request.REQUEST.get('id')
    if news_id:
        if company_id:
            news = CompanyNews.objects.get(pk=news_id)
        else:
            news = SysNews.objects.get(pk=news_id)
        if news:
            if company_id:
                result = zan_news_by_id(request.user.id, company_id, news_id, news.company_column_id, int(time.time()), False)
            else:
                result = zan_news_by_id(request.user.id, company_id, news_id, news.sys_column_id, int(time.time()), True)
            news.add_zan_num()
            if result is None or (isinstance(result, dict) and result.has_key("code")):
                return getResult(False, u'操作失败,请稍后再试')
            return getResult(True, u'成功对 %s 点了个赞。' % news.title, result)
        return getResult(False, u'数据不存在')
    else:
        return getResult(False, u'请提供正确的参数')
Ejemplo n.º 37
0
def del_wuzirecord_by_id(request, project_id=None):
    """
    不超过24小时的日志,可以由发布者 删除
    by:王健 at:2015-2-10
    修改权限校验 函数
    by:王健 at:2015-3-5
    删除项目应用节点最新数据时间
    by:尚宗凯 at:2015-05-20
    删除时间改为30日之内
    by:尚宗凯 at:2015-05-27
    """
    pk = request.REQUEST.get('id')
    if pk:
        wuzirecord = WuZiRecord.objects.get(pk=pk)
        if wuzirecord.project_id != int(project_id) or wuzirecord.user_id != request.user.pk:
            return getResult(False, u'不是您发布的数据,不能删除', status_code=2)
        if (wuzirecord.create_time + datetime.timedelta(days=30)) < timezone.now():
            return getResult(False, u'超过30日的数据,不能删除')
        wuzirecord.record_date.num -= 1
        wuzirecord.record_date.save()
        wuzirecord.is_active = False
        wuzirecord.save()
        #删除项目应用节点最新数据时间
        cache.delete(RED_DOT_PROJECT_FILE_GROUP_LAST_NEW_DATA_TIMELINE % (project_id, wuzirecord.file_group_id))
        cache.delete(RED_DOT_PROJECT_LAST_NEW_DATA_TIMELINE % project_id)
        return getResult(True, u'删除物资记录成功', pk)
    else:
        return getResult(False, u'参数不正确')
Ejemplo n.º 38
0
def delete_ding_news_by_id(request, company_id=''):
    """
    对一个记录发出顶的操作
    by:王健 at:2015-2-25
    删除点赞
    by:王健 at:2015-05-28
    修改错误提示语
    by:王健 at:2015-05-28
    解决enginecheck 没有title的bug
    by:王健 at:2015-06-01
    删除赞
    by:王健 at:2015-06-25
    适应性优化,公司id 从None改为''
    by:王健 at:2015-06-26
    """
    news_id = request.REQUEST.get('id')
    if news_id:
        if company_id:
            news = CompanyNews.objects.get(pk=news_id)
        else:
            news = SysNews.objects.get(pk=news_id)
        if news:
            if company_id:
                result = del_zan_news_by_id(request.user.id, news_id, False)
            else:
                result = del_zan_news_by_id(request.user.id, news_id, True)
            news.add_zan_num(-1)
            if result is None or (isinstance(result, dict) and result.has_key("code")):
                return getResult(False, u'操作失败,请稍后再试')
            return getResult(True, u'成功对 %s 取消了赞。' % news.title, result)
        return getResult(False, u'数据不存在')
    else:
        return getResult(False, u'请提供正确的参数')
Ejemplo n.º 39
0
def del_gysaddress_by_id(request, project_id):
    """
    删除供应商地址
    by:尚宗凯 at:2015-3-26
    删除项目应用节点最新数据时间
    by:尚宗凯 at:2015-05-20
    修复一个bug
    by:尚宗凯 at:2015-05-20
    删除时间改为30日之内
    by:尚宗凯 at:2015-05-27
    """
    # 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 or ghsform.instance.project_id != int(project_id):
            return getResult(False, u'不是您发布的数据,不能删除', status_code=2)
        if (ghsform.instance.create_time + datetime.timedelta(days=1)) < timezone.now():
            return getResult(False, u'超过30日的数据,不能删除', status_code=2)
        ghsform.instance.delete()
        #删除项目应用节点最新数据时间
        cache.delete(RED_DOT_PROJECT_FILE_GROUP_LAST_NEW_DATA_TIMELINE % (project_id, ghsform.instance.file_group_id))
        cache.delete(RED_DOT_PROJECT_LAST_NEW_DATA_TIMELINE % project_id)
        return getResult(True, u'删除供应商记录成功', id)
    else:
        return getResult(False, u'参数不正确')
Ejemplo n.º 40
0
def joinGroup(request):
    id = request.REQUEST.get('id','')
    username = request.REQUEST.get('username','')
    do = request.REQUEST.get('do','')
    usertype = request.REQUEST.get('type','join')
    if id:
        group = Group.objects.get(pk=id)
        if do =='join':
            if usertype=='join' and  username!=group.author.username and 0==group.users.filter(username=username).count():
                group.users.add(User.objects.get(username=username))
                group.observers.remove(User.objects.get(username=username))
                group.save()
            if usertype=='observer' and  username!=group.author.username and 0==group.observers.filter(username=username).count():
                group.observers.add(User.objects.get(username=username))
                group.users.remove(User.objects.get(username=username))
                group.save()
        elif do == 'out':
            if username!=group.author.username and (1==group.users.filter(username=username).count() or 1==group.observers.filter(username=username).count()):
                group.users.remove(User.objects.get(username=username))
                group.observers.remove(User.objects.get(username=username))
                group.save()
        else:
            return getResult(False,u'操作不正确',id)
        return getResult(True,u'完成操作',id)
    else:
        return getResult(False,u'操作不正确',id)
Ejemplo n.º 41
0
 def test(request, *args, **kwargs):
     if get_current_org():
         if get_current_org().is_active:
             return func(request, *args, **kwargs)
         else:
             return getResult(False, u'%s 的可使用额度不足,请续费后继续使用。' % get_current_org(), None, 400)
     else:
         return getResult(False, u'请先选择当前工作的组织或公司', None, 403)
Ejemplo n.º 42
0
 def test(request, *args, **kwargs):
     if get_current_person() and get_current_org():
         if get_current_person().is_active:
             return func(request, *args, **kwargs)
         else:
             return getResult(False, u'您已经离开了 %s。' % get_current_org(), None, 402)
     else:
         return getResult(False, u'请先选择当前工作的组织或公司', None, 403)
Ejemplo n.º 43
0
 def test(request, *args, **kwargs):
     if not request.user.is_anonymous():
         if request.user.is_active:
             return func(request, *args, **kwargs)
         else:
             return getResult(False, u'用户已被禁用。', None, 5)
     else:
         return getResult(False, u'请先登录', None, 1)
Ejemplo n.º 44
0
def replay_news_by_id(request, company_id=''):
    """
    对一条记录发出评论
    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
    增加评论数量+1
    by:尚宗凯 at:2015-06-22
    修复bug
    by:尚宗凯 at:2015-06_22
    修复栏目id错误的bug
    by:王健 at:2015-06-22
    增加name参数
    by:王健 at:2015-06-24
    适应性优化,公司id 从None改为''
    by:王健 at:2015-06-26
    获取昵称
    by:王健 at:2015-06-26
    """
    content = request.REQUEST.get('content', '')[:100]
    news_id = request.REQUEST.get('id')
    if news_id:
        if company_id:
            news = CompanyNews.objects.get(pk=news_id)
        else:
            news = SysNews.objects.get(pk=news_id)
        if news:
            if company_id:
                result = create_replay_by_news_id(request.user.id,
                                                  request.user.get_nickname(),
                                                  company_id, news_id,
                                                  news.company_column_id,
                                                  int(time.time()), content,
                                                  False)
            else:
                result = create_replay_by_news_id(request.user.id,
                                                  request.user.get_nickname(),
                                                  company_id, news_id,
                                                  news.sys_column_id,
                                                  int(time.time()), content,
                                                  True)
            news.add_replay_num()
            if result is None or (isinstance(result, dict)
                                  and result.has_key("code")):
                return getResult(False, u'操作失败,请稍后再试')
            return getResult(True, u'成功对 %s 发布了评论。' % news.title, result)
        return getResult(False, u'数据不存在')
    else:
        return getResult(False, u'请提供正确的参数')
Ejemplo n.º 45
0
 def test(request, *args, **kwargs):
     if isinstance(request, TemplateView):
         request2 = args[0]
     else:
         request2 = request
     if not request2.user.is_anonymous():
         if request2.user.is_active and request2.user.is_staff:
             return func(request, *args, **kwargs)
         else:
             return getResult(False, u'系统管理员才能进行此操作。', None, 5)
     else:
         return getResult(False, u'请先登录', None, 1)
Ejemplo n.º 46
0
def get_address_by_id(request):
    """
    根据地址id获取地址信息
    by: 范俊伟 at:2015-03-20
    :param request:
    :return:
    """
    id = request.REQUEST.get('id')
    for i in counties:
        if str(i.get('id')) == id:
            return getResult(True, '', i)
    return getResult(False, '无此记录')
Ejemplo n.º 47
0
    def process_exception(self, request, e):
        """
        程序遇到未捕获的异常,会在此处整理出错误信息,和代码行数
        by:王健 at:2015-1-3
        修改日志 配置
        by:王健 at:2015-3-10
        修改获取用户手机号
        by:王健 at:2015-3-15
        优化 日志输入
        by:王健 at:2015-3-17
        修改错误堆栈信息 获取方式
        by:王健 at:2015-4-7
        修改错误输出格式
        by: 范俊伟 at:2015-04-19
        修改log输出函数
        by: 范俊伟 at:2015-05-05
        :param request:
        :param e:
        :return:
        """
        import time

        errorid = time.time()
        log = logging.getLogger('django')
        s = [u'错误码:%s' % errorid, u'%s:%s' % (request.method, request.path)]
        user = getattr(request, 'user', None)
        if hasattr(user, "tel"):
            s.append(u'用户:%s' % user.tel)
        else:
            s.append(u'未登录用户')
        s.append(u'出现以下错误:')
        #s.append(traceback.format_exc())
        etype, value, tb = sys.exc_info()
        s.append(repr(value.message))
        s.append(u'错误代码位置如下:')
        while tb is not None:
            f = tb.tb_frame
            lineno = tb.tb_lineno
            co = f.f_code
            filename = co.co_filename
            name = co.co_name
            s.append(u'File "%s", line %d, in %s' % (filename, lineno, name))
            tb = tb.tb_next
        if not settings.DEBUG:
            log.exception('\n    '.join(s))
            return getResult(False,
                             u'服务器端错误,请联系管理员,错误标记码:%s' % errorid,
                             dialog=2)
        else:
            m = '\n    '.join(s)
            log.exception(m)
            return getResult(False, u'服务器端错误,错误如下:\n%s' % (m), dialog=2)
Ejemplo n.º 48
0
def add_user_by_tel_to_company(request, company_id):
    """
    通过手机号添加用户
    by: 范俊伟 at:2015-06-25
    :param request:
    :param company_id:
    :return:
    """
    try:
        company = Company.objects.get(id=company_id)
    except Company.DoesNotExist:
        return getResult(False, '公司不存在')
    tels = request.REQUEST.getlist('tel')
    success_tels = []
    error_tels = []
    send_sms_tels = []
    for tel in set(tels):
        try:
            user = get_user_model().objects.get(tel=tel)
            CompanyPerson.objects.get_or_create(user=user, company=company)
            success_tels.append(tel)
        except get_user_model().DoesNotExist:
            tellist = []
            for c in tel.replace('+86', ''):
                try:
                    int(c)
                    tellist.append(c)
                except:
                    pass
            if len(tellist) == 11:
                new_tel = ''.join(tellist)
                submail = MESSAGEXsend(MESSAGE_CONFIGS)
                submail.add_to(new_tel)
                submail.set_project('rT7w11')
                submail.add_var('from', (True and [request.user.name]
                                         or [request.user.tel])[0])
                submail.add_var('project', company.name)
                submail.add_var(
                    'url',
                    '%s?v=%s' % (settings.MESSAGE_URL, random.randint(0, 100)))
                submail.xsend()
                send_sms_tels.append(tel)
            else:
                error_tels.append(tel)
                continue

    return getResult(
        True, '', {
            "success_tels": success_tels,
            "error_tels": error_tels,
            "send_sms_tels": send_sms_tels
        })
Ejemplo n.º 49
0
def search(request):
    """
    阿里开放搜索
    by:尚宗凯 at:2015-05-15
    """
    search_flag = request.REQUEST.get('search_flag')
    query = request.REQUEST.get('query')
    if not search_flag:
        return getResult(False, u'search_flag参数未填')
    result = AliyunSearch.query(index_name=search_flag,
                                table_name=search_flag,
                                query=query)
    return getResult(True, u'搜索成功', result)
Ejemplo n.º 50
0
 def test(request, *args, **kwargs):
     if not request.user.is_anonymous():
         if request.user.is_active:
             if request.user.tel == None:
                 project_id = int(kwargs.get('project_id','0'))
                 if project_id == settings.SHOW_PROJECT_ID:
                     return func(request, *args, **kwargs)
                 return getResult(False, u'请登记手机号。', None, status_code=9)
             return func(request, *args, **kwargs)
         else:
             return getResult(False, u'用户已被禁用。', None, 5)
     else:
         return getResult(False, u'请先登录', None, 1)
Ejemplo n.º 51
0
def guanzhu_project(request):
    """
    关注项目
    by:王健 at:2015-1-30
    元祖改为字符串
    by:王健 at:2015-1-31
    增加缓存
    by:王健 at:2015-3-9
    清空个人信息
    by:王健 at:2015-3-16
    """
    cache.delete(MY_PROJECT_QUERY_LIST % request.user.pk)
    project_id = request.REQUEST.get('project_id', '')
    do = request.REQUEST.get('do', 'join')
    try:
        project = Project.objects.get(id=project_id)
        if do == 'join':
            if not project.nsuser_set.filter(id=request.user.id).exists():
                project.nsuser_set.add(request.user)
                project.guanzhu_num += 1
                project.save()
                msg = u'关注%s成功'
                cache.delete(USERINFO_INFO % request.user.pk)
            else:
                msg = u'已经关注过%s'
            return getResult(
                True, msg % project.name, {
                    'project':
                    MyEncoder.default(project),
                    'guanzhuprojectlist':
                    [p[0] for p in request.user.guanzhu.values_list('id')]
                })
        else:
            if project.nsuser_set.filter(id=request.user.id).exists():
                project.nsuser_set.remove(request.user)
                project.guanzhu_num -= 1
                project.save()
                cache.delete(USERINFO_INFO % request.user.pk)
            return getResult(
                True, u'取消关注%s成功' % project.name, {
                    'project':
                    MyEncoder.default(project),
                    'guanzhuprojectlist':
                    [p[0] for p in request.user.guanzhu.values_list('id')]
                })
    except Project.DoesNotExist:
        return getResult(False, u'项目不存在')
    except ValueError:
        return getResult(False, u'参数格式错误')
Ejemplo n.º 52
0
def admin_init_password(request):
    """
    初始化密码为 手机号后六位
    by:王健 at:2015-3-20
    """
    tel = request.REQUEST.get('tel')
    if not request.user.is_staff:
        return getResult(False, u'您不是系统管理员。')
    try:
        user = get_user_model().objects.get(tel=tel)
        user.set_password(user.tel[-6:])
        user.save()
        return getResult(True, u'初始化成功', None)
    except:
        return getResult(False, u'账号不存在。')
Ejemplo n.º 53
0
def current_user(request):
    """
    所有用户名 都改为 tel
    by:王健 at:2015-1-8
    修改个人信息返回值
    by:王健 at:2015-1-20
    增加积分
    by:王健 at:2015-2-5
    未登录用户自动生成测试账号
    by:尚宗凯 at:2015-3-26
    添加时间戳,防止 批量重复创建用户
    by:王健 at:2015-4-6
    无账号调用,则使用游客账号
    by:王健 at:2015-4-8
    :param request:
    :return:
    """
    if not request.user.is_anonymous():
        # if request.user.is_anonymous():
        if request.user.is_active:
            # if request.user.tel == None:
            #     return getResult(False, u'请登记手机号。', None, status_code=9)
            return getResult(True,
                             '',
                             request.user.get_user_map(True),
                             jifen=login_jifen(request))
        else:
            return getResult(False, u'用户已被禁用。', None, 5)
    # else:
    #     return getResult(False, u'请先登录', None, 1)
    else:
        # t = int(request.REQUEST.get('t', '0'))
        # timeline = int(time.time())
        # if (t + 20) < timeline:
        #     return getResult(False, u'校验不通过。', None, 5)
        user = get_user_model().objects.get(pk=settings.SHOW_USER_ID)
        # # user = NSUser()
        # user.tel = None
        # user.set_password('123456')
        # user.name = u"测试账号"
        # user.nickname = "测试账号"
        # user.save()
        user.backend = 'django.contrib.auth.backends.ModelBackend'
        auth_login(request, user)
        return getResult(True,
                         '',
                         request.user.get_user_map(True),
                         jifen=login_jifen(request))
Ejemplo n.º 54
0
def query_gysaddress_by_group_old(request, project_id=None):
    """
    查询供应商名录,根据应用节点,和时间戳 旧数据
    by:王健 at:2015-1-14
    修改排序错误
    by:王健 at:2015-1-26
    优化URL参数 timeline 0 和空 一致
    by:王健 at:2015-2-26
    修改权限校验 函数
    by:王健 at:2015-3-5
	修改搜索结束时间逻辑
	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__lt=int(timeline)).order_by('-timeline')[:20]
    return getResult(True, None, MyEncoder.default(l))
Ejemplo n.º 55
0
def commit_project_by_date(request):
    """
    查询某日到某日的新建项目列表
    by:王健 at:2015-05-26
    :param request:
    :return:
    """
    start_date = get_date_by_request(request, 'start_date')
    end_date = get_date_by_request(request, 'end_date')

    projectlist = Project.objects.filter(create_time__gt=start_date,
                                         create_time__lt=end_date +
                                         datetime.timedelta(days=1),
                                         is_active=True)

    l = []
    for p in projectlist:
        l.append({
            'date': p.create_time.strftime('%Y-%m-%d'),
            'name': p.total_name,
            'manager': p.manager.name,
            'tel': p.manager.tel,
            'num': p.person_set.filter(is_active=True).count()
        })

    return getResult(True, u'', l)
Ejemplo n.º 56
0
        def test(request, *args, **kwargs):
            """
            优化缓存结果的非空判断
            by:王健 at:2015-05-21
            修改控制校验
            by:王健 at:2015-05-21
            """
            user = request.user
            project_id = int(kwargs.get('project_id'))

            if not (add or update or delete or app_add or app_update or app_del):
                if project_id == settings.SHOW_PROJECT_ID:
                    return func(request, *args, **kwargs)

            # cache_key_project = PROJECT_POWER_TIMELINE % project_id
            project_powers, project_powers_flag = get_cache_project_power_timeline(project_id)

            if not flag:
                flags = request.REQUEST.get(flag_name, '')
                filegroup_id = project_powers['flag'].get(flags, 0)
            else:
                filegroup_id = project_powers['flag'].get(flag)

            has_prower = filegroup_id * 100
            if add:
                has_prower += 1
            if update:
                has_prower += 2
            if delete:
                has_prower += 3
            if app_add:
                has_prower += 4
            if app_update:
                has_prower += 5
            if app_del:
                has_prower += 6
            # 获取个人 权限
            if not request.session.has_key('project_id_%s' % project_id):
                person_powers = None
            else:
                person_powers = request.session['project_id_%s' % project_id]
                person_timeline = cache.get(PERSON_TIMELINE % (project_id, request.user.pk))
                if person_timeline is None:
                    person_timeline = Person.objects.get(user=request.user, project_id=project_id).timeline
                    cache.set(PERSON_TIMELINE % (project_id, request.user.pk), person_timeline, settings.CACHES_TIMEOUT)
            # powers = None
            if not person_powers or (person_powers.has_key('person_timeline') and person_timeline > person_powers['person_timeline']):
                person_powers = {'timeline': int(time.time()), 'person_timeline': int(time.time()), 'group': [], 'person': []}

                person = Person.objects.get(user=user, project_id=project_id)
                person_powers['person'] = person.real_powers()
                request.session['project_id_%s' % project_id] = person_powers

            #判断权限
            if person_powers['person'] and has_prower in person_powers['person']:
                return func(request, *args, **kwargs)
            # for gid in person_powers['group']:
            #     if project_powers['powers'] and project_powers['powers'].has_key(str(gid)) and has_prower in project_powers['powers'][str(gid)]:
            #         return func(request, *args, **kwargs)
            return getResult(False, u'您的权限不足,不能进行本项操作。' , None, status_code=8)
Ejemplo n.º 57
0
def get_project_info(request):
    """
    查询项目信息
    by: 范俊伟 at:2015-05-14
    :param request:
    :return:
    """
    id = request.REQUEST.get('id')
    if not id:
        return getResult(False, '未提供项目id')
    try:
        project = Project.objects.get(id=id)
    except Project.DoesNotExist:
        return getResult(False, '项目不存在')

    return getResult(True, '', MyEncoder.default(project))