Started working on the skeleton of an actual website. Created barebones templates...
authorKriti Godey <kriti.godey@gmail.com>
Thu, 4 Mar 2010 20:46:25 +0000 (15:46 -0500)
committerKriti Godey <kriti.godey@gmail.com>
Thu, 4 Mar 2010 20:46:25 +0000 (15:46 -0500)
templates/allsandwiches.html
templates/base.html [new file with mode: 0644]
templates/ingredient.html
templates/login.html
templates/newuser.html
templates/onesandwich.html
templates/sandwich.html
templates/sidebar.html [new file with mode: 0644]
urls.py
views.py

index 102f86c..4877263 100644 (file)
@@ -1,20 +1,18 @@
-<html>
-       <head>
-               <title>Every Ma'ayanwich Ever!</title></head>
-       <body>
-               <h1>All Ma'ayanwiches</h1>
-               {% for s in sandwiches %}
-                       <h3>{{ s.adjective }}</h3>
-                       <p>Made on {{ s.date_made }} and added by {{ s.user.username }}.</p>
-                       <img src="{{ s.picture.url }}">
-                       <h5>Ingredients</h5>
-                       <ul>
+{% extends "base.html" %}
+
+{% block content %}
+       <h1 class="pagetitle">All Ma'ayanwiches</h1>
+               {% for s in allsandwiches %}
+                       <h3 class="sandwichtitle">{{ s.adjective }}</h3>
+                       <p class="metadata">Made on {{ s.date_made }} and added by {{ s.user.username }}.</p>
+                       <img class="sandwichimg" src="{{ s.picture.url }}">
+                       <h4 class="sandwichsub">Ingredients</h4>
+                       <ul class="ingredients">
                                {% for i in s.ingredients.all %}
                                        <li>{{ i.name }}
                                {% endfor %}
                        </ul>
-                       <h5>Notes</h5>
-                       <p> {{ s.notes }}</p>
+                       <h4 class="sandwichsub">Notes</h5>
+                       <p class="sandnotes"> {{ s.notes }}</p>
                {% endfor %}
