def download(request, format):
    if(request.method == 'POST' and request.POST['cvjson']):
    
        a = json.loads(request.POST['cvjson'], object_pairs_hook = OrderedDict, strict=False)
                    
        cv = Cv(
            title = a['title'],
            profile = escape( a['profile'].encode( "utf-8" ) ).replace("\n","<br/>"),
        )
        
        t_set = []
        e_set = []
        w_set = []
        d_set = []
        o_set = []
        
        if 'technology' in a:
            for x in a['technology']:
                t_set.append( 
                    Technology( 
                        title       = x['title'], 
                        data        = escape( x['data'].encode( "utf-8", "ignore" ) ).replace("\n","<br/>")
                    ) 
                )
        
        if 'experience' in a:
            for x in a['experience']:
                e_set.append( 
                    Experience( 
                        title       = x['title'], 
                        from_year   = x['years'], # Must fix this later
                        company     = x['company'],
                        description = escape( x['description'].encode( "utf-8" ) ).replace("\n","<br/>"),
                        techs       = x['techs'],
                    ) 
                )
        
        if 'workplace' in a:
            for x in a['workplace']:
                w_set.append( 
                    Workplace( 
                        title       = x['title'], 
                        from_year   = x['years'], # Must fix this later
                        company     = x['company'],
                        description = escape( x['description'].encode( "utf-8" ) ).replace("\n","<br/>"),
                    ) 
                )
        
        if 'education' in a:
            for x in a['education']:
                d_set.append( 
                    Education( 
                        title       = x['title'], 
                        from_year   = x['years'], # Must fix this later
                        school      = x['school'],
                        description = escape( x['description'].encode( "utf-8" ) ).replace("\n","<br/>"),
                    ) 
                )
        
        if 'other' in a:
            for x in a['other']:
                datalist = "<ul><li>" + escape(x['data']).replace('&lt;br/&gt;','</li><li>') + "</li></ul>"
                o_set.append( 
                    Other( 
                        title       = x['title'], 
                        data        = datalist.encode( "utf-8", "ignore" )
                    ) 
                )
        
        p = get_object_or_404(Person, pk=a['personid'])

        # In case this has changed in the detailview, we change this temporarily (this is not saved)
        # Use case might be if someone wants a different phone number or contact number because the CV is sent via an agency
        p.name = a['name']
        p.phone = a['phone']
        p.mail = a['mail']
    
        imgdata, imgsizecm = getImgData(p.image)

        languagecode = p.country()
        if not languagecode or a['lang'] == 'en':
            languagecode = 'en'
            
        l = labels[languagecode]

        info = []
        if a['phone']:
            info.append(l['phone']+': '+a['phone'])
        if a['mail']:
            info.append(l['email']+': '+a['mail'])
        if a['age']: 
            info.append( '%s: %s' % (l['age'], a['age']) )
        if a['years_of_experience']: 
            info.append( '%s: %s' % (l['years_of_experience'], a['years_of_experience']) )
        infoline = '<text:p text:style-name="P1">' + '<text:line-break></text:line-break>'.join(info) + '</text:p>'

        dictionary = {
            'l': l,
            'a': a, # Contains age (as it is calculated and don't need special encoding - Also, it doesn't exist in the model :-/ )
            'p': p, # Person-related data
            'c': cv, # CV-related data
            't': t_set, 
            'e': e_set,
            'w': w_set, 
            'd': d_set, 
            'o': o_set,
            'infoline': infoline,
            'img': imgdata,
            'imgsizecm': imgsizecm,
            'acs_datestamp': datetime.today().strftime('%Y-%m-%d'),
        }

        templateId = a.get('template', 'default')

    elif(request.GET['cvid']):
        dictionary = getCvDictionary(request.GET['cvid'])
        templateId = request.GET.get('template', 'default')

    if templateId != 'default':
        template = get_object_or_404(Template, pk=templateId)
        template = template.template.path
    else:
        template = DEFAULT_TEMPLATE
    
    rsltFile = renderOdt(dictionary, template=template)
    filename = dictionary['p'].name.encode('ascii', 'ignore') + ' - ' + dictionary['c'].title.encode('ascii', 'ignore').replace(",","") + "_Altran"

    if format == "odt":
        response = HttpResponse( open(rsltFile, 'rb').read(), mimetype='application/vnd.oasis.opendocument.text' )
        response['Content-Disposition'] = 'attachment; filename=%s.odt' % filename
        return response
    else:
        return rtr('tempcv.odt', filename='%s.%s' % (filename, format), format=format)
