Ejemplo n.º 1
0
def get_mobile_version(mobile_type):
    mobile_ver = MobileDef.objects.filter(is_del=FALSE_INT,
                                          type=int(mobile_type)).first()
    if not mobile_ver:
        raise BusinessException(CLIENT_NOT_EXIST)

    version_url = mobile_ver.latest_version_url
    if (not version_url.startswith('http://')) and (
            not version_url.startswith('https://')):
        version_url = urljoin(get_current_sys_domain(),
                              mobile_ver.latest_version_url)

    # 安卓手机下载更新包走统计接口
    if int(mobile_type) == MOBILE_TYPE_ANDROID_PHONE:
        apk_name = mobile_ver.latest_version_url[mobile_ver.latest_version_url.
                                                 rfind('/') + 1:]

        (shortname, extension) = os.path.splitext(apk_name)
        apk_name = '%s_%s%s' % (shortname, str(random.randint(
            1, 10000000)), extension)

        version_url = urljoin(get_current_sys_domain(),
                              settings.ANDROID_APK_DOWNLOAD_UPGRADE + apk_name)

    checksum = mobile_ver.latest_version_checksum if mobile_ver.latest_version_checksum else ''

    ret_value = {
        'latest_version': str(mobile_ver.latest_version),
        'latest_version_url': version_url,
        'latest_version_checksum': checksum,
        'support_version': str(mobile_ver.support_version),
        'version_info': mobile_ver.version_info
    }
    return ret_value
Ejemplo n.º 2
0
def get_mobile_qrcode():
    # qrcode_obj = GlobalPara.objects.filter(is_del=FALSE_INT, key=MOBILE_DOWNLOAD_QRCODE_KEY_IN_DB).first()
    # if not qrcode_obj:
    #     url = ''
    # else:
    #     url = urljoin(get_current_sys_domain(), qrcode_obj.value)
    # return {
    #     'qrcode': url
    # }
    return urljoin(get_current_sys_domain(),
                   'media/public/packages/mobile.png')
Ejemplo n.º 3
0
def _prepare_ctx(request, html):
    ctx = {}
    if html == 'page_moment_detail':
        ctx = {
            'moment_id': request.GET.get('moment_id')
        }
    if html == 'page_mobile_download':
        iphone = MobileDef.objects.filter(is_del=FALSE_INT, type=MOBILE_TYPE_APPLE_PHONE).first()
        android_phone = MobileDef.objects.filter(is_del=FALSE_INT, type=MOBILE_TYPE_ANDROID_PHONE).first()
        ctx = {
            'ios_pkg': urljoin(get_current_sys_domain(), iphone.latest_version_url) if iphone else '',
            'android_pkg': urljoin(get_current_sys_domain(), settings.ANDROID_APK_DOWNLOAD + '?rand='+str(random.randint(1, 10000000))),
        }
    if html == 'page_board_class_moment':
        school_code = request.GET.get('school_code')
        grade_num = request.GET.get('grade_num')
        class_num = request.GET.get('class_num')
        clazz = Class.objects.filter(
            school__code=school_code, grade_num=int(grade_num), class_num=int(class_num), del_flag=FALSE_INT).first()
        ctx = {'class_id': clazz.id} if clazz else {'class_id': ''}
    return ctx
Ejemplo n.º 4
0
def update_mobile(type, latest_version, latest_pkg, version_info):
    mobile = MobileDef.objects.filter(is_del=FALSE_INT, type=int(type)).first()
    if not mobile:
        raise BusinessException(CLIENT_NOT_EXIST)

    checksum = ''

    if int(type) == MOBILE_TYPE_ANDROID_PHONE:
        if not latest_pkg:
            raise BusinessException(NO_APK_ERROR)

        relative_path = file_storage.gen_path(
            os.path.join(settings.MEDIA_PATH_PUBLIC, 'packages'),
            latest_pkg.name)

        if MobileHistory.objects.filter(url=relative_path).exists():
            raise BusinessException(APK_NAME_ERROR)

        if settings.USE_S3:
            checksum = s3_storage.get_operator().upload_file_obj(
                latest_pkg, relative_path)
        else:
            checksum = file_storage.save_file(
                latest_pkg, os.path.join(settings.BASE_DIR, relative_path))

        returned_url = urljoin(get_current_sys_domain(),
                               mobile.latest_version_url)
    elif int(type) == MOBILE_TYPE_APPLE_PHONE:
        if latest_pkg:
            raise BusinessException(IOS_HAS_APK_ERROR)
        relative_path = settings.IOS_DOWNLOAD
        returned_url = relative_path
    else:
        raise BusinessException(UNSUPPORT_TYPE_UPGRADE)

    # 更新当前版本数据库
    mobile.latest_version = latest_version
    mobile.latest_version_url = relative_path
    mobile.latest_version_checksum = checksum
    mobile.version_info = version_info
    mobile.save()

    # 更新历史版本数据库
    MobileHistory.objects.create(type=int(type),
                                 version=latest_version,
                                 version_info=version_info,
                                 url=relative_path)

    return {
        'latest_version': mobile.latest_version,
        'latest_version_url': returned_url
    }
