def invio_fattura(request,f_id): f=Fattura.objects.get(id=f_id) azione = 'Invio' data = { 'mittente' : f.user.email, 'destinatario' : f.cliente.mail, } if f.user == request.user or request.user.is_superuser: if request.method == 'POST': form = FatturaInvioForm(request.POST, data,) #form.helper.form_action = 'fatture/invio/'+ str(f.id)+'/' if form.is_valid(): oggetto = form.cleaned_data['oggetto'] corpo = form.cleaned_data['messaggio'] email = EmailMessage(oggetto, corpo, form.cleaned_data['mittente'], [form.cleaned_data['destinatario']], headers = {'Reply-To': form.cleaned_data['mittente']}) template = webodt.ODFTemplate(f.template.template.name) context = dict( data=str(f.data), fattura=f, ) document = template.render(Context(context)) conv = converter() pdf = conv.convert(document, format='pdf') email.attach_file(pdf.name) return HttpResponseRedirect('/fatture/dettagli/'+str(f.id)) else: form = FatturaInvioForm(data) #form.helper.form_action = '/' return render_to_response('InvioFattura.html',{'request':request, 'form':form, }, RequestContext(request)) else: raise PermissionDenied
def send_email(self, request, *args, **kwargs): # TODO: Проверить, а также сделать from_email form = SendMailForm(request.POST or None, instance=self.invoice) if form.is_valid(): invoice = form.save() to = form.cleaned_data['org_email'] template = webodt.ODFTemplate(self.document_name) doc_context = {'invoice': invoice} document = template.render(Context(doc_context)) pdf = converter().convert(document, format='pdf') is_remind = kwargs.get('remind') conf = is_remind and self.remind_send_conf or self.one_send_conf subject = render_to_string( conf['template_name']['subject'], doc_context, ).strip() text_content = render_to_string( conf['template_name']['text'], doc_context, ).srtip() msg = EmailMultiAlternatives(subject, text_content, from_email, [to]) filename = self.attach_name_template.format(invoice.id) msg.attach(filename, pdf.read(), 'application/pdf') msg.send() messages.success(request, conf['success_message']) context = {'mail_form': form, 'invoice': invoice} return self.render_to_response(context)
def invio_documento(request,f_id): f = Documento.objects.get(id=f_id) azione = 'Invio' data = { 'mittente' : f.user.email, 'destinatario' : f.cliente.mail, } if request.method == 'POST': form = FatturaInvioForm(request.POST, data,) #form.helper.form_action = 'documenti/invio/'+ str(f.id)+'/' if form.is_valid(): oggetto = form.cleaned_data['oggetto'] corpo = form.cleaned_data['messaggio'] cc = [form.cleaned_data['cc_destinatario']] to = [form.cleaned_data['destinatario']] email = EmailMessage(oggetto, corpo, form.cleaned_data['mittente'], to,cc, headers = {'Reply-To': form.cleaned_data['mittente']}) template = webodt.ODFTemplate(f.template.template.name) context = dict( data=str(f.data), documento=f, ) document = template.render(Context(context)) conv = converter() pdf = conv.convert(document, format='pdf') email.attach_file(pdf.name) return HttpResponseRedirect(reverse('minimo.documento.views.documento', args=(str(f.id)))) else: form = FatturaInvioForm(data) #form.helper.form_action = '/' return render_to_response('documento/InvioDocumento.html',{'request':request, 'form':form, }, RequestContext(request))
def emitir_documento(nome_template, dados=dict()): template = webodt.ODFTemplate(nome_template) document = template.render(Context(dados)) conv = converter() pdf = conv.convert(document, format='pdf') document.close() return HttpResponse(pdf, mimetype='application/pdf')
def render_to(format, template_name, dictionary=None, context_instance=None, delete_on_close=True, cache=CacheManager, preprocessors=None): """ Convert the template given by `template_name` and `dictionary` to a document in given `format`. The document (file-like object) will be returned. `format` is the filename extension. It's possible to use "odt", "pdf", "doc", "html" or "rtf" and probably more. `context_instance` is the optional parameter which should contain instance of the subclass of `django.template.Context`. `delete_on_close` defines whether the returned document should be deleted automatically when closed. `preprocessors` is a list of preprocessors overriding ``WEBODT_ODF_TEMPLATE_PREPROCESSORS`` settings variable. Suitable for ODF documents only. If the `template_name` ends with `.html`, template is considered as HTML template, otherwise as ODF based template. """ template = _Template(template_name, preprocessors=preprocessors) dictionary = dictionary or {} if context_instance: context_instance.update(dictionary) else: context_instance = Context(dictionary) document = template.render(context_instance, delete_on_close=delete_on_close) if format == 'odt': return document formatted_document = None if cache: cache_mgr = cache() formatted_document = cache_mgr.get(document, format) if not formatted_document: formatted_document = converter().convert( document, format, delete_on_close=delete_on_close) cache_mgr.set(document, format, formatted_document) document.close() return formatted_document
def render_to(format, template_name, dictionary=None, context_instance=None, delete_on_close=True, cache=CacheManager, preprocessors=None ): """ Convert the template given by `template_name` and `dictionary` to a document in given `format`. The document (file-like object) will be returned. `format` is the filename extension. It's possible to use "odt", "pdf", "doc", "html" or "rtf" and probably more. `context_instance` is the optional parameter which should contain instance of the subclass of `django.template.Context`. `delete_on_close` defines whether the returned document should be deleted automatically when closed. `preprocessors` is a list of preprocessors overriding ``WEBODT_ODF_TEMPLATE_PREPROCESSORS`` settings variable. Suitable for ODF documents only. If the `template_name` ends with `.html`, template is considered as HTML template, otherwise as ODF based template. """ template = _Template(template_name, preprocessors=preprocessors) dictionary = dictionary or {} if context_instance: context_instance.update(dictionary) else: context_instance = Context(dictionary) document = template.render(context_instance, delete_on_close=delete_on_close) if format == 'odt': return document formatted_document = None if cache: cache_mgr = cache() formatted_document = cache_mgr.get(document, format) if not formatted_document: formatted_document = converter().convert(document, format, delete_on_close=delete_on_close) cache_mgr.set(document, format, formatted_document) document.close() return formatted_document
def stampa_fattura(request,f_id): f=F.objects.get(id=f_id) #pdb.set_trace() #f.template template = webodt.ODFTemplate(f.template.template.name) context = dict( data=str(f.data), fattura=f, cliente=f.cliente, prestazioni=f.prestazione_fattura.all(), ) document = template.render(Context(context)) conv = converter() pdf = conv.convert(document, format='pdf') #return render_to_response( 'modello_fattura.html', {'request':request, 'f': f}) response = HttpResponse(pdf, mimetype='application/pdf') response['Content-Disposition'] = 'attachment; filename=Fattura-%s.pdf' % (f) return response
def invio_fattura(request, f_id): f = Fattura.objects.get(id=f_id) azione = 'Invio' data = { 'mittente': f.user.email, 'destinatario': f.cliente.mail, } if f.user == request.user or request.user.is_superuser: if request.method == 'POST': form = FatturaInvioForm( request.POST, data, ) #form.helper.form_action = 'fatture/invio/'+ str(f.id)+'/' if form.is_valid(): oggetto = form.cleaned_data['oggetto'] corpo = form.cleaned_data['messaggio'] email = EmailMessage( oggetto, corpo, form.cleaned_data['mittente'], [form.cleaned_data['destinatario']], headers={'Reply-To': form.cleaned_data['mittente']}) template = webodt.ODFTemplate(f.template.template.name) context = dict( data=str(f.data), fattura=f, ) document = template.render(Context(context)) conv = converter() pdf = conv.convert(document, format='pdf') email.attach_file(pdf.name) return HttpResponseRedirect('/fatture/dettagli/' + str(f.id)) else: form = FatturaInvioForm(data) #form.helper.form_action = '/' return render_to_response('InvioFattura.html', { 'request': request, 'form': form, }, RequestContext(request)) else: raise PermissionDenied
def stampa_fattura(request,f_id): f=Fattura.objects.get(id=f_id) if f.user == request.user or request.user.is_superuser: #pdb.set_trace() #f.template template = webodt.ODFTemplate(f.template.template.name) context = dict( data=str(f.data), fattura=f, ) document = template.render(Context(context)) conv = converter() pdf = conv.convert(document, format='pdf') #return render_to_response( 'modello_fattura.html', {'request':request, 'f': f}) response = HttpResponse(pdf, mimetype='application/pdf') response['Content-Disposition'] = 'attachment; filename=Fattura-%s-%s.pdf' % (f.progressivo(),f.data.year) return response else: raise PermissionDenied
def stampa_fattura(request, f_id): f = Fattura.objects.get(id=f_id) if f.user == request.user or request.user.is_superuser: #pdb.set_trace() #f.template template = webodt.ODFTemplate(f.template.template.name) context = dict( data=str(f.data), fattura=f, ) document = template.render(Context(context)) conv = converter() pdf = conv.convert(document, format='pdf') #return render_to_response( 'modello_fattura.html', {'request':request, 'f': f}) response = HttpResponse(pdf, mimetype='application/pdf') response[ 'Content-Disposition'] = 'attachment; filename=Fattura-%s-%s.pdf' % ( f.progressivo(), f.data.year) return response else: raise PermissionDenied
def stampa_documento(request,f_id): f = Documento.objects.get(id=f_id) template = webodt.ODFTemplate(f.template.template.name) context = dict( data=str(f.data), fattura=f, ) document = template.render(Context(context)) conv = converter() pdf = conv.convert(document, format='pdf') #return render_to_response( 'modello_documento.html', {'request':request, 'f': f}) response = HttpResponse(pdf, mimetype='application/pdf') if f.tipo == 'RA': response['Content-Disposition'] = 'attachment; filename=RitenutaAcconto-%s-%s.pdf' % (f.progressivo(),f.data.year) if f.tipo == 'FA': response['Content-Disposition'] = 'attachment; filename=Fattura-%s-%s.pdf' % (f.progressivo(),f.data.year) if f.tipo == 'PR': response['Content-Disposition'] = 'attachment; filename=Offerta-%s-%s.pdf' % (f.progressivo(),f.data.year) if f.tipo == 'OR': response['Content-Disposition'] = 'attachment; filename=Ordine-%s-%s.pdf' % (f.progressivo(),f.data.year) return response
def setUp(self): self.cache_manager = CacheManager() self.converter = converter()
def setUp(self): self.cache_manager = CacheManager() self.converter = converter()
#! coding: utf-8 from django.conf import settings from django.views.generic import CreateView from django.core.mail import send_mail from django.utils.translation import activate activate('en') from django.template import Context import webodt from webodt.converters import converter conv = converter() # from feedback_app.models import Contact, ContactForm import num2t4ru from num2t4ru import num2text # # class ContactCreateView(CreateView): form_class = ContactForm template_name = 'feedback_app/form.html' success_url = '/thanks/' # def form_valid(self, form): message = '{product_name} / {quarter} написал: '.format( product_name=form.cleaned_data.get('product_name').encode('utf-8'), quarter=form.cleaned_data.get('quarter'), num_contract=form.cleaned_data.get('num_contract'), contract_date=form.cleaned_data.get('contract_date').encode( 'utf-8'),
def get_questions_list(request): if not request.method == "POST": return HttpResponseNotFound("Not found") if not request.POST.get("mo"): return HttpResponseBadRequest("No mo name") context = {'title': u'Бланк опроса'} mo = MO.objects.filter(name=request.POST['mo'])[0] context['mo'] = mo form = QuestionsListForm(mo, request.POST) if not form.is_valid(): request.session['wrong_post'] = request.POST.copy() return HttpResponseRedirect(reverse('questions-list-form')) context['responsible_person'] = request.POST.get('responsible_person') context['list_sent_to_mo'] = request.POST.get('list_sent_to_mo') context['objects_equal'] = request.POST.get('objects_equal') context['persons_list'] = [] context['building_forms'] = [] for p in request.POST.getlist('persons_list'): context['persons_list'].append(Person.objects.get(pk=p)) # is there a building with payment perpective is_perspective = [p for p in Building.objects.all().values("payment_perspective" ,) if p.get("payment_perspective") != 2] context['perspective'] = 0 if is_perspective: context['perspective'] = 1 context['perspective_forms'] = [] context['contract_cmp_data'] = [] context['perspective_cmp_data'] = [] # pass forms and formsts for perspective buildings to template via dicts in array for building in Building.objects.filter(mo=mo, payment_perspective=1): object_form = BuildingForm(instance=building) room_f, hallway_f, wc_f, kitchen_f = get_fk_forms(parent=building) object_formsets = [room_f, hallway_f, wc_f, kitchen_f] context['perspective_forms'].append({object_form: object_formsets}) # get only last cmp form for displaying if building.result_set: if building.result_set.order_by('cmp_data__cmp_date'): last_cmp = building.result_set.order_by('cmp_data__cmp_date')[0] last_cmp_form = ResultForm(instance=last_cmp) context['perspective_cmp_data'].append({building.pk: last_cmp_form}) # auction always should be auction = Auction.objects.get(pk=request.POST['auction']) auction_form = AuctionForm(instance=auction) context["auction"] = auction context["auction_form"] = auction_form room_f, hallway_f, wc_f, kitchen_f = get_fk_forms(parent=auction) if auction.contract: contract = auction.contract contract_form = ContractForm(instance=contract) # pass forms and formsts for contract building to template via dicts in array for building in Building.objects.filter(contract=contract): object_form = BuildingForm(instance=building) room_f, hallway_f, wc_f, kitchen_f = get_fk_forms(parent=building) object_formsets = [room_f, hallway_f, wc_f, kitchen_f] context['building_forms'].append({object_form: object_formsets}) print context['building_forms'] # get only last cmp form for displaying if building.result_set: if building.result_set.order_by('cmp_data__cmp_date'): last_cmp = building.result_set.order_by('cmp_data__cmp_date')[0] last_cmp_form = ResultForm(instance=last_cmp) context['contract_cmp_data'].append({building.pk: last_cmp_form}) context["contract"] = contract context["contract_form"] = contract_form # room_f, hallway_f, wc_f, kitchen_f = get_fk_forms(parent=contract) #context.update({'formsets': [room_f, hallway_f, wc_f, kitchen_f], # 'titles': [ # Room._meta.verbose_name, # Hallway._meta.verbose_name, # WC._meta.verbose_name, # Kitchen._meta.verbose_name, # ]}) template = webodt.ODFTemplate('quest.odt') document = template.render(Context(context)) conv = converter() rtf_file = conv.convert(document, format='rtf') document.close() response = StreamingHttpResponse(FileWrapper(rtf_file), content_type=mimetypes.guess_type(document.name)[0]) response['Content-Disposition'] = 'attachment; filename=download.rtf' return response
#! coding: utf-8 from django.conf import settings from django.views.generic import CreateView from django.core.mail import send_mail from django.utils.translation import activate activate('en') from django.template import Context import webodt from webodt.converters import converter conv = converter() # from feedback_app.models import Contact, ContactForm import num2t4ru from num2t4ru import num2text # # class ContactCreateView(CreateView): form_class = ContactForm template_name = 'feedback_app/form.html' success_url = '/thanks/' # def form_valid(self, form): message = '{product_name} / {quarter} написал: '.format( product_name=form.cleaned_data.get('product_name').encode('utf-8'), quarter=form.cleaned_data.get('quarter'), num_contract=form.cleaned_data.get('num_contract'), contract_date=form.cleaned_data.get('contract_date').encode('utf-8'), name_provider=form.cleaned_data.get('name_provider').encode('utf-8'), boss_provider=form.cleaned_data.get('boss_provider').encode('utf-8'), provider_const=form.cleaned_data.get('provider_const').encode('utf-8'),