Commit 15bd17c2 authored by Jean Michel Rouly's avatar Jean Michel Rouly
Browse files

Moved lookout deletion to a form sytsem. This is getting icky.

parent c1420cc7
......@@ -21,8 +21,6 @@ urlpatterns = patterns('website.views',
url(r'^u/(?P<username>\w+)/?$', 'profile', name = 'profile'),
# create lookout
url(r'^u/(?P<username>\w+)/create-lookout/?$', 'create_lookout', name = 'create_lookout'),
# delete lookout
url(r'^u/(?P<username>\w+)/delete-lookout/(?P<lookout_id>\w+)$', 'delete_lookout', name = 'delete_lookout'),
#### LISTING PAGES ####
# global new listings page
......
......@@ -153,9 +153,8 @@ function insert_target( source, target ){
<td class="text-center">{{lookout.ISBN}}</td>
<td>{{lookout.get_info.title}}</td>
<td class="text-center">
<a href="{% url 'delete_lookout' request.user.username lookout.pk %}">
Delete
</a>
<a href="#" onclick="insert_target('{{DeleteLookout_form.lookout_id.id_for_label}}', '{{ lookout.pk }}');"
data-toggle="modal" data-target="#DeleteLookout">Delete</a>
</td>
</tr>
{% endfor %}
......@@ -172,7 +171,7 @@ function insert_target( source, target ){
<!-- Final Price Modal -->
<div class="modal fade" id="FinalPrice" tabindex="-1" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true">
aria-labelledby="FinalPriceLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<form class="form-horizontal" id="FinalPriceForm" method="post"
......@@ -183,7 +182,7 @@ aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">&times;</button>
<h4 class="modal-title" id="myModalLabel">Final Selling Price</h4>
<h4 class="modal-title" id="FinalPriceLabel">Final Selling Price</h4>
</div>
<div class="modal-body">
......@@ -215,7 +214,7 @@ aria-labelledby="myModalLabel" aria-hidden="true">
<!-- Close Confirm Modal -->
<div class="modal fade" id="CloseConfirm" tabindex="-1" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true">
aria-labelledby="CloseConfirmLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<form class="form-horizontal" id="CloseConfirmForm" method="post"
......@@ -227,7 +226,7 @@ aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">&times;</button>
<h4 class="modal-title" id="myModalLabel">Confirm Listing Closure</h4>
<h4 class="modal-title" id="CloseConfirmLabel">Confirm Listing Closure</h4>
</div>
<div class="modal-body text-center">
......@@ -247,4 +246,37 @@ aria-labelledby="myModalLabel" aria-hidden="true">
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- Delete Lookout Modal -->
<div class="modal fade" id="DeleteLookout" tabindex="-1" role="dialog"
aria-labelledby="DeleteLookoutLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<form class="form-horizontal" id="DeleteLookoutForm" method="post"
action="" role="form">
{%csrf_token%}
{{ DeleteLookout_form.lookout_id }}
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">&times;</button>
<h4 class="modal-title" id="DeleteLookoutLabel">Confirm Lookout Deletion</h4>
</div>
<div class="modal-body text-center">
Are you sure? This action cannot be undone!
</div>
<div class="modal-footer">
<button class="btn btn-default btn-sm" data-dismiss="modal">
Cancel
</button>
<input type="submit" class="btn btn-primary btn-sm"
value="Delete Lookout" name="lookout" />
</div>
</form>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
{% endblock %}
......@@ -3,7 +3,7 @@ from website.forms import ListingForm, FinalPriceForm, CloseForm
from bids.models import Bid
from bids.forms import BidForm
from lookouts.models import Lookout
from lookouts.forms import LookoutForm
from lookouts.forms import LookoutForm, DeleteLookoutForm
from django.http import Http404
from django.conf import settings
......@@ -132,6 +132,7 @@ def profile(request, username):
lookouts = Lookout.objects.filter(owner__user__username=username)
FinalPrice_form = FinalPriceForm(prefix="finalPrice")
close_form = CloseForm(prefix="close")
DeleteLookout_form = DeleteLookoutForm()
if request.method == 'POST':
# Parse the ClosedForm input fields
......@@ -164,6 +165,17 @@ def profile(request, username):
return redirect('profile', username)
else:
raise PermissionDenied("You do not own this listing.")
# Parse the DeleteLookoutForm input fields
elif 'lookout' in request.POST:
DeleteLookout_form = DeleteLookoutForm( request.POST )
if DeleteLookout_form.is_valid():
lookout_id = DeleteLookout_form.cleaned_data.get('lookout_id')
lookout = Lookout.objects.get(pk=lookout_id)
if lookout.owner == request.user.seller:
lookout.delete()
return redirect('profile', username)
else:
raise PermissionDenied("You do not own this lookout.")
return render(request, 'profile.html', {
'seller' : seller,
......@@ -172,6 +184,7 @@ def profile(request, username):
'total_sold' : totalSold( username ),
'FinalPrice_form' : FinalPrice_form,
'close_form' : close_form,
'DeleteLookout_form' : DeleteLookout_form,
},
)
......@@ -201,21 +214,6 @@ def create_lookout(request, username):
)
@login_required
def delete_lookout(request, username, lookout_id):
lookout = Lookout.objects.get(id=lookout_id)
if request.user.username == username:
if lookout.owner == request.user.seller:
lookout.delete()
else:
raise PermissionDenied("You do not own this lookout.")
else:
raise PermissionDenied("You do not own this lookout.")
return redirect('profile', username)
@login_required
def all_listings(request):
listings = Listing.objects.all().order_by('-date_created')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment