def fieldObjectAddTarget(request): '''add the target object to the list of coordinates for that target''' try: targ = Target.objects.get(pk=request.POST['target']) fobj = FieldObject(target=targ, ra=targ.ra, dec=targ.dec,isTarget=True) fobj.save() return okJSONResponse(FieldObject2dict(fobj)) except Exception as e: logger.debug(e) return errorJSONResponse("targetID must be supplied and a valid target")
def uploadCoordFile(request,targetID): '''upload a coordinate file for a target''' try: f = request.FILES['coords'] result = [] with transaction.commit_on_success(): for ra,dec in parseCoords(f): logger.info("Adding object at {0} {1}".format(ra,dec)) obj = FieldObject(target_id=targetID,ra=ra,dec=dec,isTarget=False) obj.save() result.append(FieldObject2dict(obj)) return okJSONResponse(result) except Exception as ex: return errorJSONResponse(str(ex))