def ld_delete(request, lid):
    if request.method == "POST":
        teacher = request.user.teacher
        try:
            teacher.lessonday_set.get(pk=int(lid)).delete()
            return json_response("OK",get_page(request))
        except LessonDay.DoesNotExist:
            return json_response("NO SUCH LESSON DAY")
    return json_response("ERROR")
def tick_save(request):
    teacher = request.user.teacher
    if request.method == "POST":
        form = TickForm(teacher, request.POST)
        if form.is_valid():
            form.cleaned_data
            list = request.POST.getlist('tick')
            for x in list:
                save_tick(x, form.cleaned_data.get('group'), form.cleaned_data.get('subject'), teacher)
            return json_response("OK",get_page(request))
    return json_response("ERROR")
def generate(request, sid, gid):
    try:
        teacher = request.user.teacher
        subject = teacher.subjects.get(pk=int(sid))
        group = teacher.groups.get(pk=int(gid))
        lessons = LessonDay.objects.filter(teacher=teacher, group=group, subject=subject)
    except Subject.DoesNotExist:
        raise Http404
    except Group.DoesNotExist:
        raise Http404

    if request.method == "POST":
        glf = GenerateLessonDayForm(request.POST)
        if glf.is_valid():
            try:
                glf.save(teacher, subject, group)
                return json_response("OK",get_page(request))
            except:
                import traceback
                traceback.print_exc()
                return json_response("CANT SAVE")
        else:
            return json_response("INVALID FORM")
    return json_response("ERROR")