Ejemplo n.º 5
0
def send_star_msg(star, user):
    moment = star.moment
    receiver = '%d,%d,%d' % (moment.account.id, moment.user_type,
                             moment.user_school.id)

    typeuserlike = get_type_user(user.id, user.type, user.school.id)

    head = {
        "account_id": user.id,  # 账号
        "user_type_id": user.type,  # 用户类型
        "school_id": user.school.id,  # 学校
        "username": typeuserlike.full_name,  # 姓名
        "avatar": get_uc_static_file_path(typeuserlike.image_url),  # 头像
        "content": "赞了我",
        "create_time": star.create_time.strftime("%Y-%m-%d %H:%M:%S"),  # 点赞时间
    }

    typeusermoment = get_type_user(moment.account.id, moment.user_type,
                                   moment.user_school.id)

    voice_url = ""
    image_url = ""
    file_url = ""
    video_url = ""
    video_cover_url = ""
    description = ""
    content = ""
    deadline = ""

    momentvoices = MomentAttachVoice.objects.filter(
        moment=moment, is_del=FALSE_INT).order_by('create_time')
    if momentvoices:
        momentvoice = momentvoices.first()
        voice_url = url(get_current_sys_domain(), momentvoice.voice.voice_url)

    if moment.moment_type == MOMENT_TYPE_IMAGE:
        momentattachs = MomentAttachImage.objects.filter(
            moment=moment, is_del=FALSE_INT).order_by('create_time')
        momentattach = momentattachs.first()
        if momentattachs:
            # 如果没有缩略图,表明该原图不需要压缩,则缩略图就是原图,同时原图置空;如果有缩略图,则返回缩略图和原图
            if momentattach.image.image_thumb_url:
                image_url = url(get_current_sys_domain(),
                                momentattach.image.image_thumb_url)
            else:
                image_url = url(get_current_sys_domain(),
                                momentattach.image.image_original_url)
            # image_url = get_moment_file_url(get_current_sys_domain(), momentattach.image.image_thumb_url)
            description = "上传了%d张图片" % momentattachs.count()
        else:
            image_url = ''
            description = "发布了文字动态"
        content = moment.content

    if moment.moment_type == MOMENT_TYPE_VIDEO:
        momentattachs = MomentAttachVideo.objects.filter(
            moment=moment, is_del=FALSE_INT).order_by('create_time')
        momentattach = momentattachs.first()
        if momentattachs:
            video_url = url(get_current_sys_domain(),
                            momentattach.video.video_converted_url)
            video_cover_url = url(get_current_sys_domain(),
                                  momentattach.video.video_snapshot_url)
            description = "上传了视频"
        else:
            video_url = ''
            video_cover_url = ''
            description = "发布了视频动态"
        content = moment.content

    if moment.moment_type == MOMENT_TYPE_FILE:
        momentattachs = MomentAttachFile.objects.filter(
            moment=moment, is_del=FALSE_INT).order_by('create_time')
        momentattach = momentattachs.first()
        if momentattachs:
            file_url = url(get_current_sys_domain(),
                           momentattach.file.file_url)
            description = "上传了%d个文件" % momentattachs.count()
        else:
            file_url = ''
            description = "发布了附件动态"
        content = moment.content

    if moment.moment_type == MOMENT_TYPE_VOTE:
        momentvotes = MomentVote.objects.filter(
            moment=moment, is_del=FALSE_INT).order_by('create_time')
        momentvote = momentvotes.first()
        description = "发布了投票"
        content = momentvote.vote_title
        deadline = "截止%s" % momentvote.vote_deadline.strftime(
            "%Y-%m-%d %H:%M:%S")

    topic = {
        "moment_id": moment.id,  # 圈子ID
        "account_id": moment.account.id,  # 圈子发布者账号
        "user_type_id": moment.user_type,  # 圈子发布者用户类型
        "school_id": moment.user_school.id,  # 圈子发布者学校
        "username": typeusermoment.full_name,  # 圈子发布者姓名
        "avatar": get_uc_static_file_path(typeusermoment.image_url),  # 圈子发布者头像
        "moment_type": moment.moment_type,  # 0、照片,1、视频,2、附件,3、投票
        "voice_url": voice_url,  # 第一个语音地址
        "image_url": image_url,  # 第一张缩略图地址
        "file_url": file_url,  # 第一个文件地址
        "video_url": video_url,  # 视频地址
        "video_cover_url": video_cover_url,  # 视频封面地址
        "description": description,  # 描述
        "content": content,  # 正文,如果是投票则为投票title
        "deadline": deadline,  # 投票截止时间
        "reply": "",  # 回复内容,点赞时此字段为空,由于移动端要求返回去回复时一致,所以才加此字段
        "ref": dict(),  # 回复的评论,点赞时此字段为空,由于移动端要求返回去回复时一致,所以才加此字段
    }
    content = {
        "head": head,
        "topic": topic,
        "description": "%s赞了我" % typeuserlike.full_name,  # 消息列表中使用的描述信息
    }
    send_msg(receiver, MSG_CATEGORY_MOMENT_LIKE, content)
