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)