-       </body>
-</html>
\ No newline at end of file
+{% endblock %}
\ No newline at end of file
diff --git a/templates/base.html b/templates/base.html
new file mode 100644 (file)
index 0000000..7b0eb1f
--- /dev/null
@@ -0,0 +1,34 @@
+<html>
+       <head>
+               <link rel="stylesheet" href="http://127.0.0.1:8000/sandwiches/style.css" type="text/css">
+               <title>{% block title %}Ma'ayanwich Tracker{% endblock %}</title>
+       </head>
+       <body>
+               <div id="wrapper">
+                       <div id="header">
+                               <h1 class="header">Ma'ayanwich Tracker</h1>
+                       </div>
+                       <div id="sidebar">
+                               <h3 class="navtitle">NAVIGATION</h3>
+                               <ul class="nav">
+                                       <li><a href="http://127.0.0.1:8000/sandwich/all/" class="navlink">All sandwiches</a></li>
+                                       <li><a href="http://127.0.0.1:8000/sandwich/add/" class="navlink">Add sandwich</a></li>
+                                       <li><a href="http://127.0.0.1:8000/login/" class="navlink">Login</a></li>
+                                       <li><a href="http://127.0.0.1:8000/signup/" class="navlink">Signup</a></li>
+                                       <li>Monthly Links (TODO)</li>
+                                       <li>Logout (TODO)</li>
+                               </ul>
+                               <h3 class="navtitle">NEWEST</h3>
+                               <ul class="newest">
+                                       {% for s in sandwiches %}
+                                               <li>{{ s.adjective }}</li>
+                                       {% endfor %}
+                               </ul>
+                       </div>
+                       <div id="content">
+                               {% block content %}     
+                               {% endblock %}
+                       </div>
+               </div>
+       <body>
+</html>
\ No newline at end of file
index 6d8b912..04f61bf 100644 (file)
@@ -1,11 +1,10 @@
-<html>
-       <head>
-               <title>Add an ingredient!</title></head>
-       <body>
-               <h1>Add a new ingredient</h1>
-               <form enctype="multipart/form-data" action="/addingredient/" method="post">
-               {{ iform.as_p }}
-               <input type="submit" value="Submit" />
-               </form>
-       </body>
-</html>
\ No newline at end of file
+{% extends "base.html" %}
+
+{% block title %}Add an ingredient{% endblock %}
+{% block content %}
+       <h1 class="pagetitle">Add a new ingredient</h1>
+       <form enctype="multipart/form-data" action="/addingredient/" method="post">
+       {{ iform.as_p }}
+       <input type="submit" value="Submit" />
+       </form>
+{% endblock %}
\ No newline at end of file
index 367b112..c92d7cf 100644 (file)
@@ -1,11 +1,9 @@
-<html>
-       <head>
-               <title>Login</title></head>
-       <body>
-               <h1>Login</h1>
-               <form enctype="multipart/form-data" action="/login/" method="post">
-               {{ aform.as_p }}
-               <input type="submit" value="Submit" />
-               </form>
-       </body>
-</html>
\ No newline at end of file
+{% extends "base.html" %}
+
+{% block content %}
+       <h1 class="pagetitle">Login</h1>
+       <form enctype="multipart/form-data" action="/login/" method="post">
+       {{ aform.as_p }}
+       <input type="submit" value="Submit" />
+       </form>
+{% endblock %}
\ No newline at end of file
index fb53041..fcba9c3 100644 (file)
@@ -1,11 +1,9 @@
-<html>
-       <head>
-               <title>Create account</title></head>
-       <body>
-               <h1>Create account</h1>
-               <form enctype="multipart/form-data" action="/newuser/" method="post">
-               {{ cform.as_p }}
-               <input type="submit" value="Submit" />
-               </form>
-       </body>
-</html>
\ No newline at end of file
+{% extends "base.html" %}
+
+{% block content %}
+       <h1 class="pagetitle">Create account</h1>
+       <form enctype="multipart/form-data" action="/newuser/" method="post">
+       {{ cform.as_p }}
+       <input type="submit" value="Submit" />
+       </form>
+{% endblock %}
\ No newline at end of file
index a8096db..b9bf28b 100644 (file)
@@ -1,17 +1,17 @@
-<html>
-       <head>
-               <title>Every Ma'ayanwich Ever!</title></head>
-       <body>
-               <h3>{{ s.adjective }}</h3>
-               <p>Made on {{ s.date_made }} and added by {{ s.user.username }}.</p>
-               <img src="{{ s.picture.url }}">
-               <h5>Ingredients</h5>
-               <ul>
-                       {% for i in s.ingredients.all %}
-                               <li>{{ i.name }}
-                       {% endfor %}
-               </ul>
-               <h5>Notes</h5>
-               <p> {{ s.notes }}</p>
-       </body>
-</html>
\ No newline at end of file
+{% extends "base.html" %}
+
+{% block title %} The {{ s.adjective }} Ma'ayanwich {% endblock %}
+
+{% block content %}
+       <h3 class="sandwichtitle">{{ s.adjective }}</h3>
+       <p class="metadata">Made on {{ s.date_made }} and added by {{ s.user.username }}.</p>
+       <img class="sandwichimg" src="{{ s.picture.url }}">
+       <h4 class="sandwichsub">Ingredients</h4>
+       <ul class="ingredients">
+               {% for i in s.ingredients.all %}
+                       <li>{{ i.name }}
+               {% endfor %}
+       </ul>
+       <h4 class="sandwichsub">Notes</h5>
+       <p class="sandnotes"> {{ s.notes }}</p>
+{% endblock %}
\ No newline at end of file
index 32a85ed..1e8e621 100644 (file)
@@ -1,11 +1,10 @@
-<html>
-       <head>
-               <title>Add a sandwich!</title></head>
-       <body>
-               <h1>Add a new sandwich</h1>
-               <form enctype="multipart/form-data" action="/addsandwich/" method="post">
-               {{ sform.as_p }}
-               <input type="submit" value="Submit" />
-               </form>
-       </body>
-</html>
\ No newline at end of file
+{% extends "base.html" %}
+
+{% block title %}Add a sandwich{% endblock %}
+{% block content %}
+       <h1 class="pagetitle">Add a new sandwich</h1>
+       <form enctype="multipart/form-data" action="/addsandwich/" method="post">
+       {{ sform.as_p }}
+       <input type="submit" value="Submit" />
+       </form>
+{% endblock %}
\ No newline at end of file
diff --git a/templates/sidebar.html b/templates/sidebar.html
new file mode 100644 (file)
index 0000000..3873e4f
--- /dev/null
@@ -0,0 +1,7 @@
+{% extends "base.html" %}
+
+<ul class="newest">
+       {% for s in sandwiches %}
+               <li>{{ s.adjective }}</li>
+       {% endfor %}
+</ul>
\ No newline at end of file
diff --git a/urls.py b/urls.py
index 091db55..26ce058 100644 (file)
--- a/urls.py
+++ b/urls.py
@@ -3,12 +3,12 @@ import views
 from django.shortcuts import render_to_response
 
 urlpatterns = patterns('',
-       (r'^sandwiches/add/$', views.add_sandwich),
+       (r'^sandwich/add/$', views.add_sandwich),
+       (r'^sandwich/addingredient/$', views.add_ingredient),
+       (r'^sandwich/all/$', views.all_sandwich),
+       (r'^sandwich/(?P<slug>[-\w]+)/$', views.specific_sandwich),
+       (r'^sandwich/(?P<year>[-\w]+)/(?P<month>[-\w]+)/$', views.sandwich_month),
        (r'^login/$', views.login_view),
-       (r'^newuser/$', views.create_user),
-       (r'^sandwiches/addingredient/$', views.add_ingredient),
-       (r'^sandwiches/all/$', views.all_sandwich),
-       (r'^sandwiches/new/$', views.newsandwiches),
-       (r'^sandwiches/(?P<slug>[-\w]+)/$', views.specific_sandwich),
-       (r'^sandwiches/(?P<year>[-\w]+)/(?P<month>[-\w]+)/$', views.sandwich_month),
+       (r'^signup/$', views.create_user),
+       (r'', views.baseview),
 )
