section improvements

This commit is contained in:
2025-06-08 17:23:47 +02:00
parent 9fcb9c358b
commit 26cdb90c3a
5 changed files with 63 additions and 24 deletions

44
app.py
View File

@@ -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/<int:plant_id>', methods=['POST'])
def delete_plant(plant_id):