Ejemplo n.º 6
0
def send_reply_msg(user, content, momentreply, premomentreply):
    ref_id = premomentreply.id if premomentreply else None
    moment = momentreply.moment
    # 有人回复时,消息通知被回复主题的发布人
    # 有人回复我的回复时,消息通知被回复人及被回复的主题发布人。
    # 如果用户回复自己评论,则只发送一次
    if ref_id:
        if moment.account.id != premomentreply.account.id or moment.user_type != premomentreply.user_type or moment.user_school.id != premomentreply.user_school.id:
            # 当评论动态的回复时,如果动态是自己发送的,只对前一回复的用户进行消息提醒 ,不对自己进行消息提醒
            if moment.account.id == user.id and moment.user_type == user.type and moment.user_school.id == user.school.id:
                receiver = '%d,%d,%d' % (premomentreply.account.id,
                                         premomentreply.user_type,
                                         premomentreply.user_school.id)
            else:
                receiver = '%d,%d,%d;%d,%d,%d' % (
                    moment.account.id, moment.user_type, moment.user_school.id,
                    premomentreply.account.id, premomentreply.user_type,
                    premomentreply.user_school.id)
        else:
            receiver = '%d,%d,%d' % (moment.account.id, moment.user_type,
                                     moment.user_school.id)
        msg_type = MSG_CATEGORY_MOMENT_REPLY_COMMENT
        typeuserref = get_type_user(premomentreply.account.id,
                                    premomentreply.user_type,
                                    premomentreply.user_school.id)
        ref = {
            "account_id": premomentreply.account.id,
            "user_type_id": premomentreply.user_type,
            "school_id": premomentreply.user_school.id,
            "username": typeuserref.full_name,
            "avatar": get_uc_static_file_path(typeuserref.image_url),
        }
    else:
        # 当直接评论动态,且动态是自己发送的时候,不对自己进行消息提醒
        if moment.account.id == user.id and moment.user_type == user.type and moment.user_school.id == user.school.id:
            return

        receiver = '%d,%d,%d' % (moment.account.id, moment.user_type,
                                 moment.user_school.id)
        msg_type = MSG_CATEGORY_MOMENT_REPLY_TOPIC
        ref = dict()

    typeuserreply = get_type_user(user.id, user.type, user.school.id)

    msgdescription = content + ''
    head = {
        "account_id": user.id,  # 账号
        "user_type_id": user.type,  # 用户类型
        "school_id": user.school.id,  # 学校
        "username": typeuserreply.full_name,  # 姓名
        "avatar": get_uc_static_file_path(typeuserreply.image_url),  # 头像
        "content": content,
        "create_time":
        momentreply.create_time.strftime("%Y-%m-%d %H:%M:%S"),  # 回复时间
    }

    typeusermoment = get_type_user(moment.account.id, moment.user_type,
                                   moment.user_school.id)

    voice_url = image_url = file_url = video_url = video_cover_url = description = content = deadline = ""

    momentvoices = MomentAttachVoice.objects.filter(
        moment=moment, is_del=FALSE_INT).order_by('create_time')
    if momentvoices:
        momentvoice = momentvoices.first()
        voice_url = url(get_current_sys_domain(), momentvoice.voice.voice_url)

    if moment.moment_type == MOMENT_TYPE_IMAGE:
        momentattachs = MomentAttachImage.objects.filter(
            moment=moment, is_del=FALSE_INT).order_by('create_time')
        momentattach = momentattachs.first()
        if momentattachs:
            # 如果没有缩略图,表明该原图不需要压缩,则缩略图就是原图,同时原图置空;如果有缩略图,则返回缩略图和原图
            if momentattach.image.image_thumb_url:
                image_url = url(get_current_sys_domain(),
                                momentattach.image.image_thumb_url)
            else:
                image_url = url(get_current_sys_domain(),
                                momentattach.image.image_original_url)
            # image_url = get_moment_file_url(get_current_sys_domain(), momentattach.image.image_thumb_url)
            description = "上传了%d张图片" % momentattachs.count()
        else:
            image_url = ''
            description = "发布了文字动态"
        content = moment.content

    if moment.moment_type == MOMENT_TYPE_VIDEO:
        momentattachs = MomentAttachVideo.objects.filter(
            moment=moment, is_del=FALSE_INT).order_by('create_time')
        momentattach = momentattachs.first()
        if momentattachs:
            video_url = url(get_current_sys_domain(),
                            momentattach.video.video_converted_url)
            video_cover_url = url(get_current_sys_domain(),
                                  momentattach.video.video_snapshot_url)
            description = "上传了视频"
        else:
            video_url = ''
            video_cover_url = ''
            description = "发布了视频动态"
        content = moment.content

    if moment.moment_type == MOMENT_TYPE_FILE:
        momentattachs = MomentAttachFile.objects.filter(
            moment=moment, is_del=FALSE_INT).order_by('create_time')
        momentattach = momentattachs.first()
        if momentattachs:
            file_url = url(get_current_sys_domain(),
                           momentattach.file.file_url)
            description = "上传了%d个文件" % momentattachs.count()
        else:
            file_url = ''
            description = "发布了附件动态"
        content = moment.content

    if moment.moment_type == MOMENT_TYPE_VOTE:
        momentvotes = MomentVote.objects.filter(
            moment=moment, is_del=FALSE_INT).order_by('create_time')
        momentvote = momentvotes.first()
        description = "发布了投票"
        content = momentvote.vote_title
        deadline = "截止%s" % momentvote.vote_deadline.strftime(
            "%Y-%m-%d %H:%M:%S")

    topic = {
        "moment_id": moment.id,  # 圈子ID
        "account_id": moment.account.id,  # 圈子发布者账号
        "user_type_id": moment.user_type,  # 圈子发布者用户类型
        "school_id": moment.user_school.id,  # 圈子发布者学校
        "username": typeusermoment.full_name,  # 圈子发布者姓名
        "avatar": get_uc_static_file_path(typeusermoment.image_url),  # 圈子发布者头像
        "moment_type": moment.moment_type,  # 0、照片,1、视频,2、附件,3、投票
        "voice_url": voice_url,  # 第一个语音地址
        "image_url": image_url,  # 第一张缩略图地址
        "file_url": file_url,  # 第一个文件地址
        "video_url": video_url,  # 视频地址
        "video_cover_url": video_cover_url,  # 视频封面地址
        "description": description,  # 描述
        "content": content,  # 正文,如果是投票则为投票title
        "deadline": deadline,  # 投票截止时间
        "ref": ref,
    }

    if ref_id:
        topic['reply'] = premomentreply.content
    else:
        topic['reply'] = ""

    content = {
        "head": head,
        "topic": topic,
        "description":
        "%s:%s" % (typeuserreply.full_name, msgdescription),  # 消息列表中使用的描述信息
    }

    status = send_msg(receiver, msg_type, content)