index eb02bad..2b92417 100644 (file)
--- a/views.py
+++ b/views.py
@@ -11,6 +11,10 @@ import datetime
 
 
 def add_sandwich(request):
+       if Sandwich.objects.count() > 5:
+               sandwiches = Sandwich.objects.order_by('date_made')[:5]
+       else:
+               sandwiches = Sandwich.objects.order_by('date_made')
        if request.method == 'POST': # If the form has been submitted...
                form = SandwichForm(request.POST, request.FILES) # A form bound to the POST data
                if form.is_valid(): # All validation rules pass
@@ -21,10 +25,14 @@ def add_sandwich(request):
        else:
                form = SandwichForm() # An unbound form
                
-       return render_to_response('sandwich.html', {'sform': form,})
+       return render_to_response('sandwich.html', {'sform': form, 'sandwiches': sandwiches,})
 
 
 def add_ingredient(request):
+       if Sandwich.objects.count() > 5:
+               sandwiches = Sandwich.objects.order_by('date_made')[:5]
+       else:
+               sandwiches = Sandwich.objects.order_by('date_made')
        if request.method == 'POST': # If the form has been submitted...
                form = IngredientForm(request.POST) # A form bound to the POST data
                if form.is_valid(): # All validation rules pass
@@ -35,26 +43,32 @@ def add_ingredient(request):
        else:
                form = IngredientForm() # An unbound form
 
-       return render_to_response('ingredient.html', {'iform': form,})
+       return render_to_response('ingredient.html', {'iform': form, 'sandwiches': sandwiches})
        
 
 def all_sandwich(request):
        try:
-               sandwiches = Sandwich.objects.all()
+               allsandwiches = Sandwich.objects.all()
+               if Sandwich.objects.count() > 5:
+                       sandwiches = Sandwich.objects.order_by('date_made')[:5]
+               else:
+                       sandwiches = Sandwich.objects.order_by('date_made')
        except Sandwich.DoesNotExist:
                raise Http404
-       return render_to_response('allsandwiches.html', {'sandwiches': sandwiches,})
+       return render_to_response('allsandwiches.html', {'allsandwiches': allsandwiches, 'sandwiches': sandwiches})
 
        
-def newsandwiches(request):
+def baseview(request):
        try:
                if Sandwich.objects.count() > 5:
                        sandwiches = Sandwich.objects.order_by('date_made')[:5]
+                       allsandwiches = Sandwich.objects.all()
                else:
                        sandwiches = Sandwich.objects.order_by('date_made')
+                       allsandwiches = Sandwich.objects.all()
        except Sandwich.DoesNotExist:
                raise Http404
-       return render_to_response('allsandwiches.html', {'sandwiches': sandwiches,})
+       return render_to_response('base.html', {'sandwiches': sandwiches, 'all': allsandwiches,})
        
        
 def sandwich_month(request, year, month):
@@ -67,13 +81,21 @@ def sandwich_month(request, year, month):
        
 def specific_sandwich(request, slug):
        try:
-               sandwiches = Sandwich.objects.get(slug=slug)
+               s = Sandwich.objects.get(slug=slug)
+               if Sandwich.objects.count() > 5:
+                       sandwiches = Sandwich.objects.order_by('date_made')[:5]
+               else:
+                       sandwiches = Sandwich.objects.order_by('date_made')
        except Sandwich.DoesNotExist:
                raise Http404
-       return render_to_response('onesandwich.html', {'s': sandwiches,})
+       return render_to_response('onesandwich.html', {'s': s, 'sandwiches': sandwiches,})
 
 
 def login_view(request):
+       if Sandwich.objects.count() > 5:
+               sandwiches = Sandwich.objects.order_by('date_made')[:5]
+       else:
+               sandwiches = Sandwich.objects.order_by('date_made')
        try:
                username = request.POST['username']
                password = request.POST['password']
@@ -91,9 +113,13 @@ def login_view(request):
                        return HttpResponse(thankshtml)
        except KeyError:
                aform = AuthenticationForm()
-               return render_to_response('login.html', {'aform': aform,})
+               return render_to_response('login.html', {'aform': aform, 'sandwiches': sandwiches,})
                
 def create_user(request):
+       if Sandwich.objects.count() > 5:
+               sandwiches = Sandwich.objects.order_by('date_made')[:5]
+       else:
+               sandwiches = Sandwich.objects.order_by('date_made')
        if request.user.is_authenticated():
                thankshtml = "<p class=\"formthanks\">You are already logged in!</p>"
                return HttpResponse(thankshtml)
@@ -119,4 +145,4 @@ def create_user(request):
                                return HttpResponse(thankshtml) # Redirect after POST   
        else:
                form = NewUserForm() # An unbound form
-               return render_to_response('newuser.html', {'cform': form,})
\ No newline at end of file
+               return render_to_response('newuser.html', {'cform': form, 'sandwiches': sandwiches,})
\ No newline at end of file