Ejemplo n.º 1
0
def query_sysmessage(request, project_id=None):
    """
    根据项目查询系统消息
    by:王健 at:2015-2-26
    优化系统消息查询接口
    by:王健 at:2015-4-13
    增加刷新最后阅读系统消息时间
    by:尚宗凯 at:2015-05-08
    删除缓存
    by:尚宗凯 at:2105-05-22
    """
    timeline = int(request.REQUEST.get('timeline', '0'))
    group_id = request.REQUEST.get('group_id')
    l = SysMessage.objects.filter(project_id=project_id)
    if timeline:
        l = l.filter(timeline__gt=int(timeline)).order_by('timeline')
    else:
        l = l.order_by('-timeline')
    if group_id:
        l = l.filter(Q(user_id=request.user.pk) | Q(user=None) | Q(to_group_id=group_id))
    else:
        l = l.filter(to_group_id=None).filter(Q(user_id=request.user.pk) | Q(user=None))
    user_id = request.user.pk
    LastReadTimeProjectSysMessage.update_last_read_timeline(type="sysmessage", user_id=user_id, project_id=project_id,group_id=group_id)
    cache.delete(RED_DOT_PROJECT_SYS_MESSAGE_UNREAD_NUMBER % ("sysmessage", user_id, project_id, None))
    return getResult(True, u'获取系统消息', MyEncoder.default(l[:20]))
Ejemplo n.º 2
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.º 3
0
def query_project_message_old(request, project_id=None):
    """
    根据项目查询分组公告旧数据
    by:王健 at:2015-2-26
    增加刷新最后一次阅读项目公告时间
    by:尚宗凯 at:2015-05-08
    删除缓存
    by:尚宗凯 at:2105-05-22
    """
    timeline = int(request.REQUEST.get('timeline', '0'))
    group_id = request.REQUEST.get('group_id')
    l = ProjectMessage.objects.filter(project_id=project_id, to_group_id=group_id)
    if timeline:
        l = l.filter(timeline__lt=int(timeline)).order_by('-timeline')
    else:
        l = l.order_by('-timeline')
    user_id = request.user.pk
    LastReadTimeProjectSysMessage.update_last_read_timeline(type="project_message", user_id=user_id, project_id=project_id,group_id=group_id)
    cache.delete(RED_DOT_PROJECT_SYS_MESSAGE_UNREAD_NUMBER % ("project_message", user_id, project_id, group_id))
    return getResult(True, u'获取公告', MyEncoder.default(l[:20]))
Ejemplo n.º 4
0
def query_sysmessage_old(request, project_id=None):
    """
    根据项目查询系统消息旧数据
    by:王健 at:2015-2-26
    优化系统消息查询接口
    by:王健 at:2015-4-13
    增加刷新最后阅读系统消息时间
    by:尚宗凯 at:2015-05-08
    """
    timeline = int(request.REQUEST.get('timeline', '0'))
    group_id = request.REQUEST.get('group_id')
    l = SysMessage.objects.filter(project_id=project_id)
    if timeline:
        l = l.filter(timeline__lt=int(timeline)).order_by('-timeline')
    else:
        l = l.order_by('-timeline')

    if group_id:
        l = l.filter(Q(user_id=request.user.pk) | Q(user=None) | Q(to_group_id=group_id))
    else:
        l = l.filter(to_group_id=None).filter(Q(user_id=request.user.pk) | Q(user=None))
        LastReadTimeProjectSysMessage.update_last_read_timeline(type="sysmessage", user_id=request.user.pk, project_id=project_id,group_id=group_id)
    return getResult(True, u'获取系统消息', MyEncoder.default(l[:20]))