Esempio n. 2
0
def download(request, format):

	if(request.POST['cvjson']):

		a = json.loads(request.POST['cvjson'], object_pairs_hook = odict.OrderedDict, strict=False)

		p = Person(
			name = a['name'],
			phone = a['phone'],
			mail = a['mail'],
		)

		c = Cv(
			title = a['title'],
			profile = a['profile'].encode('utf-8'),
		)

		try:
			imgUrl = settings.PROJECT_ROOT + a['photo']
			f = open(imgUrl, 'r')
			data = f.read()
			f.close()
		except:
			imgUrl = settings.PROJECT_ROOT + '/static/media/photos/blank.jpg'
			f = open(imgUrl, 'r')
			data = f.read()
			f.close()

		t_set = []
		e_set = []
		w_set = []
		d_set = []
		o_set = []

		if 'technology' in a:
			for x, item in a['technology'].items():
				t_set.append(
					Technology(
						title		= item['title'],
						data		= item['data'].replace('<br/>', '\n\r').encode('utf-8')
					)
				)

		if 'experience' in a:
			for x in a['experience']:
				e_set.append(
					Experience(
						title		= x['title'],
						from_year	= x['years'] or '',
						company		= x['company'],
						description = x['description'].encode('utf-8'),
						techs		= x['techs'],
					)
				)

		if 'workplace' in a:
			for x in a['workplace']:
				w_set.append(
					Workplace(
						title		= x['title'],
						from_year	= x['years'] or '',
						company		= x['company'],
						description = x['description'].encode('utf-8'),
					)
				)

		if 'education' in a:
			for x in a['education']:
				d_set.append(
					Education(
						title		= x['title'],
						from_year	= x['years'] or '',
						school		= x['school'],
						description = x['description'].encode('utf-8'),
					)
				)

		if 'other' in a:
			for x, item in a['other'].items():
				datalist = "<ul><li>" + item['data'].replace('<br/>','</li><li>') + "</li></ul>"
				o_set.append(
					Other(
						title		= item['title'],
						data		= datalist.encode('utf-8')
					)
				)

		dict = {
			'l': {
				'profile': 'Profil',
				'experience': 'Erfaring',
				'workplace': 'Arbeidsgivere',
				'education': 'Utdanning'
			},
			'a': a, # Contains age (as it is calculated and don't need special encoding - Also, it doesn't exist in the model :-/ )
			'p': p, # Person-related data
			'c': c, # CV-related data
			't': t_set,
			'e': e_set,
			'w': w_set,
			'd': d_set,
			'o': o_set,
			'img': data,
		}

	#else:
		#get cvid from url and render the entire set of stuff from cv?

	doc = ''
	if format != 'odt': doc = 'doc'

	srcFile = settings.PROJECT_ROOT + '/cv/cvjsontest%s.odt' % doc

	rsltFile = '/tmp/%s.odt' % p.name.encode('ascii', 'ignore')
	r = Renderer(srcFile, dict, rsltFile, overwriteExisting=True)
	r.run()
	if format == "odt":
		response = HttpResponse(open(rsltFile, 'rb').read(), mimetype='application/vnd.oasis.opendocument.text')
		response['Content-Disposition'] = 'attachment; filename=%s %s Inonit CV.odt' % (p.name.encode('ascii', 'ignore'), c.title.encode('ascii', 'ignore').replace(" ", "_"))
		return response
	else:
		return rtr(p.name.encode('ascii', 'ignore')+'.odt', filename='%s %s Inonit CV.%s' % (p.name.encode('ascii', 'ignore'), c.title.encode('ascii', 'ignore').replace(" ", "_"), format), format=format)
