예제 #1
0
def saveResume(user, resume_text, resume_html_style='', resume_html_formatter='', original=True):
    try:
        #safety first, filter the html
        if original:
            resume_text = hotmetal.filter(resume_text)
        
        resume_dir = user.resume_dir
        if not resume_dir:
            #if user.resume_dir is null, we need to fill it up
            resume_dir = getResumeDir()
            user.resume_dir = resume_dir
        
        success, resume_html_body, masked_html_body = saveResumeHtml(user, resume_dir, resume_text, resume_html_style, resume_html_formatter)
        if not success:
            return False
        
        #Writing to plain text resume file
        #beautiful-soup gives unicode, dammit! :) need to u => ascii
        html_text = html2text.html2text(resume_html_body)        
        update_success = updatePlainTextResume(user, html_text)
        if not update_success:
            return False
        
        cleaned_up_preview_text = cleanUpPreviewText(html2text.html2text(masked_html_body))
        
        #store stuff in hilite and small_desc
        if dataplus.isNullOrEmpty(user.personal_desc):
            user.hilite = dataplus.getPreviewText(cleaned_up_preview_text, 512)
            user.small_desc = dataplus.getPreviewText(cleaned_up_preview_text, 256)
        
        if original:
            settings = models.UserSettings.objects.get(user=user)
            if settings.original_resume_format != 'doc':
                call(['rm',resume_dir + '/' + user.username + '.doc'])
                call(['rm',resume_dir + '/' + user.username + '-masked.doc'])
            
            settings.original_resume_format = 'html'
            settings.available_resume_download_formats = 'html'
            if not settings.resume_download_format_set:
                settings.preferred_resume_download_format = 'pdf'
            settings.save()
            
        user.resume_update_time = datetime.utcnow()
        user.save()        
        
        return True
    except:
        logError('Save resume failed for user:'******': ' + str(sys.exc_info()[0]) + ', ' + str(sys.exc_info()[1]))
        return False
예제 #2
0
def updatePlainTextResume(user, html_text=None):
    try:
        if not user.resume_dir:
            #if user.resume_dir is null, we need to fill it up
            user.resume_dir = getResumeDir()
        
        textfile_path = user.resume_dir + '/' + user.username + '.txt'
                
        if not html_text:
            soup = BeautifulSoup('<html><body>' + user.resume_contents.text + '</body></html>')
            resume_html = soup.prettify()
            
            #beautiful-soup gives unicode, dammit! :) need to u => ascii
            html_text = html2text.html2text(resume_html)
            
        resume_plaintext = 'User: '******', Name: ' + user.name +   ' - ' + html_text
        if not dataplus.isNullOrEmpty(user.personal_desc):
            try:
                #TODO:fixme: this bombs when non-ascii chars live in user.personal_desc
                resume_plaintext += '\n' + user.personal_desc    
            except:
                pass
        
        resume_plaintext = dataplus.toAscii(resume_plaintext)
        try:
            textfile = open(textfile_path, 'w')
            textfile.write(resume_plaintext)
        except:
            logError('Writing Plain text resume file failed for user:'******': ' + str(sys.exc_info()[0]) + ', ' + str(sys.exc_info()[1]))
            return False
        finally:
            textfile.close()
        
        return True
    except:
        logError('Update plain text failed for user:'******': ' + str(sys.exc_info()[0]) + ', ' + str(sys.exc_info()[1]))
        return False