Spaces:
Sleeping
Sleeping
Update utils.py
Browse files
utils.py
CHANGED
@@ -237,30 +237,44 @@ def generate_follow_up_questions(idea_form: IdeaForm, current_stage: int) -> Lis
|
|
237 |
|
238 |
return questions
|
239 |
|
240 |
-
def
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
264 |
|
265 |
def load_idea_from_database(idea_id: int, db: Session) -> Optional[IdeaForm]:
|
266 |
"""
|
@@ -285,18 +299,6 @@ def load_idea_from_database(idea_id: int, db: Session) -> Optional[IdeaForm]:
|
|
285 |
)
|
286 |
return None
|
287 |
|
288 |
-
def update_idea_in_database(idea_id: int, form: IdeaForm, db: Session) -> bool:
|
289 |
-
"""
|
290 |
-
Updates an existing idea in the database.
|
291 |
-
"""
|
292 |
-
db_idea = db.query(InnovativeIdea).filter(InnovativeIdea.id == idea_id).first()
|
293 |
-
if db_idea:
|
294 |
-
for field, value in form.dict(exclude_unset=True).items():
|
295 |
-
setattr(db_idea, field, value)
|
296 |
-
db.commit()
|
297 |
-
return True
|
298 |
-
return False
|
299 |
-
|
300 |
def extract_search_query(message: str) -> Optional[str]:
|
301 |
"""
|
302 |
Extract a search query from a user message if it starts with '@'.
|
|
|
237 |
|
238 |
return questions
|
239 |
|
240 |
+
def update_idea_in_database(idea_id: int, form: IdeaForm, db: Session) -> bool:
|
241 |
+
try:
|
242 |
+
db_idea = db.query(InnovativeIdea).filter(InnovativeIdea.id == idea_id).first()
|
243 |
+
if db_idea:
|
244 |
+
for field, value in form.dict(exclude_unset=True).items():
|
245 |
+
setattr(db_idea, field, value)
|
246 |
+
db.commit()
|
247 |
+
return True
|
248 |
+
except Exception as e:
|
249 |
+
db.rollback()
|
250 |
+
logging.error(f"Error updating idea in database: {str(e)}")
|
251 |
+
return False
|
252 |
+
|
253 |
+
def save_idea_to_database(form: IdeaForm, db: Session) -> Optional[int]:
|
254 |
+
try:
|
255 |
+
db_idea = InnovativeIdea(
|
256 |
+
idea_name=form.idea_name,
|
257 |
+
idea_overview=form.idea_overview,
|
258 |
+
problem_solution=form.problem_solution,
|
259 |
+
target_customers=form.target_customers,
|
260 |
+
market_value=form.market_value,
|
261 |
+
existing_solutions=form.existing_solutions,
|
262 |
+
unique_value=form.unique_value,
|
263 |
+
technical_challenges=form.technical_challenges,
|
264 |
+
legal_barriers=form.legal_barriers,
|
265 |
+
data_dependencies=form.data_dependencies,
|
266 |
+
team_roles=','.join(form.team_roles) if form.team_roles else None,
|
267 |
+
timeline=form.timeline,
|
268 |
+
additional_info=form.additional_info
|
269 |
+
)
|
270 |
+
db.add(db_idea)
|
271 |
+
db.commit()
|
272 |
+
db.refresh(db_idea)
|
273 |
+
return db_idea.id
|
274 |
+
except Exception as e:
|
275 |
+
db.rollback()
|
276 |
+
logging.error(f"Error saving idea to database: {str(e)}")
|
277 |
+
return None
|
278 |
|
279 |
def load_idea_from_database(idea_id: int, db: Session) -> Optional[IdeaForm]:
|
280 |
"""
|
|
|
299 |
)
|
300 |
return None
|
301 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
302 |
def extract_search_query(message: str) -> Optional[str]:
|
303 |
"""
|
304 |
Extract a search query from a user message if it starts with '@'.
|