File size: 6,009 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env python3
"""
Test PDF generation with actual user data.
"""

from models import db, User, Introduction, ProfileSummary, WorkExperience, Project, Education, Skill, Achievement, ProfileSectionOrder
from app import app
from pdf_generator import create_pdf_resume
import calendar

def test_with_actual_data():
    """Test PDF generation with actual user data."""
    
    with app.app_context():
        # Get user with profile
        user = User.query.filter_by(email='[email protected]').first()
        if not user:
            print("User [email protected] not found")
            return
        
        print(f"Testing PDF generation for user: {user.email}")
        
        # Get profile data
        intro = Introduction.query.filter_by(user_id=user.id).first()
        summary = ProfileSummary.query.filter_by(user_id=user.id).first()
        work_experiences = WorkExperience.query.filter_by(user_id=user.id).order_by(WorkExperience.order).all()
        projects = Project.query.filter_by(user_id=user.id).order_by(Project.order).all()
        educations = Education.query.filter_by(user_id=user.id).order_by(Education.order).all()
        skills = Skill.query.filter_by(user_id=user.id).order_by(Skill.order).all()
        achievements = Achievement.query.filter_by(user_id=user.id).order_by(Achievement.order).all()
        
        # Get section order
        section_order_obj = ProfileSectionOrder.query.filter_by(user_id=user.id).first()
        section_order = section_order_obj.section_order if section_order_obj else [
            'introduction', 'profile_summary', 'work_experience', 
            'projects', 'education', 'skills', 'achievements'
        ]
        
        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 data for PDF generation
        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 ''
            })
        
        projects_list = []
        for proj in projects:
            start_date = format_date(proj.start_month, proj.start_year)
            end_date = "Present" if not proj.end_month or not proj.end_year else format_date(proj.end_month, proj.end_year)
            
            projects_list.append({
                'title': proj.title,
                'organization': proj.organization,
                'start_date': start_date,
                'end_date': end_date,
                'remarks': proj.remarks or ''
            })
        
        education_list = []
        for edu in educations:
            start_date = format_date(edu.start_month, edu.start_year)
            end_date = "Present" if not edu.end_month or not edu.end_year else format_date(edu.end_month, edu.end_year)
            
            education_list.append({
                'title': edu.title,
                'organization': edu.organization,
                'start_date': start_date,
                'end_date': end_date,
                'remarks': edu.remarks or ''
            })
        
        # Convert skills and achievements to comma-separated strings
        skills_text = ', '.join([skill.skill for skill in skills]) if skills else ''
        achievements_text = ', '.join([achievement.achievement for achievement in achievements]) if achievements else ''
        
        # Create data dictionary
        data = {
            'name': intro.name,
            'email': intro.email,
            'phone': intro.phone,
            'linkedin': intro.linkedin,
            'github': intro.github,
            'website': intro.website,
            'summary': summary.summary if summary else '',
            'work_experience': work_exp_list,
            'projects': projects_list,
            'education': education_list,
            'skills': skills_text,
            'achievements': achievements_text,
            'sections_order': section_order
        }
        
        print("Data prepared:")
        print(f"  Name: {data['name']}")
        print(f"  Work experiences: {len(work_exp_list)}")
        print(f"  Projects: {len(projects_list)}")
        print(f"  Education: {len(education_list)}")
        print(f"  Skills: {skills_text}")
        print(f"  Achievements: {achievements_text}")
        
        # Test PDF generation
        try:
            print("\nGenerating standard PDF...")
            pdf_bytes = create_pdf_resume(data, "standard")
            if pdf_bytes:
                with open('test_user_standard.pdf', 'wb') as f:
                    f.write(pdf_bytes)
                print("SUCCESS: Standard PDF generated successfully: test_user_standard.pdf")
            else:
                print("✗ Failed to generate standard PDF")
            
            print("\nGenerating modern PDF...")
            pdf_bytes = create_pdf_resume(data, "modern")
            if pdf_bytes:
                with open('test_user_modern.pdf', 'wb') as f:
                    f.write(pdf_bytes)
                print("SUCCESS: Modern PDF generated successfully: test_user_modern.pdf")
            else:
                print("FAILED: Failed to generate modern PDF")
                
        except Exception as e:
            print(f"Error: {str(e)}")
            import traceback
            traceback.print_exc()

if __name__ == "__main__":
    test_with_actual_data()