Ejemplo n.º 1
0
def save_cookbook_set(request,):
    """
    用于保存学校的食谱设置
    """
    # 取得参数
    try:
        user = request.user
        schools = user.manageSchools.all()

        if schools.count() > 0:
            school = schools[0]
        else:
            messages.error(request, "你没有可管理的学校")
            return redirect("manage")

        breakfast = True if request.POST.get("breakfast") else False
        light_breakfast = True if request.POST.get("light_breakfast") else False
        lunch = True if request.POST.get("lunch") else False
        light_lunch = True if request.POST.get("light_lunch") else False
        dinner = True if request.POST.get("dinner") else False
        light_dinner = True if request.POST.get("light_dinner") else False

        school_set = CookbookSet.objects.filter(school=school)

        if school_set.count() > 0:
            school_set = school_set[0]
            school_set.breakfast = breakfast
            school_set.light_breakfast = light_breakfast
            school_set.lunch = lunch
            school_set.light_lunch = light_lunch
            school_set.dinner = dinner
            school_set.light_dinner = light_dinner

        else:
            school_set = CookbookSet(
                school=school,
                breakfast=breakfast,
                light_breakfast=light_breakfast,
                lunch=lunch,
                light_lunch=light_lunch,
                dinner=dinner,
                light_dinner=light_dinner,
            )

        school_set.save()
        messages.success(request, "设置成功")
    except:
        messages.success(request, "设置失败")

    return redirect(request.META["HTTP_REFERER"])
Ejemplo n.º 2
0
def save_cookbook_set(request,):
    """
    用于保存学校的食谱设置
    """
    # 取得参数
    user = request.user
    schools = get_schools(request.user)
    school_pks = [s.id for s in schools]
    school_id = int(request.POST.get('school_id',0))
    if school_id != 0:
        try:
            school =School.objects.get(id=school_id,id__in=school_pks)
        except:
            messages.error(request,'你没有可管理的学校')
            return redirect('oa_home')
    else:
        if schools:
            school = schools[0]
        else:
            messages.error(request,'你没有可管理的学校')
            return redirect('oa_home')
    try:            
        breakfast = True if request.POST.get('breakfast') else False
        light_breakfast = True if request.POST.get('light_breakfast') else False
        lunch = True if request.POST.get('lunch') else False
        light_lunch = True if request.POST.get('light_lunch') else False
        dinner = True if request.POST.get('dinner') else False
        light_dinner = True if request.POST.get('light_dinner') else False
        school_set = CookbookSet.objects.filter(school=school)

        if school_set.count() > 0:
            school_set = school_set[0]
            school_set.breakfast = breakfast
            school_set.light_breakfast = light_breakfast
            school_set.lunch = lunch
            school_set.light_lunch = light_lunch
            school_set.dinner = dinner
            school_set.light_dinner = light_dinner
            
        else:
            school_set = CookbookSet(school=school,breakfast=breakfast,light_breakfast=light_breakfast,lunch=lunch,light_lunch=light_lunch,dinner=dinner,light_dinner=light_dinner)

        school_set.save()
        messages.success(request,'设置成功')
    except:
        messages.success(request,'设置失败')       
    
    return redirect(request.META['HTTP_REFERER'])