def add(request): '''Add new link to a specific target The target should be a valid model within TCMS, which are documented in ``LINKREF_TARGET``. Incoming request should be a POST request, and contains following arguments: - target: To which the new link will link to. The avialable target names are documented in the ``LINKREF_TARGET``. - target_id: the ID used to construct the concrete target instance, to which the new link will be linked. - name: a short description to this new link, and accept 64 characters at most. - url: the actual URL. ''' form = AddLinkReferenceForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] url = form.cleaned_data['url'] target_id = form.cleaned_data['target_id'] model_class = form.cleaned_data['target'] model_instance = model_class.objects.get(pk=target_id) create_link(name=name, url=url, link_to=model_instance) jd = json.dumps({ 'status': 0, 'message': '', 'data': { 'name': name, 'url': url } }) return HttpJSONResponse(content=jd) else: jd = json.dumps({'status': 1, 'message': form.errors.as_text()}) return HttpJSONResponseBadRequest(content=jd)
def add(request): '''Add new link to a specific target The target should be a valid model within TCMS, which are documented in ``LINKREF_TARGET``. Incoming request should be a POST request, and contains following arguments: - target: To which the new link will link to. The avialable target names are documented in the ``LINKREF_TARGET``. - target_id: the ID used to construct the concrete target instance, to which the new link will be linked. - name: a short description to this new link, and accept 64 characters at most. - url: the actual URL. ''' form = AddLinkReferenceForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] url = form.cleaned_data['url'] target_id = form.cleaned_data['target_id'] model_class = form.cleaned_data['target'] model_instance = model_class.objects.get(pk=target_id) create_link(name=name, url=url, link_to=model_instance) jd = json.dumps( {'rc': 0, 'response': 'ok', 'data': {'name': name, 'url': url}}) return HttpJSONResponse(content=jd) else: jd = json.dumps( {'rc': 1, 'response': form.errors.as_text()}) return HttpJSONResponseBadRequest(content=jd)