golf/views/view_import.py
def courses(request):
    """
    Update function to import courses from uploaded json file
    TODO: json validation, try catch
    url: '/golf/importcourses/'
    """
    resObject = {}
    for f in request.FILES:
        if (request.FILES[f].size < 10000):
            reqFile = request.FILES[f].read().decode('utf-8')
            reqObject = json.loads(reqFile)
            for course in serializers.deserialize('json', json.dumps([reqObject['course']])):
                course.save()
            for hole in serializers.deserialize('json', json.dumps(reqObject['holes'])):
                hole.save()
            for courseTee in serializers.deserialize('json', json.dumps(reqObject['courseTees'])):
                courseTee.save()
            for tee in reqObject['tees']:
                ct = CourseTee.objects.get(name=tee['course_tee__name'], course__name=reqObject['course']['fields']['name'])
                h = Hole.objects.get(number=tee['hole__number'], course__name=reqObject['course']['fields']['name'])
                t = Tee.objects.get_or_create(course_tee=ct, hole=h, yardage=tee['yardage'], handicap=tee['handicap'], par=tee['par'])

    return JsonResponse({'data':'success'})

    Update function to import courses from uploaded json file
    TODO: json validation, try catch
    url: '/golf/importcourses/'
    
Update function to import courses from uploaded json file
TODO: json validation, try catch
url: '/golf/importcourses/'
Update function to import courses from uploaded json file TODO : json validation try catch url : ' / golf / importcourses / '
def courses(request):
    resObject = {}
    for f in request.FILES:
        if (request.FILES[f].size < 10000):
            reqFile = request.FILES[f].read().decode('utf-8')
            reqObject = json.loads(reqFile)
            for course in serializers.deserialize('json', json.dumps([reqObject['course']])):
                course.save()
            for hole in serializers.deserialize('json', json.dumps(reqObject['holes'])):
                hole.save()
            for courseTee in serializers.deserialize('json', json.dumps(reqObject['courseTees'])):
                courseTee.save()
            for tee in reqObject['tees']:
                ct = CourseTee.objects.get(name=tee['course_tee__name'], course__name=reqObject['course']['fields']['name'])
                h = Hole.objects.get(number=tee['hole__number'], course__name=reqObject['course']['fields']['name'])
                t = Tee.objects.get_or_create(course_tee=ct, hole=h, yardage=tee['yardage'], handicap=tee['handicap'], par=tee['par'])
    return JsonResponse({'data':'success'})
def courses ( request ) : resObject = { } for f in request . FILES : if ( request . FILES [ f ] . size < 10000 ) : reqFile = request . FILES [ f ] . read ( ) . decode ( 'utf-8' ) reqObject = json . loads ( reqFile ) for course in serializers . deserialize ( 'json' , json . dumps ( [ reqObject [ 'course' ] ] ) ) : course . save ( ) for hole in serializers . deserialize ( 'json' , json . dumps ( reqObject [ 'holes' ] ) ) : hole . save ( ) for courseTee in serializers . deserialize ( 'json' , json . dumps ( reqObject [ 'courseTees' ] ) ) : courseTee . save ( ) for tee in reqObject [ 'tees' ] : ct = CourseTee . objects . get ( name = tee [ 'course_tee__name' ] , course__name = reqObject [ 'course' ] [ 'fields' ] [ 'name' ] ) h = Hole . objects . get ( number = tee [ 'hole__number' ] , course__name = reqObject [ 'course' ] [ 'fields' ] [ 'name' ] ) t = Tee . objects . get_or_create ( course_tee = ct , hole = h , yardage = tee [ 'yardage' ] , handicap = tee [ 'handicap' ] , par = tee [ 'par' ] ) return JsonResponse ( { 'data' : 'success' } )
Update function to import courses from uploaded json file
TODO: json validation, try catch
url: '/golf/importcourses/'
Update function to import courses from uploaded json file TODO : json validation try catch url : ' / golf / importcourses / '
"""
    Update function to import courses from uploaded json file
    TODO: json validation, try catch
    url: '/golf/importcourses/'
    """
request