X-Git-Url: http://git.ithinksw.org/~kgodey/maayanwich.git/blobdiff_plain/b40a66a512f018ca056f96c79cd7bf4ed05a83ce..808fb552369a814e41d8241c36168e56681ea69b:/views.py?ds=sidebyside diff --git a/views.py b/views.py index fde9e56..18f6951 100644 --- 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): @@ -104,14 +108,23 @@ def all_sandwich(request): except Sandwich.DoesNotExist: raise Http404 return render_to_response('allsandwiches.html', {'allsandwiches': allsandwiches,}, context_instance=RequestContext(request)) + +def index_sandwich(request): + try: + allsandwiches = Sandwich.objects.order_by('adjective') + except Sandwich.DoesNotExist: + raise Http404 + return render_to_response('indexsandwiches.html', {'allsandwiches': allsandwiches,}, context_instance=RequestContext(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): @@ -182,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():