Commits

Chris Grubbs committed cdd3240

added a featured recipe bit to the homepage

Comments (0)

Files changed (5)

phlombay/recipes/fixtures/recipes_recipes.json

             "creator": 1,
             "created": "2012-09-22T18:06:45.001",
             "modified": "2012-09-22T20:52:21.141",
-            "featured": false,
+            "featured": true,
             "steps_json_blob": "[{\"text\": \"Chop melon into bite-size chunks.\"}, {\"text\": \"Place a slice of prosciutto and a chunk of melon on each toothpick.\"}]",
             "time_required": "10 minutes",
             "servings": 12,

phlombay/recipes/tests.py

 
     def test_index(self):
         """
-        Tests that the homepage works.
+        Tests that the homepage renders and that it has a featured recipe.
         """
         response = self.client.get('/')
         self.assertTemplateUsed(response, 'recipes/index.html')
+        self.assertContains(response, 'Featured Recipe')
+        self.assertContains(response, 'Prosciutto & Melon Bites')
 
     def test_browse_recipes(self):
         """

phlombay/recipes/views.py

 
 def index(request):
     """
-    Renders the homepage.
+    Renders the homepage, which also shows a featured recipe if there are any.
     """
-    return render(request, 'recipes/index.html', {'nav_section': 'index'})
+    context = {'nav_section': 'index'}
+    try:
+        featured_recipe = Recipe.objects.filter(featured=True).order_by('?')[0]
+        context['featured_recipe'] = featured_recipe 
+    except IndexError:
+        pass
+    return render(request, 'recipes/index.html', context)
 
 
 def browse_recipes(request):

phlombay/templates/recipes/browse_recipes.html

 
 <h1>All Recipes</h1>
 
-{% for recipe in recipes %}
-<div>
-	<h3><a href="{% url recipes.views.detail recipe.id %}">{{ recipe.name }}</a></h3>
-	<p>{{ recipe.description }}</p>
-</div>
-{% endfor %}
+{% if recipes %}
+	{% for recipe in recipes %}
+	<div>
+		<h3><a href="{% url recipes.views.detail recipe.id %}">{{ recipe.name }}</a></h3>
+		<p>{{ recipe.description }}</p>
+	</div>
+	{% endfor %}
+{% else %}
+	<p>Phlombay must have just launched, because there aren't any recipes to show. Check back soon!</p>
+{% endif %}
 
 {% endblock %}
 

phlombay/templates/recipes/index.html

   recipes. Happy cooking!
 </p>
 
+{% if featured_recipe %}
+	<hr/>
+	<div class="row">
+		<div class="span8"></div>
+		<div class="span4">
+			<h6>Featured Recipe</h6>
+			<p><a href="{% url recipes.views.detail featured_recipe.id %}">{{ featured_recipe.name }}</a></p>
+			<p>{{ featured_recipe.description }}</p>
+		</div>
+	</div>
+{% endif %}
+
 {% endblock %}