예제 #1
0
def create(request):
    try:
        if not request.POST.get('pid', ''):
            return HttpResponse('You did not specify a parent ID.')
        else:
            parent = Section.objects.get(pk = request.POST['pid'])
    except:
        return HttpResponse('The specified ID # ' + request.POST['pid'] + ' does not exist.', status=400)
    
    if not request.POST.get('caption', ''):
        return HttpResponse('Name is not specified for the new section.')
    else:
        caption = unicode(request.POST['caption'])
    
    if request.POST.get('slug', ''):
        slug = request.POST['slug']
    else:
        slug = ''
        
    try:
        if request.POST.get('type', ''):
            section_type = SectionType.objects.get(pk = request.POST['type'])
        else:
            section_type = None
    except:
        return HttpResponse('Current type <b>' + request.POST['type'] + '</b> does not exist.', status=400)
    
    Section.create_section(parent, caption, slug, section_type)
    return HttpResponse('OK')