Beispiel #1
0
def get(request):
    '''Get links of specific instance of content type

    - target: The model name of the instance being searched
    - target_id: The ID of the instance

    Only accept GET request from client.
    '''

    form = BasicValidationForm(request.GET)

    if form.is_valid():
        model_class = form.clean_data['target']
        target_id = form.clean_data['target_id']

        try:
            model_instance = model_class.objects.get(pk=target_id)
            links = LinkReference.get_from(model_instance)
        except Exception, err:
            jd = json.dumps({'status': 1, 'message': str(err)})
            return HttpJSONResponseServerError(content=jd)

        jd = []
        for link in links:
            jd.append({'name': link.name, 'url': link.url})
        jd = json.dumps(jd)

        return HttpJSONResponse(content=jd)
Beispiel #2
0
def get(request):
    '''Get links of specific instance of content type

    - target: The model name of the instance being searched
    - target_id: The ID of the instance

    Only accept GET request from client.
    '''

    form = BasicValidationForm(request.GET)

    if form.is_valid():
        model_class = form.clean_data['target']
        target_id = form.clean_data['target_id']

        try:
            model_instance = model_class.objects.get(pk=target_id)
            links = LinkReference.get_from(model_instance)
        except Exception, err:
            jd = json.dumps({'rc': 1, 'response': str(err)})
            return HttpJSONResponseServerError(content=jd)

        jd = []
        for link in links:
            jd.append({'name': link.name, 'url': link.url})
        jd = json.dumps(jd)

        return HttpJSONResponse(content=jd)
Beispiel #3
0
        jd = json.dumps({'status': 1, 'message': form.errors.as_text()})
        return HttpJSONResponseBadRequest(content=jd)


@user_passes_test(lambda u: u.has_perm('testruns.change_testcaserun'))
@require_GET
def remove(request, link_id):
    ''' Remove a specific link with ID ``link_id`` '''

    from django.forms import IntegerField
    from django.forms import ValidationError

    field = IntegerField(min_value=1)
    try:
        value = field.clean(link_id)
    except ValidationError, err:
        jd = json.dumps({'status': 1, 'messages': '\n'.join(err.messages)})
        return HttpJSONResponseBadRequest(content=jd)

    try:
        LinkReference.unlink(link_id)
    except Exception, err:
        jd = json.dumps({'status': 1, 'messages': str(err)})
        return HttpJSONResponseBadRequest(content=jd)

    return HttpJSONResponse(
        content=json.dumps({
            'status': 0,
            'messages': 'Link has been removed successfully.'
        }))
Beispiel #4
0
        jd = json.dumps(
            {'rc': 1, 'response': form.errors.as_text()})
        return HttpJSONResponseBadRequest(content=jd)


@user_passes_test(lambda u: u.has_perm('testruns.change_testcaserun'))
@require_GET
def remove(request, link_id):
    ''' Remove a specific link with ID ``link_id`` '''

    from django.forms import IntegerField
    from django.forms import ValidationError

    field = IntegerField(min_value=1)
    try:
        value = field.clean(link_id)
    except ValidationError, err:
        jd = json.dumps({'rc': 1, 'response': '\n'.join(err.messages)})
        return HttpJSONResponseBadRequest(content=jd)

    try:
        LinkReference.unlink(value)
    except Exception, err:
        jd = json.dumps({'rc': 1, 'response': str(err)})
        return HttpJSONResponseBadRequest(content=jd)

    return HttpJSONResponse(
        content=json.dumps(
            {'rc': 0,
             'response': 'Link has been removed successfully.'}))
Beispiel #5
0
        jd = json.dumps({'rc': 1, 'response': form.errors.as_text()})
        return HttpJSONResponseBadRequest(content=jd)


@user_passes_test(lambda u: u.has_perm('testruns.change_testcaserun'))
@require_GET
def remove(request, link_id):
    ''' Remove a specific link with ID ``link_id`` '''

    from django.forms import IntegerField
    from django.forms import ValidationError

    field = IntegerField(min_value=1)
    try:
        value = field.clean(link_id)
    except ValidationError, err:
        jd = json.dumps({'rc': 1, 'response': '\n'.join(err.messages)})
        return HttpJSONResponseBadRequest(content=jd)

    try:
        LinkReference.unlink(value)
    except Exception, err:
        jd = json.dumps({'rc': 1, 'response': str(err)})
        return HttpJSONResponseBadRequest(content=jd)

    return HttpJSONResponse(
        content=json.dumps({
            'rc': 0,
            'response': 'Link has been removed successfully.'
        }))
Beispiel #6
0
    else:
        jd = json.dumps(
            { 'status': 1, 'message': form.errors.as_text() })
        return HttpJSONResponseBadRequest(content=jd)

@user_passes_test(lambda u: u.has_perm('testruns.change_testcaserun'))
@require_GET
def remove(request, link_id):
    ''' Remove a specific link with ID ``link_id`` '''

    from django.forms import IntegerField
    from django.forms import ValidationError

    field = IntegerField(min_value=1)
    try:
        value = field.clean(link_id)
    except ValidationError, err:
        jd = json.dumps({ 'status': 1, 'messages': '\n'.join(err.messages) })
        return HttpJSONResponseBadRequest(content=jd)

    try:
        LinkReference.unlink(link_id)
    except Exception, err:
        jd = json.dumps({ 'status': 1, 'messages': str(err) })
        return HttpJSONResponseBadRequest(content=jd)

    return HttpJSONResponse(
        content=json.dumps(
            { 'status': 0,
              'messages': 'Link has been removed successfully.' }))