def add_fields(self): super(Categorized, self).add_fields() self.fields[u'legal_date'] = forms.DateField( label=_( u'inforequests:obligee_action:Categorized:legal_date:label'), help_text=render_to_string( u'inforequests/obligee_action/texts/categorized_legal_date_help.txt', self.context()), localize=True, widget=forms.DateInput( attrs={ u'placeholder': _('inforequests:obligee_action:Categorized:legal_date:placeholder' ), u'class': u'pln-datepicker', }), ) self.fields[u'file_number'] = forms.CharField( label=_( u'inforequests:obligee_action:Categorized:file_number:label'), max_length=255, required=False, widget=forms.TextInput( attrs={ u'placeholder': _(u'inforequests:obligee_action:Categorized:file_number:placeholder' ), }), ) branch = self.wizard.values[u'branch'] if branch.last_action.delivered_date is None and branch.last_action.type in [ Action.TYPES.REQUEST, Action.TYPES.CLARIFICATION_RESPONSE, Action.TYPES.APPEAL, Action.TYPES.ADVANCED_REQUEST, ]: self.fields[u'last_action_dd'] = forms.DateField( label=render_to_string( u'inforequests/obligee_action/texts/categorized_last_action_dd_label.txt', self.context()), help_text=render_to_string( u'inforequests/obligee_action/texts/categorized_last_action_dd_help.txt', self.context()), localize=True, required=False, widget=forms.DateInput( attrs={ u'placeholder': _('inforequests:obligee_action:Categorized:last_action_dd:placeholder' ), u'class': u'pln-datepicker', }), )
def pre_transition(self): res = super(PaperStep, self).pre_transition() if self.accessible: context = self.context(dict(finalize=True)) subject = squeeze(render_to_string(self.subject_template, context)) content = render_to_string(self.content_template, context) res.globals[self.subject_value_name] = subject res.globals[self.content_value_name] = content return res
def add_fields(self): super(Categorized, self).add_fields() self.fields[u'legal_date'] = forms.DateField( label=_(u'inforequests:obligee_action:Categorized:legal_date:label'), help_text=render_to_string( u'inforequests/obligee_action/texts/categorized_legal_date_help.txt', self.context()), localize=True, widget=forms.DateInput(attrs={ u'placeholder': _('inforequests:obligee_action:Categorized:legal_date:placeholder'), u'class': u'pln-datepicker', }), ) self.fields[u'file_number'] = forms.CharField( label=_(u'inforequests:obligee_action:Categorized:file_number:label'), max_length=255, required=False, widget=forms.TextInput(attrs={ u'placeholder': _(u'inforequests:obligee_action:Categorized:file_number:placeholder'), }), ) branch = self.wizard.values[u'branch'] if branch.last_action.delivered_date is None and branch.last_action.type in [ Action.TYPES.REQUEST, Action.TYPES.CLARIFICATION_RESPONSE, Action.TYPES.APPEAL, Action.TYPES.ADVANCED_REQUEST, ]: self.fields[u'last_action_dd'] = forms.DateField( label=render_to_string( u'inforequests/obligee_action/texts/categorized_last_action_dd_label.txt', self.context()), help_text=render_to_string( u'inforequests/obligee_action/texts/categorized_last_action_dd_help.txt', self.context()), localize=True, required=False, widget=forms.DateInput(attrs={ u'placeholder': _('inforequests:obligee_action:Categorized:last_action_dd:placeholder'), u'class': u'pln-datepicker', }), )
def render(self, name, value, attrs=None): obligee = value if isinstance(value, Obligee) else None return render_to_string(u'obligees/widgets/obligee_widget.html', { u'widget_attrs': self._widget_attrs(attrs), u'input_attrs': self._input_attrs(name, value), u'obligee': obligee, })
def render_message(request, level, template, context=None, **kwargs): u""" Render the template and use the result to create and queue a ``django.contrib.messages`` message. """ message = render_to_string(template, context or {}).strip() messages.add_message(request, level, message, **kwargs)
def json_success(request, inforequest): return JsonOperations( JsonCloseModal(), JsonContent(target=u'#content', content=render_to_string( u'inforequests/detail/detail.html', dict(inforequest=inforequest))), )
def render(self, name, value, attrs=None): obligee = value if isinstance(value, Obligee) else None return render_to_string( u'obligees/widgets/obligee_widget.html', { u'widget_attrs': self._widget_attrs(attrs), u'input_attrs': self._input_attrs(name, value), u'obligee': obligee, })
def json_success(request, inforequest): return JsonOperations( JsonCloseModal(), JsonContent( target=u"#content", content=render_to_string(u"inforequests/detail/detail.html", dict(inforequest=inforequest)), ), )
def render_mail(template_prefix, dictionary=None, **kwargs): u""" Create ``django.core.mail.EmailMessage`` object ready to be sent with ``msg.send()`` method. Message subject and body are rendered using templates "(prefix)_subject.txt" and "(prefix)_message.txt" and/or "(prefix)_message.html". If both ".txt" and ".html" body templates exist, the created message is multipart/alternativea including its text and html versions. The functions accepts additional keyword arguments for EmailMessage constructor. Of most interest are: ``from_email``, ``to``, ``bcc``, ``attachments``, ``headers`` and ``cc``. Based on: Django-allauth's allauth.DefaultAccountAdapter.render_mail method. Examples: render_mail('app/mail', from_email='My Name <*****@*****.**>', to=['Your Name <*****@*****.**>']) """ site = Site.objects.get_current() subject = render_to_string(u'{}_subject.txt'.format(template_prefix), dictionary) subject = squeeze(u'[{}] {}'.format(site.name, subject)) bodies = {} for ext in [u'html', u'txt']: template_name = u'{}_message.{}'.format(template_prefix, ext) try: bodies[ext] = render_to_string(template_name, dictionary).strip() except TemplateDoesNotExist: # We need at least one body if ext == u'txt' and not bodies: raise if u'txt' in bodies and u'html' in bodies: msg = EmailMultiAlternatives(subject, bodies[u'txt'], **kwargs) msg.attach_alternative(bodies[u'html'], u'text/html') elif u'html' in bodies: msg = EmailMessage(subject, bodies[u'html'], **kwargs) msg.content_subtype = u'html' # Main content is now text/html else: msg = EmailMessage(subject, bodies[u'txt'], **kwargs) return msg
def render(self, name, value, attrs=None): inputs = [] for item in value or [None]: obligee = item if isinstance(item, Obligee) else None input_attrs = self._input_attrs(name, item) inputs.append((input_attrs, obligee)) return render_to_string(u'obligees/widgets/multiple_obligee_widget.html', { u'widget_attrs': self._widget_attrs(attrs), u'skel_attrs': self._input_attrs(name, None, skel=True), u'inputs': inputs, })
def post_transition(self): res = super(Main, self).post_transition() if self.is_valid(): res.globals.update({ u'subject': squeeze(render_to_string( u'inforequests/clarification_response/forms/subject.txt')), u'content': self.fields[u'content'].finalize(self.cleaned_data[u'content']), }) return res
def render(self, name, value, attrs=None): inputs = [] for item in value or [None]: obligee = item if isinstance(item, Obligee) else None input_attrs = self._input_attrs(name, item) inputs.append((input_attrs, obligee)) return render_to_string( u'obligees/widgets/multiple_obligee_widget.html', { u'widget_attrs': self._widget_attrs(attrs), u'skel_attrs': self._input_attrs(name, None, skel=True), u'inputs': inputs, })
def render(self, name, value, attrs=None): textinput_value = u',{},'.format(u','.join(format(a.pk) for a in value or [])) textinput_attrs = dict(attrs, type=u'hidden') textinput = super(AttachmentsWidget, self).render(name, textinput_value, textinput_attrs) return render_to_string(u'attachments/attachments_widget.html', { u'name': name, u'textinput': textinput, u'attachments': value or [], u'funcs': { u'upload_url': self.upload_url_func, u'download_url': self.download_url_func, }, })
def post_transition(self): res = super(Main, self).post_transition() if self.is_valid(): res.globals.update({ u'subject': squeeze( render_to_string( u'inforequests/clarification_response/forms/subject.txt' )), u'content': self.fields[u'content'].finalize( self.cleaned_data[u'content']), }) return res
def __init__(self, *args, **kwargs): self.draft = kwargs.pop(u'draft', False) self.attached_to = kwargs.pop(u'attached_to') self.user = kwargs.pop(u'user') super(InforequestForm, self).__init__(*args, **kwargs) unique_email = settings.INFOREQUEST_UNIQUE_EMAIL.format(token=u'xxxx') unique_email = mark_safe(render_to_string(u'inforequests/create/snippets/content_unique_email.html', dict(unique_email=unique_email)).strip()) self.fields[u'content'].widget.context[u'user'] = self.user self.fields[u'content'].widget.context[u'unique_email'] = unique_email self.fields[u'attachments'].attached_to = self.attached_to if self.draft: self.fields[u'obligee'].required = False self.fields[u'subject'].required = False self.fields[u'content'].required = False
def __init__(self, *args, **kwargs): self.draft = kwargs.pop(u'draft', False) self.attached_to = kwargs.pop(u'attached_to') self.user = kwargs.pop(u'user') super(InforequestForm, self).__init__(*args, **kwargs) unique_email = settings.INFOREQUEST_UNIQUE_EMAIL.format(token=u'xxxx') unique_email = mark_safe( render_to_string( u'inforequests/create/snippets/content_unique_email.html', dict(unique_email=unique_email)).strip()) self.fields[u'content'].widget.context[u'user'] = self.user self.fields[u'content'].widget.context[u'unique_email'] = unique_email self.fields[u'attachments'].attached_to = self.attached_to if self.draft: self.fields[u'obligee'].required = False self.fields[u'obligee'].email_required = False self.fields[u'subject'].required = False self.fields[u'content'].required = False self.fields[u'attachments'].max_count = None self.fields[u'attachments'].max_size = None self.fields[u'attachments'].max_total_size = None
def render_to_string(self): return render_to_string(self.template or self.base_template, self.context())
def json_form(request, form, **context): return JsonOperations(JsonContent(target=None, content=render_to_string(form.template, dict(context, form=form))))
def _render_ancestors(cls, page): return render_to_string(u'pages/admin/snippets/ancestors.html', { u'page': page, u'inclusive': True, })
def json_form(request, form, **context): return JsonOperations( JsonContent(target=None, content=render_to_string(form.template, dict(context, form=form))), )
def format_output(self, rendered_widgets): context = dict(self.context, inputs=rendered_widgets, finalize=False) content = mark_safe(render_to_string(self.template, context).strip()) attrs = merge_html_attrs(self.composite_attrs, class_=u'pln-composite-text') return format_html(u'<div{0}>{1}</div>', flatatt(attrs), content)
def finalize(self, cleaned_data, context={}): context = dict(self.widget.context, inputs=cleaned_data, finalize=True, template=self.widget.template, **context) return render_to_string(u'utils/forms/compositetextfield/finalize.txt', context).strip()