File size: 3,035 Bytes
ab028ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/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()