Spaces:
Configuration error
Configuration error
| #!/usr/bin/env python3 | |
| """ | |
| Debug script to check database state and test PDF generation. | |
| """ | |
| from models import db, User, Introduction, WorkExperience, Project, Education, Skill, Achievement, ProfileSectionOrder | |
| from app import app | |
| import calendar | |
| def debug_user_profile(): | |
| """Debug user profile data.""" | |
| with app.app_context(): | |
| # Get first user (for testing) | |
| user = User.query.first() | |
| if not user: | |
| print("No users found in database") | |
| return | |
| print(f"Debugging profile for user: {user.email}") | |
| # Get profile data | |
| intro = Introduction.query.filter_by(user_id=user.id).first() | |
| if not intro: | |
| print("No introduction found") | |
| return | |
| print(f"Introduction: {intro.name}") | |
| # Get work experiences | |
| work_experiences = WorkExperience.query.filter_by(user_id=user.id).all() | |
| print(f"Work experiences: {len(work_experiences)}") | |
| for exp in work_experiences: | |
| print(f" - {exp.title} at {exp.organization} ({exp.start_month}/{exp.start_year} - {exp.end_month or 'Present'}/{exp.end_year or ''})") | |
| # Get projects | |
| projects = Project.query.filter_by(user_id=user.id).all() | |
| print(f"Projects: {len(projects)}") | |
| # Get education | |
| educations = Education.query.filter_by(user_id=user.id).all() | |
| print(f"Education: {len(educations)}") | |
| # Get skills | |
| skills = Skill.query.filter_by(user_id=user.id).all() | |
| print(f"Skills: {len(skills)}") | |
| for skill in skills: | |
| print(f" - {skill.skill}") | |
| # Get achievements | |
| achievements = Achievement.query.filter_by(user_id=user.id).all() | |
| print(f"Achievements: {len(achievements)}") | |
| for achievement in achievements: | |
| print(f" - {achievement.achievement}") | |
| # Test data preparation (same as in app.py) | |
| def format_date(month, year): | |
| """Format month and year as 'Month Year'""" | |
| if month and year: | |
| try: | |
| month_name = calendar.month_name[int(month)] | |
| return f"{month_name[:3]} {year}" | |
| except: | |
| return f"{month}/{year}" | |
| return "" | |
| # Prepare work experiences | |
| work_exp_list = [] | |
| for exp in work_experiences: | |
| start_date = format_date(exp.start_month, exp.start_year) | |
| end_date = "Present" if not exp.end_month or not exp.end_year else format_date(exp.end_month, exp.end_year) | |
| work_exp_list.append({ | |
| 'title': exp.title, | |
| 'organization': exp.organization, | |
| 'start_date': start_date, | |
| 'end_date': end_date, | |
| 'remarks': exp.remarks or '' | |
| }) | |
| print(f"Formatted work exp: {work_exp_list[-1]}") | |
| if __name__ == "__main__": | |
| debug_user_profile() |