Пример #1
0
def saveResumeDoc(user, resume_dir, ext='.doc'):
    try:        
        html_created, html_formatter = codejar_resume.convertToXHtml(user, resume_dir + '/' + user.username + ext, resume_dir, ext)        
        if not html_created:
            return False, 'cannot_create_html'
        
        html_body, html_style = codejar_resume.extractBodyAndStyle(resume_dir + '/' + user.username + '.html', html_formatter)
        
        save_result = codejar_resume.saveResume(user, html_body, html_style, html_formatter, False)
        
        if save_result:
            format = ext[1:]
            settings = models.UserSettings.objects.get(user=user)
            settings.original_resume_format = format
            settings.available_resume_download_formats = 'html'
            if not settings.resume_download_format_set:
                if format == 'doc':
                    settings.preferred_resume_download_format = 'doc'
                elif format == 'odt':
                    settings.preferred_resume_download_format = 'pdf'
            settings.save()
            return True, 'ok'
        else:
            return False, 'unknown'
    except:
        return False, 'unknown'
Пример #2
0
def handle(request):
    myself = siteaction.getLoggedInUser(request)
    if not myself:
        return HttpResponseRedirect('/login.htm')
    
    if request.method == 'GET':
        action_result = ''
        if dataplus.dictGetVal(request.REQUEST, 'flashId'):
            action_result = dataplus.dictGetVal(statix.action_messages, dataplus.dictGetVal(request.REQUEST, 'flashId'), '')
        
        user_settings = models.UserSettings.objects.get(user=myself)
        action = dataplus.dictGetVal(request.REQUEST, 'action')
        redirected_from = dataplus.dictGetVal(request.REQUEST, 'from', 'edit')
        return_url = ''
        if redirected_from == 'profile':
            return_url = '/profiles/' + myself.username
        else:
            return_url = '/me/editresume.htm'
            
        if action == 'redo_html' or action == 'revert_html' or action == 'edit_html':
            if user_settings.original_resume_format =='doc':
                src_file_path = myself.resume_dir + '/' + myself.username + '.doc'
                target_file_path = myself.resume_dir + '/' + myself.username + '.html'
                if not (action == 'edit_html' and myself.resume_contents.html_formatter == 'abiword'):
                    if myself.resume_contents.html_formatter == 'abiword':
                        formatter = 'openoffice'
                        success = codejar_resume.convertWithOpenOffice(src_file_path, target_file_path, 'html')
                    elif myself.resume_contents.html_formatter == 'openoffice':
                        formatter = 'abiword'
                        success = codejar_resume.convertWithAbiword(src_file_path, 'html')
                    
                    if not success:
                        return HttpResponseRedirect('/me/previewresume.htm?flashId=cannot_create_html')
                        
                    html_body, html_style = codejar_resume.extractBodyAndStyle(target_file_path, formatter)
                    success, resume_html_body, masked_html_body = codejar_resume.saveResumeHtml(myself, myself.resume_dir, html_body, html_style, formatter)
                    if not success:
                        return HttpResponseRedirect('/me/previewresume.htm?flashId=cannot_create_html')
                
                if action == 'redo_html':
                    return HttpResponseRedirect('/me/previewresume.htm?flashId=resume_html_reformatted&action=preview&from=' + redirected_from)
                elif action == 'revert_html':
                    return HttpResponseRedirect('/me/previewresume.htm?flashId=resume_html_reverted&action=preview&from=' + redirected_from)
                elif action == 'edit_html':
                    return HttpResponseRedirect('/me/editresume.htm')
                
        else:       
            resume_html_text = myself.resume_contents.text
            resume_html_style = myself.resume_contents.html_style
            message = ''
            if action == 'preview':
                if dataplus.dictGetVal(request.REQUEST, 'flashId') == 'resume_html_reformatted':
                    next_action = 'revert_html'
                else:
                    next_action = 'redo_html'
                
                if user_settings.original_resume_format =='doc':
                    if next_action == 'redo_html':
                        message = '<h3>Are you OK with how your resume looks?</h3>\r\n<ul>' + \
                            '<li><a href="' + return_url + '?flashId=res_style_saved">Yes, It looks OK</a>.</li>' + \
                            '<li>No, This has problems. <a href="/me/previewresume.htm?action=redo_html&amp;from=' + redirected_from + '">Try to fix it</a>.</li></ul>'
                    else:
                        message = '<h3>Is it OK now?</h3>\r\n<ul>' + \
                            '<li><a href="' + return_url + '?flashId=res_style_saved">Yes, It looks fine</a>.</li>' + \
                            '<li>No, This is not working. <a href="/me/previewresume.htm?action=edit_html">I will edit it myself</a>.</li>' + \
                            '<li>No, <a href="/me/previewresume.htm?action=revert_html&amp;from=' + redirected_from + '">I prefer the previous one</a>.</li></ul>'
                        
                else:
                    message = '<h3>Are you OK with how your resume looks?</h3>\r\n<ul>' + \
                        '<li><a href="' + return_url + '?flashId=res_style_saved">Yes, It looks OK</a>.</li>' + \
                        '<li>No, <a href="/me/editresume.htm">I will edit it myself</a>.</li></ul>'
                
            return siteaction.render_to_response('me/previewresume.htm',
                {   'message' : message,
                    'resume_html_text':resume_html_text,
                    'resume_html_style':resume_html_style,
                    'action_result':action_result,
                    'myself': myself})