Changeset - 11c89784b7d7
[Not reviewed]
default
0 1 0
Branko Majic (branko) - 13 years ago 2013-02-19 21:08:20
branko@majic.rs
Added check in the view to make sure that session data is available.
1 file changed with 11 insertions and 10 deletions:
0 comments (0 inline, 0 general)
djangoshaker/views.py
Show inline comments
 
@@ -49,17 +49,18 @@ class UserView(TemplateView):
 

	
 
    def get_context_data(self, **kwargs):
 
        context = super(UserView, self).get_context_data(**kwargs)
 
        context['user_ingredients'] = Ingredient.objects.filter(pk__in = self.request.session['user_ingredients']).order_by('name')
 
        context['ingredients'] = Ingredient.objects.exclude(pk__in = self.request.session['user_ingredients']).order_by('name')
 
        if 'user_ingredients' in self.request.session:
 
            context['user_ingredients'] = Ingredient.objects.filter(pk__in = self.request.session['user_ingredients']).order_by('name')
 
            context['ingredients'] = Ingredient.objects.exclude(pk__in = self.request.session['user_ingredients']).order_by('name')
 

	
 
        user_ingredients = set(self.request.session['user_ingredients'])
 
        available_recipes = []
 
        for recipe in Recipe.objects.all():
 
            recipe_ingredients = set([recing.ingredient_id for recing in recipe.recipeingredient_set.all()])
 
            if recipe_ingredients.issubset(user_ingredients):
 
                print recipe.name
 
                available_recipes.append(recipe)
 
        context['available_recipes'] = available_recipes
 
            user_ingredients = set(self.request.session['user_ingredients'])
 
            available_recipes = []
 
            for recipe in Recipe.objects.all():
 
                recipe_ingredients = set([recing.ingredient_id for recing in recipe.recipeingredient_set.all()])
 
                if recipe_ingredients.issubset(user_ingredients):
 
                    print recipe.name
 
                    available_recipes.append(recipe)
 
            context['available_recipes'] = available_recipes
 

	
 
        return context
 

	
0 comments (0 inline, 0 general)