Modified templates a little for sandwich by user and sandwich by month (to have more...
authorKriti Godey <kriti.godey@gmail.com>
Fri, 23 Apr 2010 17:16:36 +0000 (13:16 -0400)
committerKriti Godey <kriti.godey@gmail.com>
Fri, 23 Apr 2010 17:16:36 +0000 (13:16 -0400)
templates/base.html
templates/editsandwich.html
templates/monthsandwiches.html [new file with mode: 0644]
templates/usersandwiches.html [new file with mode: 0644]
urls.py
views.py

index 280e209..7de1bc3 100644 (file)
@@ -13,6 +13,7 @@
                                <h3 class="navtitle">Account</h3>
                                <ul class="nav">
                                        {% if user.is_authenticated %}
+                                               <li><a href="{% url sandwich_user username=request.user.username %}" class="navlink">My Sandwiches</a></li>
                                                <li><a href="{% url add_sandwich %}" class="navlink">Add sandwich</a></li>
                                                <li><a href="{% url edit_user gusername=request.user.username %}" class="navlink">User Settings</a></li>
                                                <li><a href="{% url logout %}" class="navlink">Logout</a></li>
index ed649d4..a8a8133 100644 (file)
@@ -43,6 +43,18 @@ $(function()
        <p><label for="id_ing">Ingredients:</label> <input id="id_ing" type="text" name="ing"/></p>
        <input type="submit" value="Submit" />
        </form>
-       {% ifequal s.user request.user %}<p class="sandnotes"><a href="{% url del_sandwich slug=s.slug %}">Delete sandwich</a></p>{% endifequal %}
+       <script type="text/javascript">
+       <!--
+       function show_confirm()
+       {
+       var r=confirm("Are you sure you want to delete this sandwich?");
+       if (r !=0)
+         {
+         location = "{% url del_sandwich slug=s.slug %}"
+         }
+       }
+       -->
+       </script>
+       {% ifequal s.user request.user %}<p class="sandnotes"><a href="#" onClick='show_confirm(); return false;'>Delete sandwich</a></p>{% endifequal %}
        </span>
 {% endblock %}
\ No newline at end of file
diff --git a/templates/monthsandwiches.html b/templates/monthsandwiches.html
new file mode 100644 (file)
index 0000000..a956670
--- /dev/null
@@ -0,0 +1,41 @@
+{% extends "base.html" %}
+
+{% block title %}Your Sandwiches{% endblock %}
+
+{% block content %}
+       <h1 class="pagetitle">{{ xdate|date:"F Y" }}<h1>
+               {% for s in allsandwiches %}
+                       <h3 class="sandwichtitle">{{ s.adjective }}</h3>
+                       <p class="metadata">Made on {{ s.date_made|date:"F j Y" }} and added by  
+                               {% ifequal s.user request.user %} you. 
+                                       <a href="{% url edit_sandwich slug=s.slug %}"> (Edit) 
+                               {% else %} 
+                                       {% if s.user.first_name %} {{ s.user.first_name }} 
+                                               {% if s.user.last_name %} {{ s.user.last_name }} 
+                                               {% endif %} 
+                                       {% else %} 
+                                               {{ s.user.username }}. 
+                                       {% endif %}
+                               {% endifequal %}</p>
+                       {% if s.picture %}
+                               <img class="sandwichimg" src="{{ s.picture.url }}">
+                       {% endif %}
+                       <h4 class="sandwichsub">Ingredients</h4>
+                       <ul class="ingredients">
+                               {% for i in s.ingredients.all %}
+                                       <li>{{ i.name }}
+                               {% endfor %}
+                       </ul>
+                       {% if s.notes %}
+                               <h4 class="sandwichsub">Notes</h4>
+                               <p class="sandnotes"> {{ s.notes }}</p>
+                       {% endif %}
+                       {% load comments %}
+                       {% get_comment_count for s as c %}
+                       {% ifequal c 1 %}
+                               <p class="sandnotes"><a href="{{ s.get_absolute_url }}">1 comment</a></p>
+                       {% else %}
+                               <p class="sandnotes"><a href="{{ s.get_absolute_url }}">{{ c }} comments</a></p>
+                       {% endifequal %}
+               {% endfor %}
+{% endblock %}
\ No newline at end of file
diff --git a/templates/usersandwiches.html b/templates/usersandwiches.html
new file mode 100644 (file)
index 0000000..197f5a7
--- /dev/null
@@ -0,0 +1,41 @@
+{% extends "base.html" %}
+
+{% block title %}My Sandwiches{% endblock %}
+
+{% block content %}
+       <h1 class="pagetitle">My Sandwiches<h1>
+               {% for s in allsandwiches %}
+                       <h3 class="sandwichtitle">{{ s.adjective }}</h3>
+                       <p class="metadata">Made on {{ s.date_made|date:"F j Y" }} and added by  
+                               {% ifequal s.user request.user %} you. 
+                                       <a href="{% url edit_sandwich slug=s.slug %}"> (Edit) 
+                               {% else %} 
+                                       {% if s.user.first_name %} {{ s.user.first_name }} 
+                                               {% if s.user.last_name %} {{ s.user.last_name }} 
+                                               {% endif %} 
+                                       {% else %} 
+                                               {{ s.user.username }}. 
+                                       {% endif %}
+                               {% endifequal %}</p>
+                       {% if s.picture %}
+                               <img class="sandwichimg" src="{{ s.picture.url }}">
+                       {% endif %}
+                       <h4 class="sandwichsub">Ingredients</h4>
+                       <ul class="ingredients">
+                               {% for i in s.ingredients.all %}
+                                       <li>{{ i.name }}
+                               {% endfor %}
+                       </ul>
+                       {% if s.notes %}
+                               <h4 class="sandwichsub">Notes</h4>
+                               <p class="sandnotes"> {{ s.notes }}</p>
+                       {% endif %}
+                       {% load comments %}
+                       {% get_comment_count for s as c %}
+                       {% ifequal c 1 %}
+                               <p class="sandnotes"><a href="{{ s.get_absolute_url }}">1 comment</a></p>
+                       {% else %}
+                               <p class="sandnotes"><a href="{{ s.get_absolute_url }}">{{ c }} comments</a></p>
+                       {% endifequal %}
+               {% endfor %}
+{% endblock %}
\ No newline at end of file
diff --git a/urls.py b/urls.py
index 98de04b..774e399 100644 (file)
--- a/urls.py
+++ b/urls.py
@@ -6,7 +6,8 @@ urlpatterns = patterns('',
        url(r'^sandwich/index/$', views.index_sandwich, name='index_sandwich'),
        url(r'^sandwich/add/$', views.add_sandwich, name='add_sandwich'),
        url(r'^sandwich/all/$', views.all_sandwich, name='all_sandwiches'),
-       url(r'^sandwich/(?P<gusername>[-\w]+)/edit/', views.edit_user, name='edit_user'),
+       url(r'^users/(?P<username>[-\w]+)/sandwiches/', views.sandwich_user, name='sandwich_user'),
+       url(r'^users/(?P<gusername>[-\w]+)/edit/', views.edit_user, name='edit_user'),
        url(r'^sandwich/(?P<slug>[-\w]+)/edit/', views.edit_sandwich, name='edit_sandwich'),
        url(r'^sandwich/(?P<slug>[-\w]+)/delete/', views.del_sandwich, name='del_sandwich'),
        url(r'^sandwich/(?P<slug>[-\w]+)/$', views.specific_sandwich, name='sandwich_by_slug'),
index bc4798b..18f6951 100644 (file)
--- a/views.py
+++ b/views.py
@@ -54,7 +54,10 @@ def add_sandwich(request):
 
 @login_required
 def edit_sandwich(request, slug):
-       sedit = Sandwich.objects.get(slug=slug)
+       try:
+               sedit = Sandwich.objects.get(slug=slug)
+       except Sandwich.DoesNotExist:
+               raise Http404
        ingred = sedit.ingredients.all()
        if not sedit.user == request.user:
                return render_to_response('nopermission.html', context_instance=RequestContext(request))
@@ -93,9 +96,10 @@ def del_sandwich(request, slug):
                del_sandwich = Sandwich.objects.get(slug=slug)
                if request.user == del_sandwich.user:
                        del_sandwich.delete()
-               return HttpResponseRedirect(reverse('all_sandwiches'))
+               x = request.user.username
+               return HttpResponseRedirect(reverse('sandwich_user', kwargs={'username': x,}))
        else:
-               return HttpResponseRedirect(reverse('all_sandwiches'))
+               raise Http404
 
 
 def all_sandwich(request):
@@ -116,9 +120,11 @@ def index_sandwich(request):
 def sandwich_month(request, year, month):
        try:
                ms = Sandwich.objects.filter(date_made__month=month, date_made__year=year)
+               x = ms[0]
+               xdate = x.date_made
        except Sandwich.DoesNotExist:
                raise Http404
-       return render_to_response('allsandwiches.html', {'allsandwiches': ms,}, context_instance=RequestContext(request))
+       return render_to_response('monthsandwiches.html', {'allsandwiches': ms, 'xdate': xdate, }, context_instance=RequestContext(request))
        
        
 def current_home(request):
@@ -189,7 +195,16 @@ def create_user(request):
 
        return render_to_response('newuser.html', {'aform': aform,}, context_instance=RequestContext(request))
 
+@login_required
+def sandwich_user(request, username):
+       user = User.objects.get(username = username)
+       try:
+               ms = Sandwich.objects.filter(user = user)
+       except Sandwich.DoesNotExist:
+               raise Http404
+       return render_to_response('usersandwiches.html', {'allsandwiches': ms,}, context_instance=RequestContext(request))
 
+@login_required
 def edit_user(request, gusername):
        guser = User.objects.get(username = gusername)
        if not request.user.is_authenticated():