Example #1
0
def entity_list(request):
    _start_at = datetime.datetime.now()
    if request.method == "GET":
        _session = request.GET.get('session', None)
        if _session != None:
            _request_user_id = Session_Key.objects.get_user_id(_session)
        else:
            _request_user_id = None
        _timestamp = request.GET.get('timestamp', None)
        if _timestamp != None:
            _timestamp = datetime.datetime.fromtimestamp(float(_timestamp))

        _sort_by = request.GET.get('sort', 'novus_time')
        _reverse = request.GET.get('reverse', '0')
        if _reverse == '0':
            _reverse = False
        else:
            _reverse = True
        _offset = int(request.GET.get('offset', '0'))
        _count = int(request.GET.get('count', '30'))
        _root_old_cat_id = request.GET.get('rcat', None)
        if _root_old_cat_id != None:
            _root_old_cat_id = int(_root_old_cat_id)

        _entity_id_list = MobileEntity.find(
            root_old_category_id=_root_old_cat_id,
            timestamp=_timestamp,
            offset=_offset,
            count=_count,
            sort_by=_sort_by,
            reverse=_reverse,
            status='novus')

        _rslt = []
        for _entity_id in _entity_id_list:
            try:
                _entity = MobileEntity(_entity_id)
                _entity_context = _entity.read(_request_user_id)
                _entity_context['updated_time'] = _entity_context['novus_time']
                _rslt.append(_entity_context)
            except Exception, e:
                pass

        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration=_duration.seconds * 1000000 + _duration.microseconds,
            view='NOVUS',
            request=request.REQUEST,
            ip=get_client_ip(request),
            log_time=datetime.datetime.now(),
            request_user_id=_request_user_id,
            appendix={'result_entities': _entity_id_list},
        )

        return SuccessJsonResponse(_rslt)
Example #2
0
def category_entity(request, category_id):
    _start_at = datetime.datetime.now()
    if request.method == "GET":
        _session = request.GET.get('session', None)
        if _session != None:
            _request_user_id = Session_Key.objects.get_user_id(_session)
        else:
            _request_user_id = None
        _sort_by = request.GET.get('sort', None)
        _reverse = request.GET.get('reverse', '0')
        if _reverse == '0':
            _reverse = False
        else:
            _reverse = True
        _offset = int(request.GET.get('offset', '0'))
        _count = int(request.GET.get('count', '30'))

        _entity_id_list = MobileEntity.find(category_id=category_id,
                                            status='normal',
                                            sort_by=_sort_by,
                                            offset=_offset,
                                            count=_count,
                                            reverse=_reverse)
        _rslt = []
        for _entity_id in _entity_id_list:
            _entity = MobileEntity(_entity_id)
            _rslt.append(_entity.read(_request_user_id))

        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration=_duration.seconds * 1000000 + _duration.microseconds,
            view='CATEGORY_ENTITY',
            request=request.REQUEST,
            ip=get_client_ip(request),
            log_time=datetime.datetime.now(),
            request_user_id=_request_user_id,
            appendix={
                'neo_category_id': int(category_id),
                'result_entities': _entity_id_list
            },
        )

        return SuccessJsonResponse(_rslt)