Esempio n. 3
0
def download(request, format):
    if (request.method == 'POST' and request.POST['cvjson']):

        a = json.loads(request.POST['cvjson'],
                       object_pairs_hook=OrderedDict,
                       strict=False)

        cv = Cv(
            title=a['title'],
            profile=escape(a['profile'].encode("utf-8")).replace(
                "\n", "<br/>"),
        )

        t_set = []
        e_set = []
        w_set = []
        d_set = []
        o_set = []

        if 'technology' in a:
            for x in a['technology']:
                t_set.append(
                    Technology(title=x['title'],
                               data=escape(x['data'].encode(
                                   "utf-8", "ignore")).replace("\n", "<br/>")))

        if 'experience' in a:
            for x in a['experience']:
                e_set.append(
                    Experience(
                        title=x['title'],
                        from_year=x['years'],  # Must fix this later
                        company=x['company'],
                        description=escape(
                            x['description'].encode("utf-8")).replace(
                                "\n", "<br/>"),
                        techs=x['techs'],
                    ))

        if 'workplace' in a:
            for x in a['workplace']:
                w_set.append(
                    Workplace(
                        title=x['title'],
                        from_year=x['years'],  # Must fix this later
                        company=x['company'],
                        description=escape(
                            x['description'].encode("utf-8")).replace(
                                "\n", "<br/>"),
                    ))

        if 'education' in a:
            for x in a['education']:
                d_set.append(
                    Education(
                        title=x['title'],
                        from_year=x['years'],  # Must fix this later
                        school=x['school'],
                        description=escape(
                            x['description'].encode("utf-8")).replace(
                                "\n", "<br/>"),
                    ))

        if 'other' in a:
            for x in a['other']:
                datalist = "<ul><li>" + escape(x['data']).replace(
                    '&lt;br/&gt;', '</li><li>') + "</li></ul>"
                o_set.append(
                    Other(title=x['title'],
                          data=datalist.encode("utf-8", "ignore")))

        p = get_object_or_404(Person, pk=a['personid'])

        # In case this has changed in the detailview, we change this temporarily (this is not saved)
        # Use case might be if someone wants a different phone number or contact number because the CV is sent via an agency
        p.name = a['name']
        p.phone = a['phone']
        p.mail = a['mail']

        imgdata, imgsizecm = getImgData(p.image)

        languagecode = p.country()
        if not languagecode or a['lang'] == 'en':
            languagecode = 'en'

        l = labels[languagecode]

        info = []
        if a['phone']:
            info.append(l['phone'] + ': ' + a['phone'])
        if a['mail']:
            info.append(l['email'] + ': ' + a['mail'])
        if a['age']:
            info.append('%s: %s' % (l['age'], a['age']))
        if a['years_of_experience']:
            info.append('%s: %s' %
                        (l['years_of_experience'], a['years_of_experience']))
        infoline = '<text:p text:style-name="P1">' + '<text:line-break></text:line-break>'.join(
            info) + '</text:p>'

        dictionary = {
            'l': l,
            'a':
            a,  # Contains age (as it is calculated and don't need special encoding - Also, it doesn't exist in the model :-/ )
            'p': p,  # Person-related data
            'c': cv,  # CV-related data
            't': t_set,
            'e': e_set,
            'w': w_set,
            'd': d_set,
            'o': o_set,
            'infoline': infoline,
            'img': imgdata,
            'imgsizecm': imgsizecm,
            'acs_datestamp': datetime.today().strftime('%Y-%m-%d'),
        }

        templateId = a.get('template', 'default')

    elif (request.GET['cvid']):
        dictionary = getCvDictionary(request.GET['cvid'])
        templateId = request.GET.get('template', 'default')

    if templateId != 'default':
        template = get_object_or_404(Template, pk=templateId)
        template = template.template.path
    else:
        template = DEFAULT_TEMPLATE

    rsltFile = renderOdt(dictionary, template=template)
    filename = dictionary['p'].name.encode(
        'ascii', 'ignore') + ' - ' + dictionary['c'].title.encode(
            'ascii', 'ignore').replace(",", "") + "_Altran"

    if format == "odt":
        response = HttpResponse(
            open(rsltFile, 'rb').read(),
            mimetype='application/vnd.oasis.opendocument.text')
        response[
            'Content-Disposition'] = 'attachment; filename=%s.odt' % filename
        return response
    else:
        return rtr('tempcv.odt',
                   filename='%s.%s' % (filename, format),
                   format=format)