Ejemplo n.º 7
0
def get_onemoment_only_display(momenteach):
    """
        获取单条动态信息(仅用于展示)
    """
    typeuser = get_type_user(momenteach.account.id, momenteach.user_type,
                             momenteach.user_school_id)
    moment = dict()
    moment["moment_id"] = momenteach.id
    moment["username"] = typeuser.full_name
    moment["account_id"] = momenteach.account.id
    moment["user_type_id"] = momenteach.user_type
    moment["user_type"] = USER_TYPE_MAP[momenteach.user_type]
    moment["moment_type"] = momenteach.moment_type
    moment["school_id"] = momenteach.user_school_id
    moment["avatar"] = get_uc_static_file_path(typeuser.image_url)
    moment["sex"] = typeuser.sex

    class_name = ''
    class_list = get_classes_by_turple(momenteach.account.id,
                                       momenteach.user_type,
                                       momenteach.user_school_id)
    if class_list and len(class_list) > 0:
        class_name = class_list[0]['class_name']
    moment["class"] = class_name

    moment["create_time"] = datetime2str(
        momenteach.create_time)  # .strftime("%Y-%m-%d %H:%I:%S")
    moment["create_time_perform"] = get_time_perform(
        datetime2str(momenteach.create_time))  # .strftime("%Y-%m-%d %H:%I:%S")
    moment["content"] = momenteach.content
    moment["read_count"] = momenteach.read_count
    moment["like_count"] = momenteach.like_count

    moment["reply_count"] = momenteach.reply_count
    moment["has_voice"] = momenteach.has_voice
    moment["has_image"] = momenteach.has_image
    moment["has_video"] = momenteach.has_video
    moment["has_file"] = momenteach.has_file
    if momenteach.append_attr:
        moment["append_attr"] = momenteach.append_attr
    else:
        moment["append_attr"] = ''

    # 获取语音列表
    voice_list = []
    moment_voice_list = MomentAttachVoice.objects.filter(
        moment=momenteach, is_del=FALSE_INT).order_by('create_time')
    for moment_voice in moment_voice_list:
        voice = {
            "voice_id":
            moment_voice.id,
            "voice_name":
            moment_voice.voice.voice_name,
            "voice_size":
            moment_voice.voice.voice_size,
            "voice_duration":
            moment_voice.voice.voice_duration,
            "voice_type":
            moment_voice.voice.voice_type,
            "voice_url":
            url(get_current_sys_domain(), moment_voice.voice.voice_url),
            "voice_converted_url":
            url(get_current_sys_domain(),
                moment_voice.voice.voice_converted_url),
            "voice_converted_status":
            str(moment_voice.voice.voice_converted_status)
        }
        voice_list.append(voice)
    moment["voices"] = voice_list

    # 获取图片列表
    image_list = []
    moment_image_list = MomentAttachImage.objects.filter(
        moment=momenteach, is_del=FALSE_INT).order_by('create_time')
    for moment_image in moment_image_list:
        # 如果没有缩略图,表明该原图不需要压缩,则缩略图就是原图,同时原图置空;如果有缩略图,则返回缩略图和原图
        if moment_image.image.image_thumb_url:
            image_thumb_url = url(get_current_sys_domain(),
                                  moment_image.image.image_thumb_url)
            image_original_url = url(get_current_sys_domain(),
                                     moment_image.image.image_original_url)
        else:
            image_thumb_url = url(get_current_sys_domain(),
                                  moment_image.image.image_original_url)
            image_original_url = url(get_current_sys_domain(),
                                     moment_image.image.image_original_url)
        image_crop_url = url(get_current_sys_domain(),
                             moment_image.image.image_crop_url)
        image = {
            "image_id": moment_image.id,
            "image_name": moment_image.image.image_name,
            "image_size": moment_image.image.image_size,
            "image_square": moment_image.image.image_square,
            "image_original_url": image_original_url,
            "image_thumb_url": image_thumb_url,
            "image_crop_url": image_crop_url,
            "image_type": moment_image.image.image_type,
            "image_width": moment_image.image.image_square.split(',')[0],
            "image_hight": moment_image.image.image_square.split(',')[1]
        }
        image_list.append(image)
    moment["images"] = image_list

    # 获取视频列表
    video_list = []
    moment_video_list = MomentAttachVideo.objects.filter(
        moment=momenteach, is_del=FALSE_INT).order_by('create_time')
    for moment_video in moment_video_list:
        video = {
            "video_id":
            moment_video.id,
            "video_name":
            moment_video.video.video_name,
            "video_size":
            moment_video.video.video_size,
            "video_duration":
            moment_video.video.video_duration,
            "video_url":
            url(get_current_sys_domain(), moment_video.video.video_url),
            "video_type":
            moment_video.video.video_type,
            "video_converted_url":
            url(get_current_sys_domain(),
                moment_video.video.video_converted_url),
            "video_converted_status":
            moment_video.video.video_converted_status,
            "video_cover_url":
            url(get_current_sys_domain(),
                moment_video.video.video_snapshot_url),
            "video_square":
            moment_video.video.video_square,
            "video_width":
            moment_video.video.video_square.split(',')[0],
            "video_hight":
            moment_video.video.video_square.split(',')[1]
        }
        video_list.append(video)
    moment["videos"] = video_list

    # 获取文件列表
    file_list = []
    moment_file_list = MomentAttachFile.objects.filter(
        moment=momenteach, is_del=FALSE_INT).order_by('create_time')
    for moment_file in moment_file_list:
        myfile = {
            "file_id":
            moment_file.id,
            "file_name":
            moment_file.file.file_name,
            "file_size":
            moment_file.file.file_size,
            "file_url_with_fname":
            gen_url_with_fname(
                url(get_current_sys_domain(), moment_file.file.file_url),
                moment_file.file.file_name),
            "file_url":
            url(get_current_sys_domain(), moment_file.file.file_url),
            "file_type":
            moment_file.file.file_type
        }
        file_list.append(myfile)
    moment["files"] = file_list

    # 获取投票
    vote = dict()
    rs_votes = MomentVote.objects.filter(
        moment=momenteach,
        is_del=FALSE_INT).select_related().order_by('create_time')

    if rs_votes:
        rs_vote = rs_votes.first()
        if datetime.now() > rs_vote.vote_deadline:
            moment["is_voteexpire"] = TRUE_STR
        else:
            moment["is_voteexpire"] = FALSE_STR
        vote["vote_title"] = rs_vote.vote_title
        vote["vote_num"] = rs_vote.vote_num
        vote["vote_deadline"] = datetime2str(rs_vote.vote_deadline)
        vote["vote_statistics"] = rs_vote.vote_statistics
        vote_items = []
        vote_items_list = rs_vote.items.filter(
            is_del=FALSE_INT).order_by('sort')
        for vote_item_each in vote_items_list:
            vote_item = {
                "vote_item_id": vote_item_each.id,
                "branch": vote_item_each.branch,
                "count": vote_item_each.count
            }
            vote_items.append(vote_item)
        vote["vote_items"] = vote_items
    moment["vote"] = vote

    moment["like"] = []

    replys = get_momentreply(momenteach, MOMENT_FROM_LIST)
    moment["reply"] = replys

    return moment
