def get_edit_menu(request,bid): form = MenuItemForm() allergyform =AllergyInfoForm() otherinfoform = OtherInfoForm() nutritionform = NutritionInfoForm() b = get_object_or_404(InterestedBusiness,pk=int(bid)) if request.method == 'POST': if request.user != b.owner: return HttpResponseRedirect('/invalid') mi = MenuItem(business=b) form = MenuItemForm(request.POST,instance=mi) if form.is_valid(): menuitem = form.save() instanceAllergy = AllergyInfo(menuitem=menuitem) instanceNutrition = NutritionInfo(menuitem=menuitem) instanceOther = OtherRestrictions(menuitem=menuitem) allergyform = AllergyInfoForm(request.POST, instance=instanceAllergy) otherinfoform = OtherInfoForm(request.POST, instance=instanceOther) nutritionform = NutritionInfoForm(request.POST, instance=instanceNutrition) allergyform.save() nutritionform.save() otherinfoform.save() print 'saved a form!' else: print 'invalid form' return HttpResponseRedirect('/menu/'+str(b.id)) mealName = generate_menu_list(b) return render_to_response('menu/menuelements/menu.html',{'business':b,'menuitems':mealName, 'mform':form, 'nform':nutritionform, 'aform':allergyform, 'oiform': otherinfoform}, context_instance=RequestContext(request))
def edit_menu(request,bid,mid): b = get_object_or_404(InterestedBusiness,pk=int(bid)) mi = MenuItem.objects.get(id=mid) menuitemform = MenuItemForm(instance=mi) instanceAllergy = mi.allergy instanceNutrition = mi.nutrition instanceOther = mi.otherinfo allergyform = AllergyInfoForm( instance=instanceAllergy) otherinfoform = OtherInfoForm( instance=instanceOther) nutritionform = NutritionInfoForm( instance=instanceNutrition) print ' before and method is ' + str(request.method) if request.method == 'POST': if request.user != b.owner: return HttpResponseRedirect('/invalid') form = MenuItemForm(request.POST,instance=mi) print 'here and form is ' + str(form) if form.is_valid(): mi = form.save() instanceAllergy = mi.allergy instanceNutrition = mi.nutrition instanceOther = mi.otherinfo allergyform = AllergyInfoForm(request.POST, instance=instanceAllergy) otherinfoform = OtherInfoForm(request.POST, instance=instanceOther) nutritionform = NutritionInfoForm(request.POST, instance=instanceNutrition) print nutritionform allergyform.save() nutritionform.save() otherinfoform.save() print 'saved a form!' else: print 'invalid form' return HttpResponseRedirect('/menu/'+str(b.id)) mealName = generate_menu_list(b,int(mid)) return render_to_response('menu/menuelements/menu.html',{'business':b,'menuitems':mealName, 'mform':menuitemform, 'nform':nutritionform, 'aform':allergyform, 'oiform': otherinfoform, 'editing':True}, context_instance=RequestContext(request))
def get_edit_details(request,bid,mid): b = get_object_or_404(InterestedBusiness,pk=int(bid)) mi = MenuItem.objects.get(id=mid) instanceAllergy = mi.allergy instanceNutrition = mi.nutrition instanceOther = mi.otherinfo if 'editing' in request.GET: if request.user != b.owner: return HttpResponseRedirect('/invalid') editing = True else: editing = False form = MenuItemForm(instance=mi) allergyform = AllergyInfoForm( instance=instanceAllergy) otherinfoform = OtherInfoForm( instance=instanceOther) nutritionform = NutritionInfoForm( instance=instanceNutrition) print ' before and method is ' + str(request.method) if request.method == 'POST': if request.user != b.owner: return HttpResponseRedirect('/invalid') form = MenuItemForm(request.POST,instance=mi) print 'here and form is ' + str(form) if form.is_valid(): mi = form.save() instanceAllergy = mi.allergy instanceNutrition = mi.nutrition instanceOther = mi.otherinfo allergyform = AllergyInfoForm(request.POST, instance=instanceAllergy) otherinfoform = OtherInfoForm(request.POST, instance=instanceOther) nutritionform = NutritionInfoForm(request.POST, instance=instanceNutrition) print nutritionform allergyform.save() nutritionform.save() otherinfoform.save() print 'saved a form!' else: print 'invalid form' return HttpResponseRedirect('/menu/'+str(b.id)+'/details/'+str(mi.id)) return render_to_response('menu/dish/dishdetails.html',{'business':b,'m':mi, 'mform':form, 'nform':nutritionform, 'aform':allergyform, 'oiform': otherinfoform, 'editing':editing}, context_instance=RequestContext(request))