<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>
<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
--- /dev/null
+{% 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
--- /dev/null
+{% 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
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'),
@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))
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):
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):
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():