06/16 Phase 6
This commit is contained in:
@@ -9,10 +9,11 @@ from flask_babel import gettext as _
|
||||
from app.extensions import db, limiter
|
||||
from app.models.category import Category
|
||||
from app.models.listing import Listing, ListingImage
|
||||
from app.models.enums import ListingStatus
|
||||
from app.models.enums import ListingStatus, ReportReason
|
||||
from app.services import listings as svc
|
||||
from app.services.geo import geocode_zip
|
||||
from app.services.images import process_upload, delete_image_files, ImageError
|
||||
from app.services import reports as rsvc
|
||||
from app.blueprints.listings.forms import ListingForm, ImageUploadForm
|
||||
|
||||
listings_bp = Blueprint("listings", __name__)
|
||||
@@ -220,6 +221,28 @@ def mark_sold(listing_id):
|
||||
return redirect(url_for("listings.detail", listing_id=listing.id))
|
||||
|
||||
|
||||
# --- report ---
|
||||
@listings_bp.route("/listings/<int:listing_id>/report", methods=["POST"])
|
||||
@login_required
|
||||
@limiter.limit("20 per hour", methods=["POST"])
|
||||
def report(listing_id):
|
||||
listing = Listing.query.get_or_404(listing_id)
|
||||
reason_raw = request.form.get("reason", type=str)
|
||||
note = request.form.get("note", type=str)
|
||||
try:
|
||||
reason = ReportReason(reason_raw)
|
||||
except ValueError:
|
||||
flash(_("Invalid report reason."), "danger")
|
||||
return redirect(url_for("listings.detail", listing_id=listing.id))
|
||||
try:
|
||||
rsvc.create_report(listing, current_user, reason, note=note)
|
||||
except rsvc.ReportError as e:
|
||||
flash(str(e), "warning")
|
||||
else:
|
||||
flash(_("Thanks — this listing has been reported for review."), "success")
|
||||
return redirect(url_for("listings.detail", listing_id=listing.id))
|
||||
|
||||
|
||||
# --- my listings ---
|
||||
@listings_bp.route("/my/listings")
|
||||
@login_required
|
||||
|
||||
Reference in New Issue
Block a user