Cottage Chooser – Technical Support

← Back

This document helps operators and contributors set up, configure, deploy, and troubleshoot the Cottage Chooser application.

System Requirements

  • Python 3.9–3.12
  • pip and venv
  • SQLite (bundled with Python)
  • Windows, Linux, or macOS

Dependencies

flask>=2.2,<3
bleach>=6.1
requests>=2.31
# openai removed (manual summaries only)

Configuration (Environment Variables)

  • CC_SECRET: Flask secret key. Defaults to "dev-secret-key". Set a strong value in production.
  • CC_ALLOW_ADMIN_OVERRIDE: Enable admin override for deletes/edits (true/false/1/0/yes/no).
  • CC_ADMIN_USERS: Comma-separated admin usernames (used with override).
  • CC_ADMINS: Comma-separated admin usernames (used for vote/rating admin controls).

Note: The app unifies admin checks using both CC_ADMIN_USERS and CC_ADMINS. Either can grant admin rights. Usernames are case-insensitive and whitespace-trimmed.

Example (PowerShell): $env:CC_ADMINS = "alice,bob"

Local Setup (Windows, PowerShell)

cd C:\Users\Peter\Downloads\CottageChooser_Full
py -3 -m venv venv
.\venv\Scripts\Activate.ps1
python -m pip install --upgrade pip setuptools wheel
python -m pip install -r requirements.txt
python app.py

If venv activation is blocked, run once: Set-ExecutionPolicy -Scope CurrentUser RemoteSigned

The app will be available at http://localhost:5000

Database

  • SQLite file: data.db (auto-created in the app folder).
  • Initialize using /init route (loads schema.sql).
  • Key tables:
    • cottages: name, location, price, beds, dogs_allowed, image, url, description, hottub, secure_garden, ev_charging, parking, log_burner, high_chair, cot, votes, submitted_by, ai_review_summary.
    • votes: id, cottage_id, user_name, voted_at (one active vote per user; denormalized count in cottages.votes).
    • comments: id, cottage_id, author, text, created_at (user reviews/comments on cottages).
    • ratings: id, cottage_id, user_name, rating (0-10), rated_at. UNIQUE constraint on (cottage_id, user_name) – one rating per user per cottage.
  • Foreign Keys: All child tables (votes, comments, ratings) use ON DELETE CASCADE to auto-cleanup when cottages are deleted.

Application Features

  • Join/Login: Group code authentication (default: "saywards").
  • Cottage Management: Add, edit (own), delete (own or admin), list, compare, and view details.
  • Voting System:
    • One vote per user (single choice)
    • Vote button on list page cards
    • Delete from Results page to change vote
    • Public voter lists on details pages
  • Rating System:
    • Users rate cottages 0-10 (multiple cottages allowed)
    • Click rating buttons on cottage cards to submit/update
    • Delete ratings individually via "Clear my rating" or ratings detail page
    • View aggregate stats: count, average, total score
    • Regular users see only their own ratings + aggregates
    • Admins see all individual ratings on the ratings detail page
  • Reviews & Comments:
    • Dedicated reviews page per cottage (/reviews/<id>)
    • Add, edit (own), delete (own or admin) comments
    • Reviews page shows cottage summary, rating stats, and all comments
    • Comments also appear on main details page
  • Results: Ranked list by votes with rating statistics displayed.
  • Compare: Side-by-side table with features, votes, and rating stats.
  • Admin Controls:
    • Manage votes (view/delete any vote)
    • View all individual ratings per cottage
    • Delete any comment (with override enabled)
    • Delete any cottage (with override enabled)
  • Presentation Mode: Slideshow viewer for PNG/JPG in static/slides/.
  • Help Mode: Floating toggle; tooltips appear below elements.
  • HTML Sanitization: Descriptions cleaned with Bleach (allowed tags: p, br, strong, em, u, ol, ul, li, h1-h4, blockquote).

Security Notes

  • Set a strong CC_SECRET in production to protect sessions.
  • Descriptions and comments are sanitized with Bleach to prevent XSS.
  • Change the group code from "saywards" if privacy is required.
  • Use HTTPS in production; ensure secure cookie flags.
  • Rating system enforces one rating per user per cottage via database UNIQUE constraint.
  • Comment editing restricted to original author or admin.
  • Admin checks use normalized (case-insensitive, trimmed) usernames.

Deployment (Linux + Apache mod_wsgi)

  1. Create a venv in the project directory and install requirements.
  2. Create a WSGI entry file (e.g., cottage.wsgi) pointing to app.py.
  3. Configure Apache VirtualHost to use mod_wsgi and point to the WSGI file.
  4. Set environment variables (CC_SECRET, CC_ADMINS, CC_ALLOW_ADMIN_OVERRIDE, CC_ADMIN_USERS) in Apache config or .env file.
  5. Ensure Apache user (e.g., www-data) can read the project directory and venv, and write to data.db and parent directory.
  6. Set permissions:
    sudo chown -R www-data:www-data /path/to/app
    sudo chmod 664 /path/to/app/data.db
    sudo chmod 775 /path/to/app
  7. Restart Apache: sudo systemctl restart apache2

