diff --git a/app.py b/app.py index fecb8ad..69ca0bb 100644 --- a/app.py +++ b/app.py @@ -203,7 +203,7 @@ def home(): query = query.filter(Plant.care_difficulty_id == care_difficulty_id) if growth_rate_id: query = query.filter(Plant.growth_rate_id == growth_rate_id) - if section_id and hasattr(Plant, 'section_id'): + if section_id: query = query.filter(Plant.section_id == section_id) plants = query.order_by(Plant.date_added.desc()).all() @@ -221,6 +221,7 @@ def home(): product_names.append(products_dict[int(pid)]) climate_info = climates_dict.get(plant.climate_id, {'name': '', 'icon': None, 'description': ''}) environment_info = environments_dict.get(plant.environment_id, {'name': '', 'icon': None, 'description': ''}) + display_plants.append({ 'id': plant.id, 'name': plant.name, @@ -249,26 +250,28 @@ def home(): 'growth_rate': plant.growth_rate.name if plant.growth_rate else '', 'growth_rate_icon': plant.growth_rate.icon if plant.growth_rate and plant.growth_rate.icon else None, 'growth_rate_description': plant.growth_rate.description if plant.growth_rate else '', + 'section': plant.section }) return render_template('home.html', - plants=display_plants, - climates=Climate.query.all(), - environments=Environment.query.all(), - lights=Light.query.order_by(Light.name).all(), - toxicities=Toxicity.query.order_by(Toxicity.name).all(), - sizes=Size.query.order_by(Size.name).all(), - difficulties=CareDifficulty.query.order_by(CareDifficulty.name).all(), - growth_rates=GrowthRate.query.order_by(GrowthRate.name).all(), - search=search, - selected_climate=climate_id, - selected_environment=environment_id, - selected_light=light_id, - selected_toxicity=toxicity_id, - selected_size=size_id, - selected_care_difficulty=care_difficulty_id, - selected_growth_rate=growth_rate_id - ) + plants=display_plants, + climates=Climate.query.all(), + environments=Environment.query.all(), + lights=Light.query.all(), + toxicities=Toxicity.query.all(), + sizes=Size.query.all(), + difficulties=CareDifficulty.query.all(), + growth_rates=GrowthRate.query.all(), + sections=Section.query.all(), + search=search, + selected_climate=climate_id, + selected_environment=environment_id, + selected_light=light_id, + selected_toxicity=toxicity_id, + selected_size=size_id, + selected_care_difficulty=care_difficulty_id, + selected_growth_rate=growth_rate_id, + selected_section=section_id) @app.route('/login', methods=['GET', 'POST']) def login(): @@ -624,6 +627,7 @@ def edit_plant(plant_id): sizes = Size.query.order_by(Size.name).all() difficulties = CareDifficulty.query.order_by(CareDifficulty.name).all() growth_rates = GrowthRate.query.order_by(GrowthRate.name).all() + sections = Section.query.order_by(Section.name).all() if request.method == 'POST': plant.name = request.form['name'] @@ -634,6 +638,7 @@ def edit_plant(plant_id): plant.size_id = request.form.get('size_id') plant.care_difficulty_id = request.form.get('care_difficulty_id') plant.growth_rate_id = request.form.get('growth_rate_id') + plant.section_id = request.form.get('section_id') plant.products = ','.join(request.form.getlist('product_ids')) plant.description = request.form['description'] plant.care_guide = request.form.get('care_guide') @@ -661,7 +666,8 @@ def edit_plant(plant_id): toxicities=toxicities, sizes=sizes, difficulties=difficulties, - growth_rates=growth_rates) + growth_rates=growth_rates, + sections=sections) @app.route('/plant/delete/', methods=['POST']) def delete_plant(plant_id): diff --git a/templates/edit_plant.html b/templates/edit_plant.html index d3609b5..8667d08 100644 --- a/templates/edit_plant.html +++ b/templates/edit_plant.html @@ -21,6 +21,16 @@ {% endif %}
+
+ + +
+ Clear
@@ -67,7 +73,7 @@ } const form = document.getElementById('plant-filter-form'); const searchInput = document.getElementById('search'); - const selects = [document.getElementById('climate'), document.getElementById('environment'), document.getElementById('light'), document.getElementById('toxicity'), document.getElementById('size'), document.getElementById('care_difficulty'), document.getElementById('growth_rate')]; + const selects = [document.getElementById('climate'), document.getElementById('environment'), document.getElementById('light'), document.getElementById('toxicity'), document.getElementById('size'), document.getElementById('care_difficulty'), document.getElementById('growth_rate'), document.getElementById('section')]; // Auto-submit on select change selects.forEach(sel => sel.addEventListener('change', () => form.submit())); @@ -103,7 +109,17 @@ {% endif %}

{{ plant.name }}

+ {% if plant.section %} +
+ Section: {{ plant.section.name }} +
+ {% endif %}
+ + {% if plant.climate_icon %} Climate icon diff --git a/templates/manage_plants.html b/templates/manage_plants.html index a9f31ad..d785dbf 100644 --- a/templates/manage_plants.html +++ b/templates/manage_plants.html @@ -126,8 +126,6 @@ Name - Climate - Environment Added Actions @@ -136,8 +134,6 @@ {% for plant in plants %} {{ plant.name }} - {{ climates[plant.climate_id] if plant.climate_id in climates else '' }} - {{ environments[plant.environment_id] if plant.environment_id in environments else '' }} Edit diff --git a/templates/post.html b/templates/post.html index 04366a8..c9a3db0 100644 --- a/templates/post.html +++ b/templates/post.html @@ -14,6 +14,11 @@

{{ plant.name }}

+ {% if plant.section %} +
+ Section: {{ plant.section.name }} +
+ {% endif %}
{% if plant.climate %} @@ -92,6 +97,12 @@ class="inline-block bg-[#6b8f71] text-white hover:bg-[#4e6b50] font-semibold px-6 py-2 rounded-lg shadow transition-colors duration-200"> 🌱 View Similar Plants + {% if plant.section %} + + 📚 View Plants in this Section + + {% endif %} ← Back to Home