Default view is now latest sandwich's month's sandwiches. Fixed other minor things.
authorKriti Godey <kriti.godey@gmail.com>
Fri, 5 Mar 2010 04:33:29 +0000 (23:33 -0500)
committerKriti Godey <kriti.godey@gmail.com>
Fri, 5 Mar 2010 04:33:29 +0000 (23:33 -0500)
templates/base.html
urls.py
views.py

index 2c15dee..b12c087 100644 (file)
@@ -9,9 +9,8 @@
                                <h1 class="header">Ma'ayanwich Tracker</h1>
                        </div>
                        <div id="sidebar">
                                <h1 class="header">Ma'ayanwich Tracker</h1>
                        </div>
                        <div id="sidebar">
-                               <h3 class="navtitle">NAVIGATION</h3>
+                               <h3 class="navtitle">ACCOUNT</h3>
                                <ul class="nav">
                                <ul class="nav">
-                                       <li><a href="http://127.0.0.1:8000/sandwich/all/" class="navlink">All sandwiches</a></li>
                                        {% if user.is_authenticated %}
                                                <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/logout/" class="navlink">Logout</a></li>
                                        {% if user.is_authenticated %}
                                                <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/logout/" class="navlink">Logout</a></li>
                                                <li><a href="{{ s.get_absolute_url }}">{{ s.adjective }}</a></li>
                                        {% endfor %}
                                </ul>
                                                <li><a href="{{ s.get_absolute_url }}">{{ s.adjective }}</a></li>
                                        {% endfor %}
                                </ul>
-                               <h3 class="navtitle">BY MONTH</h3>
+                               <h3 class="navtitle">SANDWICHES</h3>
                                <ul class="newest">
                                        <li>January 2010</li>
                                        <li>February 2010</li>
                                        <li>To be done.</li>
                                </ul>
                                <ul class="newest">
                                        <li>January 2010</li>
                                        <li>February 2010</li>
                                        <li>To be done.</li>
                                </ul>
+                               <ul class="newest">
+                                       <li><a href="http://127.0.0.1:8000/sandwich/all/" class="navlink">All sandwiches</a></li>
+                               </ul>
                        </div>
                        <div id="content">
                                {% block content %}     
                        </div>
                        <div id="content">
                                {% block content %}     
diff --git a/urls.py b/urls.py
index dfab245..08e08e5 100644 (file)
--- a/urls.py
+++ b/urls.py
@@ -11,5 +11,5 @@ urlpatterns = patterns('',
        (r'^login/$', views.login_view),
        (r'^logout/$', views.logout_view),
        (r'^signup/$', views.create_user),
        (r'^login/$', views.login_view),
        (r'^logout/$', views.logout_view),
        (r'^signup/$', views.create_user),
-       (r'', views.baseview),
+       (r'', views.current_home),
 )
 )
index 6395205..2a175af 100644 (file)
--- a/views.py
+++ b/views.py
@@ -1,10 +1,9 @@
-from django.http import HttpResponse
+from django.http import HttpResponse, Http404
 from django.contrib.auth.models import User
 from forms import SandwichForm, IngredientForm, NewUserForm
 from django.shortcuts import render_to_response
 from django.core.files.uploadedfile import SimpleUploadedFile
 from models import Sandwich, Ingredient
 from django.contrib.auth.models import User
 from forms import SandwichForm, IngredientForm, NewUserForm
 from django.shortcuts import render_to_response
 from django.core.files.uploadedfile import SimpleUploadedFile
 from models import Sandwich, Ingredient
-from django.http import Http404
 from django.contrib.auth import authenticate, login, logout
 from django.contrib.auth.forms import AuthenticationForm
 import datetime
 from django.contrib.auth import authenticate, login, logout
 from django.contrib.auth.forms import AuthenticationForm
 import datetime
@@ -12,9 +11,9 @@ import datetime
 
 def add_sandwich(request):
        if Sandwich.objects.count() > 5:
 
 def add_sandwich(request):
        if Sandwich.objects.count() > 5:
-               sandwiches = Sandwich.objects.order_by('date_made')[:5]
+               sandwiches = Sandwich.objects.order_by('-date_made')[:5]
        else:
        else:
-               sandwiches = Sandwich.objects.order_by('date_made')
+               sandwiches = Sandwich.objects.order_by('-date_made')
        if request.user.is_authenticated():
                if request.method == 'POST': # If the form has been submitted...
                        form = SandwichForm(request.POST, request.FILES) # A form bound to the POST data
        if request.user.is_authenticated():
                if request.method == 'POST': # If the form has been submitted...
                        form = SandwichForm(request.POST, request.FILES) # A form bound to the POST data
@@ -33,9 +32,9 @@ def add_sandwich(request):
 def add_ingredient(request):
        if request.user.is_authenticated():
                if Sandwich.objects.count() > 5:
 def add_ingredient(request):
        if request.user.is_authenticated():
                if Sandwich.objects.count() > 5:
-                       sandwiches = Sandwich.objects.order_by('date_made')[:5]
+                       sandwiches = Sandwich.objects.order_by('-date_made')[:5]
                else:
                else:
-                       sandwiches = Sandwich.objects.order_by('date_made')
+                       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
                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
@@ -55,9 +54,9 @@ def all_sandwich(request):
        try:
                allsandwiches = Sandwich.objects.all()
                if Sandwich.objects.count() > 5:
        try:
                allsandwiches = Sandwich.objects.all()
                if Sandwich.objects.count() > 5:
-                       sandwiches = Sandwich.objects.order_by('date_made')[:5]
+                       sandwiches = Sandwich.objects.order_by('-date_made')[:5]
                else:
                else:
