예제 #1
0
def export(request):
    output = io.StringIO()

    data = {"Entity": [], "EntityAttr": []}

    entities = get_permitted_objects(request.user, Entity, ACLType.Readable)
    for entity in entities:
        data["Entity"].append(
            {
                "created_user": entity.created_user.username,
                "id": entity.id,
                "name": entity.name,
                "note": entity.note,
                "status": entity.status,
            }
        )

    attrs = get_permitted_objects(request.user, EntityAttr, ACLType.Readable)
    for attr in attrs:
        data["EntityAttr"].append(
            {
                "created_user": attr.created_user.username,
                "entity": attr.parent_entity.name,
                "id": attr.id,
                "is_mandatory": attr.is_mandatory,
                "name": attr.name,
                "refer": ",".join(
                    list(map(lambda x: x.name, attr.referral.filter(is_active=True)))
                ),
                "type": attr.type,
            }
        )

    output.write(yaml.dump(data, default_flow_style=False, allow_unicode=True))
    return get_download_response(output, "entity.yaml")
예제 #2
0
def download(request, job_id):
    job = Job.objects.filter(id=job_id).first()
    if not job:
        return HttpResponse("Invalid Job-ID is specified", status=400)

    if job.user.id != request.user.id:
        return HttpResponse("Target Job is executed by other people", status=400)

    export_operations = [
        JobOperation.EXPORT_ENTRY.value,
        JobOperation.EXPORT_SEARCH_RESULT.value,
    ]
    if job.operation not in export_operations:
        return HttpResponse("Target Job has no value to return", status=400)

    # get value associated this Job from cache
    io_stream = io.StringIO()
    try:
        io_stream.write(job.get_cache())
    except OSError as e:
        # errno.ENOENT is the errno of FileNotFoundError
        if e.errno == errno.ENOENT:
            return HttpResponse("This result is no longer available", status=400)

    return get_download_response(io_stream, job.text)
예제 #3
0
def export(request):
    output = io.StringIO()

    data = {
        "Group": [],
        "User": [],
    }

    for group in Group.objects.filter(is_active=True):
        data["Group"].append(
            {
                "id": group.id,
                "name": group.name,
            }
        )

    for user in User.objects.filter(is_active=True):
        data["User"].append(
            {
                "email": user.email,
                "groups": ",".join(
                    list(map(lambda x: x.name, user.groups.filter(group__is_active=True)))
                ),
                "id": user.id,
                "username": user.username,
            }
        )

    output.write(yaml.dump(data, default_flow_style=False, allow_unicode=True))
    return get_download_response(output, "user_group.yaml")