Ejemplo n.º 8
0
def get_onemoment(momenteach, user, reqfrom):
    """
    获取单条动态信息
    """
    start_time = datetime.now()

    typeuser = get_type_user(momenteach.account.id, momenteach.user_type, momenteach.user_school_id)

    moment = dict()
    moment["moment_id"] = momenteach.id
    moment["username"] = typeuser.full_name if typeuser else u'该用户不存在或已删除'
    moment["account_id"] = momenteach.account.id
    moment["user_type_id"] = momenteach.user_type
    moment["user_type"] = USER_TYPE_MAP[momenteach.user_type]
    moment["moment_type"] = momenteach.moment_type
    moment["school_id"] = momenteach.user_school_id
    moment["avatar"] = get_uc_static_file_path(typeuser.image_url) if typeuser else ''
    moment["sex"] = typeuser.sex if typeuser else ''

    class_name = ''
    class_list = get_classes_by_turple(momenteach.account.id, momenteach.user_type, momenteach.user_school_id)
    if class_list and len(class_list) > 0:
        class_name = class_list[0]['class_name']
    moment["class"] = class_name

    moment["create_time"] = datetime2str(momenteach.create_time)  # .strftime("%Y-%m-%d %H:%I:%S")
    moment["create_time_perform"] = get_time_perform(datetime2str(momenteach.create_time))  # .strftime("%Y-%m-%d %H:%I:%S")
    moment["content"] = momenteach.content
    moment["read_count"] = momenteach.read_count
    moment["like_count"] = momenteach.like_count

    # 检查自己是否点赞
    moment["is_like"] = TRUE_STR \
            if MomentLike.objects.filter(
                    moment=momenteach, account=user, user_type=user.type, user_school=user.school) \
                .exists()  \
            else FALSE_STR

    moment["reply_count"] = momenteach.reply_count
    moment["has_voice"] = momenteach.has_voice
    moment["has_image"] = momenteach.has_image
    moment["has_video"] = momenteach.has_video
    moment["has_file"] = momenteach.has_file
    moment["append_attr"] = ''

    # 获取语音列表
    voice_list = []
    moment_voice_list = MomentAttachVoice.objects.filter(moment=momenteach, is_del=FALSE_INT).order_by('create_time')
    for moment_voice in moment_voice_list:
        voice = {"voice_id": moment_voice.id, "voice_name": moment_voice.voice.voice_name,
                 "voice_size": moment_voice.voice.voice_size, "voice_duration": moment_voice.voice.voice_duration,
                 "voice_type": moment_voice.voice.voice_type, "voice_url": url(get_current_sys_domain(), moment_voice.voice.voice_url),
                 "voice_converted_url": url(get_current_sys_domain(), moment_voice.voice.voice_converted_url),
                 "voice_converted_status": str(moment_voice.voice.voice_converted_status)}
        voice_list.append(voice)
    moment["voices"] = voice_list

    # 获取图片列表
    image_list = []
    moment_image_list = MomentAttachImage.objects.filter(moment=momenteach, is_del=FALSE_INT).order_by('create_time')
    for moment_image in moment_image_list:
        # 如果没有缩略图,表明该原图不需要压缩,则缩略图就是原图,同时原图置空;如果有缩略图,则返回缩略图和原图
        if moment_image.image.image_thumb_url:
            image_thumb_url = url(get_current_sys_domain(), moment_image.image.image_thumb_url)
            image_original_url = url(get_current_sys_domain(), moment_image.image.image_original_url)
        else:
            image_thumb_url = url(get_current_sys_domain(), moment_image.image.image_original_url)
            image_original_url = url(get_current_sys_domain(), moment_image.image.image_original_url)
        image_crop_url = url(get_current_sys_domain(), moment_image.image.image_crop_url)
        image = {"image_id": moment_image.id, "image_name": moment_image.image.image_name,
                 "image_size": moment_image.image.image_size, "image_square": moment_image.image.image_square,
                 "image_original_url": image_original_url,
                 "image_thumb_url": image_thumb_url,
                 "image_crop_url": image_crop_url,
                 "image_type": moment_image.image.image_type,
                 "image_width": moment_image.image.image_square.split(',')[0],
                 "image_hight": moment_image.image.image_square.split(',')[1]}
        image_list.append(image)
    moment["images"] = image_list

    # 获取视频列表
    video_list = []
    moment_video_list = MomentAttachVideo.objects.filter(moment=momenteach, is_del=FALSE_INT).order_by('create_time')
    for moment_video in moment_video_list:
        video = {"video_id": moment_video.id, "video_name": moment_video.video.video_name,
                 "video_size": moment_video.video.video_size, "video_duration": moment_video.video.video_duration,
                 "video_url": url(get_current_sys_domain(), moment_video.video.video_url), "video_type": moment_video.video.video_type,
                 "video_converted_url": url(get_current_sys_domain(), moment_video.video.video_converted_url),
                 "video_converted_status": moment_video.video.video_converted_status,
                 "video_cover_url": url(get_current_sys_domain(), moment_video.video.video_snapshot_url),
                 "video_square": moment_video.video.video_square,
                 "video_width": moment_video.video.video_square.split(',')[0],
                 "video_hight": moment_video.video.video_square.split(',')[1]}
        video_list.append(video)
    moment["videos"] = video_list

    # 获取文件列表
    file_list = []
    moment_file_list = MomentAttachFile.objects.filter(moment=momenteach, is_del=FALSE_INT).order_by('create_time')
    for moment_file in moment_file_list:
        myfile = {"file_id": moment_file.id, "file_name": moment_file.file.file_name,
                  "file_size": moment_file.file.file_size,
                  "file_url_with_fname": gen_url_with_fname(url(get_current_sys_domain(), moment_file.file.file_url), moment_file.file.file_name),
                  "file_url": url(get_current_sys_domain(), moment_file.file.file_url),
                  "file_type": moment_file.file.file_type}
        file_list.append(myfile)
    moment["files"] = file_list

    # 获取投票
    vote = dict()
    rs_votes = MomentVote.objects.filter(moment=momenteach, is_del=FALSE_INT).select_related().order_by('create_time')
    # 检查自己是否投票
    momentvoteusers = MomentVoteUser.objects.filter(vote_item__vote__moment=momenteach, account=user, user_type=user.type, user_school=user.school, is_del=FALSE_INT)
    if momentvoteusers:
        moment["is_vote"] = TRUE_STR
        momentvotechoice = momentvoteusers.first().vote_item
    else:
        moment["is_vote"] = FALSE_STR
        momentvotechoice = MomentVoteItem()
    if rs_votes:
        rs_vote = rs_votes.first()
        if datetime.now() > rs_vote.vote_deadline:
            moment["is_voteexpire"] = TRUE_STR
        else:
            moment["is_voteexpire"] = FALSE_STR
        vote["vote_title"] = rs_vote.vote_title
        vote["vote_num"] = rs_vote.vote_num
        vote["vote_deadline"] = datetime2str(rs_vote.vote_deadline)
        vote["vote_statistics"] = rs_vote.vote_statistics
        vote_items = []
        # vote_items_list = MomentVoteItem.objects.filter(vote=rs_vote, is_del=FALSE_INT)
        vote_items_list = rs_vote.items.filter(is_del=FALSE_INT).order_by('sort')
        for vote_item_each in vote_items_list:
            if momentvotechoice == vote_item_each:
                isvote = TRUE_STR
            else:
                isvote = FALSE_STR
            vote_item = {"vote_item_id": vote_item_each.id, "branch": vote_item_each.branch, "count": vote_item_each.count, "isvote": isvote}
            vote_items.append(vote_item)
        vote["vote_items"] = vote_items
    moment["vote"] = vote

    # 评价类互动
    evaluate = dict()
    moment["evaluate"] = evaluate
    if momenteach.moment_type == MOMENT_TYPE_EVALUATE:
        evaluate_obj = MomentEvaluate.objects.filter(moment=momenteach).first()
        evaluate['type'] = str(evaluate_obj.type)
        evaluate['is_visible_for_parent_related'] = str(evaluate_obj.is_visible_for_parent_related)
        moment_evaluate_stu_qs = MomentEvaluateStudent.objects.filter(moment_evaluate=evaluate_obj, moment=momenteach)
        student_name_list = [each_evaluate_stu.student.full_name for each_evaluate_stu in moment_evaluate_stu_qs]
        evaluate['students'] = ','.join(student_name_list)

    # 请假类互动
    dayoff = dict()
    moment["dayoff"] = dayoff
    if momenteach.moment_type == MOMENT_TYPE_DAYOFF:
        dayoff_obj = MomentDayoff.objects.filter(moment=momenteach).first()
        dayoff['is_visible_for_teacher'] = str(dayoff_obj.is_visible_for_teacher)

    # 获取点赞列表,查询点动态列表时,不显示点赞列表,查询动态详情时,才显示。
    likes = []
    if reqfrom == MOMENT_FROM_DETAIL:
        rs_like = MomentLike.objects.filter(moment=momenteach, is_del=FALSE_INT).order_by('create_time')
        for rs_like_each in rs_like:
            typeuserlike = get_type_user(rs_like_each.account.id, rs_like_each.user_type, rs_like_each.user_school.id)
            like = {
                "account_id": rs_like_each.account.id,
                "user_type_id": rs_like_each.user_type,
                "school_id": rs_like_each.user_school.id,
                "username": typeuserlike.full_name,
            }
            likes.append(like)
    moment["like"] = likes

    # 获取回复列表,如果是查询列表,则显示前3条,如果是查询详情则全部显示。
    moment["reply"] = get_momentreply(momenteach, reqfrom)

    end_time = datetime.now()
    #logger.debug('Function Time  %s' % (str(end_time - start_time)))

    return moment