Spaces:
Configuration error
Configuration error
| #!/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() |