-                       sandwiches = Sandwich.objects.order_by('date_made')
+                       sandwiches = Sandwich.objects.order_by('-date_made')
        except Sandwich.DoesNotExist:
                raise Http404
        return render_to_response('allsandwiches.html', {'allsandwiches': allsandwiches, 'sandwiches': sandwiches, 'user': request.user,})
        except Sandwich.DoesNotExist:
                raise Http404
        return render_to_response('allsandwiches.html', {'allsandwiches': allsandwiches, 'sandwiches': sandwiches, 'user': request.user,})
@@ -66,10 +65,10 @@ def all_sandwich(request):
 def baseview(request):
        try:
                if Sandwich.objects.count() > 5:
 def baseview(request):
        try:
                if Sandwich.objects.count() > 5:
-                       sandwiches = Sandwich.objects.order_by('date_made')[:5]
+                       sandwiches = Sandwich.objects.order_by('-date_made')[:5]
                        allsandwiches = Sandwich.objects.all()
                else:
                        allsandwiches = Sandwich.objects.all()
                else:
-                       sandwiches = Sandwich.objects.order_by('date_made')
+                       sandwiches = Sandwich.objects.order_by('-date_made')
                        allsandwiches = Sandwich.objects.all()
        except Sandwich.DoesNotExist:
                raise Http404
                        allsandwiches = Sandwich.objects.all()
        except Sandwich.DoesNotExist:
                raise Http404
@@ -80,9 +79,23 @@ def sandwich_month(request, year, month):
        try:
                ms = Sandwich.objects.filter(date_made__month=month, date_made__year=year)
                if Sandwich.objects.count() > 5:
        try:
                ms = Sandwich.objects.filter(date_made__month=month, date_made__year=year)
                if Sandwich.objects.count() > 5:
-                       sandwiches = Sandwich.objects.order_by('date_made')[:5]
+                       sandwiches = Sandwich.objects.order_by('-date_made')[:5]
                else:
                else:
-                       sandwiches = Sandwich.objects.order_by('date_made')
+                       sandwiches = Sandwich.objects.order_by('-date_made')
+       except Sandwich.DoesNotExist:
+               raise Http404
+       return render_to_response('allsandwiches.html', {'allsandwiches': ms, 'sandwiches': sandwiches, 'user': request.user,})
+       
+def current_home(request):
+       temp = Sandwich.objects.order_by('-date_made')[0]
+       curr_month = temp.date_made.month
+       curr_year = temp.date_made.year
+       try:
+               ms = Sandwich.objects.filter(date_made__month=curr_month, date_made__year=curr_year)
+               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', {'allsandwiches': ms, 'sandwiches': sandwiches, 'user': request.user,})
        except Sandwich.DoesNotExist:
                raise Http404
        return render_to_response('allsandwiches.html', {'allsandwiches': ms, 'sandwiches': sandwiches, 'user': request.user,})
@@ -92,18 +105,18 @@ def specific_sandwich(request, slug):
        try:
                s = Sandwich.objects.get(slug=slug)
                if Sandwich.objects.count() > 5:
        try:
                s = Sandwich.objects.get(slug=slug)
                if Sandwich.objects.count() > 5:
-                       sandwiches = Sandwich.objects.order_by('date_made')[:5]
+                       sandwiches = Sandwich.objects.order_by('-date_made')[:5]
                else:
                else:
-                       sandwiches = Sandwich.objects.order_by('date_made')
+                       sandwiches = Sandwich.objects.order_by('-date_made')
        except Sandwich.DoesNotExist:
                raise Http404
        return render_to_response('onesandwich.html', {'s': s, 'sandwiches': sandwiches, 'user': request.user,})
 
 def logout_view(request):
        if Sandwich.objects.count() > 5:
        except Sandwich.DoesNotExist:
                raise Http404
        return render_to_response('onesandwich.html', {'s': s, 'sandwiches': sandwiches, 'user': request.user,})
 
 def logout_view(request):
        if Sandwich.objects.count() > 5:
-               sandwiches = Sandwich.objects.order_by('date_made')[:5]
+               sandwiches = Sandwich.objects.order_by('-date_made')[:5]
        else:
        else:
-               sandwiches = Sandwich.objects.order_by('date_made')
+               sandwiches = Sandwich.objects.order_by('-date_made')
        if request.user.is_authenticated():
                logout(request)
                thankshtml = "<p class=\"formthanks\">You have been logged out.</p>"
        if request.user.is_authenticated():
                logout(request)
                thankshtml = "<p class=\"formthanks\">You have been logged out.</p>"
@@ -115,9 +128,9 @@ def logout_view(request):
 
 def login_view(request):
        if Sandwich.objects.count() > 5:
 
 def login_view(request):
        if Sandwich.objects.count() > 5:
-               sandwiches = Sandwich.objects.order_by('date_made')[:5]
+               sandwiches = Sandwich.objects.order_by('-date_made')[:5]
        else:
        else:
-               sandwiches = Sandwich.objects.order_by('date_made')
+               sandwiches = Sandwich.objects.order_by('-date_made')
        try:
                username = request.POST['username']
                password = request.POST['password']
        try:
                username = request.POST['username']
                password = request.POST['password']
@@ -140,9 +153,9 @@ def login_view(request):
 
 def create_user(request):
        if Sandwich.objects.count() > 5:
 
 def create_user(request):
        if Sandwich.objects.count() > 5:
-               sandwiches = Sandwich.objects.order_by('date_made')[:5]
+               sandwiches = Sandwich.objects.order_by('-date_made')[:5]
        else:
        else:
-               sandwiches = Sandwich.objects.order_by('date_made')
+               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)
        if request.user.is_authenticated():
                thankshtml = "<p class=\"formthanks\">You are already logged in!</p>"
                return HttpResponse(thankshtml)