Exemple #1
0
def get_entries(request, entity_ids):
    total_entries = []

    # parse parameters
    is_active = request.GET.get('is_active', True)
    keyword = request.GET.get('keyword')
    if keyword:
        query_name_regex = Q(name__iregex=prepend_escape_character(
            CONFIG.ESCAPE_CHARACTERS_ENTRY_LIST, keyword))
    else:
        query_name_regex = Q()

    for entity_id in [
            x for x in entity_ids.split(',')
            if x and Entity.objects.filter(id=x, is_active=True).exists()
    ]:
        query = Q(Q(schema__id=entity_id, is_active=is_active),
                  query_name_regex)

        total_entries += Entry.objects.order_by('-updated_time').filter(query)
        if (len(total_entries) > CONFIG.MAX_LIST_ENTRIES):
            break

    if (len(total_entries) > CONFIG.MAX_LIST_ENTRIES):
        total_entries = total_entries[0:CONFIG.MAX_LIST_ENTRIES]

    # serialize data for each entries to convert json format
    entries_data = [{
        'id': x.id,
        'name': x.name,
        'status': x.status,
    } for x in total_entries]

    # return entries as JSON
    return JsonResponse({'results': entries_data})
Exemple #2
0
def restore(request, entity_id):
    user = User.objects.get(id=request.user.id)
    entity, error = get_object_with_check_permission(user, Entity, entity_id, ACLType.Full)
    if error:
        return error

    page = request.GET.get('page', 1)
    keyword = request.GET.get('keyword', None)

    # get all deleted entries that correspond to the entity, the specififcation of
    # 'status=0' is necessary to prevent getting entries that were under processing.
    if keyword:
        name_pattern = prepend_escape_character(CONFIG.ESCAPE_CHARACTERS_ENTRY_LIST, keyword)
        entries = Entry.objects.filter(schema=entity, status=0, is_active=False,
                                       name__iregex=name_pattern).order_by('-updated_time')
    else:
        entries = Entry.objects.filter(schema=entity, status=0,
                                       is_active=False).order_by('-updated_time')

    p = Paginator(entries, CONFIG.MAX_LIST_ENTRIES)
    try:
        page_obj = p.page(page)
    except PageNotAnInteger:
        return HttpResponse('Invalid page number. It must be unsigned integer', status=400)
    except EmptyPage:
        return HttpResponse('Invalid page number. The page doesn\'t have anything', status=400)

    return render(request, 'list_deleted_entry.html', {
        'entity': entity,
        'keyword': keyword,
        'page_obj': page_obj,
    })
Exemple #3
0
def index(request, entity_id):
    entity, error = get_obj_with_check_perm(request.user, Entity, entity_id,
                                            ACLType.Readable)
    if error:
        return error

    page = request.GET.get("page", 1)
    keyword = request.GET.get("keyword", None)

    if custom_view.is_custom("list_entry_without_context", entity.name):
        # show custom view without context
        resp = custom_view.call_custom("list_entry_without_context",
                                       entity.name, request, entity)
        if resp:
            return resp

    if keyword:
        name_pattern = prepend_escape_character(
            CONFIG.ESCAPE_CHARACTERS_ENTRY_LIST, keyword)
        entries = Entry.objects.order_by("name").filter(
            schema=entity, is_active=True, name__iregex=name_pattern)
    else:
        entries = Entry.objects.order_by("name").filter(schema=entity,
                                                        is_active=True)

    p = Paginator(entries, CONFIG.MAX_LIST_ENTRIES)
    try:
        page_obj = p.page(page)
    except PageNotAnInteger:
        return HttpResponse("Invalid page number. It must be unsigned integer",
                            status=400)
    except EmptyPage:
        return HttpResponse(
            "Invalid page number. The page doesn't have anything", status=400)

    context = {
        "entity": entity,
        "keyword": keyword,
        "page_obj": page_obj,
    }

    if custom_view.is_custom("list_entry", entity.name):
        # list custom view
        return custom_view.call_custom("list_entry", entity.name, request,
                                       entity, context)
    else:
        # list ordinal view
        return render(request, "list_entry.html", context)
Exemple #4
0
def index(request, entity_id):
    page = request.GET.get('page', 1)
    keyword = request.GET.get('keyword', None)

    if not Entity.objects.filter(id=entity_id).exists():
        return HttpResponse('Failed to get entity of specified id', status=400)

    entity = Entity.objects.get(id=entity_id)
    if custom_view.is_custom("list_entry_without_context", entity.name):
        # show custom view without context
        resp = custom_view.call_custom("list_entry_without_context",
                                       entity.name, request, entity)
        if resp:
            return resp

    if keyword:
        name_pattern = prepend_escape_character(
            CONFIG.ESCAPE_CHARACTERS_ENTRY_LIST, keyword)
        entries = Entry.objects.order_by('name').filter(
            schema=entity, is_active=True, name__iregex=name_pattern)
    else:
        entries = Entry.objects.order_by('name').filter(schema=entity,
                                                        is_active=True)

    p = Paginator(entries, CONFIG.MAX_LIST_ENTRIES)
    try:
        page_obj = p.page(page)
    except PageNotAnInteger:
        return HttpResponse('Invalid page number. It must be unsigned integer',
                            status=400)
    except EmptyPage:
        return HttpResponse(
            'Invalid page number. The page doesn\'t have anything', status=400)

    context = {
        'entity': entity,
        'keyword': keyword,
        'page_obj': page_obj,
    }

    if custom_view.is_custom("list_entry", entity.name):
        # list custom view
        return custom_view.call_custom("list_entry", entity.name, request,
                                       entity, context)
    else:
        # list ordinal view
        return render(request, 'list_entry.html', context)