delete listing
This commit is contained in:
@@ -89,6 +89,16 @@ def verify_document(document_id):
|
|||||||
return redirect(url_for('dashboard'))
|
return redirect(url_for('dashboard'))
|
||||||
return redirect(url_for('home'))
|
return redirect(url_for('home'))
|
||||||
|
|
||||||
|
@app.route('/delete-listing/<int:listing_id>', methods=['POST', 'DELETE'])
|
||||||
|
@login_required
|
||||||
|
def delete_listing(listing_id):
|
||||||
|
if current_user.is_host:
|
||||||
|
listing = Listing.query.get_or_404(listing_id)
|
||||||
|
db.session.delete(listing)
|
||||||
|
db.session.commit()
|
||||||
|
return redirect(url_for('dashboard'))
|
||||||
|
return redirect(url_for('home'))
|
||||||
|
|
||||||
@app.route('/dashboard', methods=['GET', 'POST'])
|
@app.route('/dashboard', methods=['GET', 'POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def dashboard():
|
def dashboard():
|
||||||
|
|||||||
@@ -2,6 +2,23 @@
|
|||||||
{% block title %}Dashboard{% endblock %}
|
{% block title %}Dashboard{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<script>
|
||||||
|
function confirmDelete(listingId) {
|
||||||
|
if (confirm("Are you sure you want to delete this listing?")) {
|
||||||
|
fetch(`/delete-listing/${listingId}`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
|
}
|
||||||
|
}).then(response => {
|
||||||
|
if (response.ok) {
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
<div class="container mt-4">
|
<div class="container mt-4">
|
||||||
<h1 class="text-center">Host Dashboard</h1>
|
<h1 class="text-center">Host Dashboard</h1>
|
||||||
<div class="mt-4">
|
<div class="mt-4">
|
||||||
@@ -26,7 +43,7 @@
|
|||||||
<td>{{ listing.property_type }}</td>
|
<td>{{ listing.property_type }}</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="/edit-listing/{{ listing.id }}" class="btn btn-warning btn-sm">Edit</a>
|
<a href="/edit-listing/{{ listing.id }}" class="btn btn-warning btn-sm">Edit</a>
|
||||||
<a href="/delete-listing/{{ listing.id }}" class="btn btn-danger btn-sm">Delete</a>
|
<button onclick="confirmDelete({{ listing.id }})" class="btn btn-danger btn-sm">Delete</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
Reference in New Issue
Block a user