예제 #1
0
파일: views.py 프로젝트: myztinen/tsoha
def add_recipe(request):
    if request.user.is_authenticated():
        ingredients = Ingredient.objects.all().order_by('name')
        drink_types = Drink_type.objects.all().order_by('type_name')
        if AddRecipeValidator(request).isValidAddRecipeRequest():
            form = AddRecipeForm(request.POST)
            if form.is_valid():
                message = AddRecipeHandler(form).saveRecipe()
                return AddRecipePageRenderer(request).renderAddRecipePage(ingredients, drink_types, message)
        else:
           message = 'Drinkkireseptin pakollisina tietoina on annettava juoman nimi, valmistusohjeet, juomatyyppi ja ainakin yksi ainesosa ja sen annos'

           return AddRecipePageRenderer(request).renderAddRecipePage(ingredients, drink_types, message)
    else:
        message = 'Sinun täytyy kirjautua lisätäksesi reseptejä'
        return IndexPageRenderer(request).renderIndexPage(None,message)
예제 #2
0
 def isValidAddRecipeRequest(self):
     if self.request.method == 'POST':
         form = AddRecipeForm(self.request.POST) 
         if form.is_valid():
             return True
     return False