Operations

  • Backup: Stop the app, copy data.db and static/, templates/.
  • Restore: Replace data.db, restart the app.
  • Slides: Add images to static/slides/; optional static/presentation.pptx.
  • Database Migration: If schema changes, either:
    • Visit /init (drops and recreates all tables – data loss!)
    • Manually run ALTER TABLE commands in SQLite shell
    • Use a migration tool like Alembic (not currently integrated)

Troubleshooting

ModuleNotFoundError: No module named 'flask'
  • Activate venv: .\venv\Scripts\Activate.ps1
  • Install deps: python -m pip install -r requirements.txt
  • Verify interpreter: python -c "import sys; print(sys.executable)"
Delete functionality not working (Raspberry Pi LAMP)
  • Check ownership: ls -la /var/www/html/Cottage
  • Set permissions:
    sudo chown -R www-data:www-data /var/www/html/Cottage
    sudo chmod 664 /var/www/html/Cottage/data.db
    sudo chmod 775 /var/www/html/Cottage
  • Check Apache errors: sudo tail -50 /var/log/apache2/error.log
  • Test as Apache user: sudo -u www-data sqlite3 data.db "SELECT * FROM cottages LIMIT 1;"
  • Ensure foreign keys cascade properly (ON DELETE CASCADE in schema.sql)
Admin can't delete votes/view ratings/delete comments
  • Set CC_ADMINS or CC_ADMIN_USERS with your username (case-insensitive).
  • Ensure you're logged in with that exact username.
  • For comment/cottage deletion, also set CC_ALLOW_ADMIN_OVERRIDE=true
Rating not saving/updating
  • Ensure you're logged in (ratings require authentication)
  • Check browser console for JavaScript errors
  • Verify ratings table exists (visit /init if needed)
  • Check SQLite constraint: UNIQUE(cottage_id, user_name)
Vote button not appearing on list page

You must be logged in to see vote buttons. If logged in and still not visible, check that list.html includes the vote button code and JavaScript handlers.

Reviews page shows error or missing data
  • Ensure /reviews/<cottage_id> route exists in app.py
  • Check that reviews.html template exists in templates/ folder
  • Verify comments table has data: SELECT * FROM comments;
Duplicate route error

Search app.py for duplicate @app.route decorators with same paths. Each route+function should appear only once.

Tooltips not visible

Toggle Help mode using the floating "Help" button; bubbles appear below elements on hover.

Key Endpoints

Endpoint Method Description
/joinGET, POSTLogin/Join via group code
/logoutGETClear session and logout
/cottagesGETList cottages with ratings/votes
/cottage/<id>GET, POSTDetails/comments/voters
/reviews/<id>GETDedicated reviews page
/addGET, POSTAdd cottage
/edit/<id>GET, POSTEdit cottage (owner only)
/delete/<id>POSTDelete cottage (owner/admin)
/vote/<id>POSTVote for cottage (one at a time)
/vote/delete/<vote_id>POSTDelete vote (user/admin)
/rate/<id>POSTSubmit/update 0-10 rating
/rating/delete/<id>POSTDelete user's rating
/ratings/<id>GETView ratings (user/admin)
/comment/edit/<id>POSTEdit comment (owner)
/comment/delete/<id>POSTDelete comment (owner/admin)
/resultsGETRankings with vote/rating stats
/compareGETSide-by-side compare
/presentationGETSlides viewer
/results_dataGETJSON snapshot for dashboards
/guideGETUser guide
/supportGETTechnical documentation
/initGETInitialize/reset DB (⚠️ data loss)

Green highlight = reviews feature. Yellow highlight = rating system endpoints.

Rating & Review API Reference

POST /rate/<cottage_id>

Submit or update a rating for a cottage.

Body: rating=0-10

Response: {"ok": true, "rating": 8, "count": 5, "average": 7.4, "total": 37}

Errors: 401 (not logged in), 400 (invalid rating), 404 (cottage not found)

POST /rating/delete/<cottage_id>

Delete the current user's rating for a cottage.

Response: {"ok": true, "count": 4, "average": 7.2, "total": 29}

Errors: 401 (not logged in), 404 (no rating found)

GET /ratings/<cottage_id>

View rating statistics and details for a cottage.

Returns: HTML page with aggregate stats, user's own rating, and (for admins) all individual ratings.

GET /reviews/<cottage_id>

View all reviews/comments for a cottage with rating context.

Returns: HTML page with cottage summary, rating stats, user's rating, and all comments with edit/delete controls.