model = Student
can_delete = False
fields = ['level', 'iej', 'period', 'training', 'platform_only', 'procedure',
- 'written_speciality', 'oral_speciality', 'oral_1', 'oral_2']
+ 'written_speciality', 'oral_speciality', 'oral_1', 'oral_2', 'promo_code']
default_application_fees = 40
subscription_fees = models.FloatField(_('subscription fees'), help_text='€', blank=True, null=True)
promo_code = models.CharField(_('promo code'), blank=True, max_length=100)
+ date_registered = models.DateTimeField(_('registration date'), auto_now_add=True, null=True, blank=True)
date_subscribed = models.DateTimeField(_('subscription date'), null=True, blank=True)
is_subscribed = models.BooleanField(_('subscribed'))
confirmation_sent = models.BooleanField(_('confirmation sent'))
--- /dev/null
+@page {
+ margin: 1cm;
+ margin-bottom: 2.5cm;
+ @frame footer {
+ -pdf-frame-content: footer;
+ bottom: 1cm;
+ margin-left: 1cm;
+ margin-right: 1cm;
+ height: 1cm;
+ }
+}
+
+#header{
+ font-size: 4em;
+ color: white;
+ padding-top: 2em;
+ padding-left: 1em;
+ background-color: #3a69b1;
+}
+
+#content {
+ margin: 50px;
+
+}
+
+.table1 {
+ font-size: 1.5em;
+ padding-top: 2px;
+}
+
+
+.table2 {
+ margin: 0px;
+ font-size: 1em;
+ padding: 0px;
+}
+
+#footer{
+ font-size: 1em;
+ color: white;
+ padding: 1em;
+ background-color: #3a69b1;
+ text-align: center;
+}
+
+.bold {
+ font-weight: bold;
+ vertical-align: top;
+}
75006 Paris
<br><br><br>
-<a href="{{ register_doc_print.file.url }}" class="component_icon button" id="action_green" target="_blank"><img src="{{STATIC_URL}}telemeta/images/download.png" alt="" style="vertical-align:middle" /> {% trans "Download" %}</a>
+<a href="{% url 'teleforma-registration-download' username %}" class="component_icon button" id="action_green" target="_blank"><img src="{{STATIC_URL}}telemeta/images/download.png" alt="" style="vertical-align:middle" /> {% trans "Download" %}</a>
</center>
</div>
{% load telemeta_utils %}
{% load teleforma_tags %}
-{% block title %}<center>{% trans "Registration" %} - {% description %}</center>{% endblock %}
+{% block title %}<center>{% trans "Pre-registration" %} - {% description %}</center>{% endblock %}
{% block content %}
<center>
--- /dev/null
+<!DOCTYPE html>
+{% load i18n %}
+{% load telemeta_utils %}
+{% load teleforma_tags %}
+
+{% get_current_language as LANGUAGE_CODE %}
+{% get_available_languages as LANGUAGES %}
+<html xmlns="http://www.w3.org/1999/xhtml" lang="{{ LANGUAGE_CODE }}" xml:lang="{{ LANGUAGE_CODE }}" {% if LANGUAGE_BIDI %}dir="rtl"{% endif %}>
+
+<head>
+<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
+
+<title>{%block head_title %}{% description %} - {% trans "Registration" %}{% endblock %}</title>
+
+{% block stylesheets %}
+<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}teleforma/css/teleforma_pdf.css" />
+{% endblock %}
+
+{% block extra_stylesheets %}{% endblock %}
+
+</head>
+
+<body>
+{% block layout %}
+<div id="layout">
+
+<div id="header">
+ <span style="color: yellow; font-weight: bold;">></span> {% trans "Training registration" %}
+</div>
+
+<div id="content">
+
+ <table class="table1">
+ <tr><td class="bold">{% trans "Last name" %} : </td><td>{{ student.user.last_name|upper }}</td></tr>
+ <tr><td class="bold">{% trans "First name" %} : </td><td>{{ student.user.first_name|upper }}</td></tr>
+ <tr><td class="bold">{% trans "Address" %} : </td><td>{{ student.user.profile.all.0.address }} {{ student.user.profile.all.0.postal_code }} {{ student.user.profile.all.0.city }}</td></tr>
+ <tr><td class="bold">{% trans "Training" %} : </td><td>{{ student.training.name }}</td></tr>
+ <tr><td class="bold">{% trans "Training type" %} : </td><td>{% if student.platform_only %}E-learning{% else %}Présentielle et E-learning{% endif %}</td></tr>
+ <tr><td class="bold">{% trans "Registration date" %} : </td><td>{{ student.date_registered}}</td></tr>
+ </table>
+
+ <table class="table2">
+ <tr><td>
+ Je certifie avoir pris connaissance des conditions générales d’inscription et du règlement intérieur.
+ </td>
+ <td>
+ A ...................................., le .......................................
+ <br>
+ Signature
+ </td></tr>
+ </table>
+
+</div>
+
+{% block footer %}
+<div id="footer">
+ Copyright © {% current_year %} Pré-Barreau
+ </div>
+{% endblock %}
+
+</div>
+{% endblock layout %}
+
+</body>
+</html>
# (r'^accounts/register0/$', RegistrationView.as_view(), {'form_class':CustomRegistrationForm}),
url(r'^accounts/register/$', UserAddView.as_view(), name="teleforma-register"),
url(r'^accounts/complete/$', UserCompleteView.as_view(), name="teleforma-register-complete"),
+ url(r'^accounts/register/(?P<username>.*)/download/$', RegistrationPDFViewDowload.as_view(),
+ name="teleforma-registration-download"),
+
url(r'^captcha/', include('captcha.urls')),
# Help
import jqchat.models
from xlwt import Workbook
+from xhtml2pdf import pisa
+
try:
from telecaster.models import *
from telecaster.tools import *
def dispatch(self, *args, **kwargs):
return super(HelpView, self).dispatch(*args, **kwargs)
+
+
+class PDFTemplateResponseMixin(TemplateResponseMixin):
+ """
+ Mixin for Django class based views.
+ Switch normal and pdf template based on request.
+
+ The switch is made when the request has a particular querydict, e.g.::
+
+ http://www.example.com?format=pdf
+
+ The key and value of the querydict can be overridable using *as_view()*.
+ That pdf url will be present in the context as *pdf_url*.
+
+ For example it is possible to define a view like this::
+
+ from django.views.generic import View
+
+ class MyView(PDFTemplateResponseMixin, View):
+ template_name = 'myapp/myview.html'
+ pdf_filename = 'report.pdf'
+
+ The pdf generation is automatically done by *xhtml2pdf* using
+ the *myapp/myview_pdf.html* template.
+
+ Note that the pdf template takes the same context as the normal template.
+ """
+ pdf_template_name = None
+ pdf_template_name_suffix = '_pdf'
+ pdf_querydict_key = 'format'
+ pdf_querydict_value = 'pdf'
+ pdf_encoding = 'utf-8'
+ pdf_filename = None
+ pdf_url_varname = 'pdf_url'
+ pdf_kwargs = {}
+
+ def is_pdf(self):
+ value = self.request.REQUEST.get(self.pdf_querydict_key, '')
+ return value.lower() == self.pdf_querydict_value.lower()
+
+ def _get_pdf_template_name(self, name):
+ base, ext = os.path.splitext(name)
+ return '%s%s%s' % (base, self.pdf_template_name_suffix, ext)
+
+ def get_pdf_template_names(self):
+ """
+ If the template name is not given using the class attribute
+ *pdf_template_name*, then it is obtained using normal template
+ names, appending *pdf_template_name_suffix*, e.g.::
+
+ path/to/detail.html -> path/to/detail_pdf.html
+ """
+ if self.pdf_template_name is None:
+ names = super(PDFTemplateResponseMixin, self).get_template_names()
+ return map(self._get_pdf_template_name, names)
+ return [self.pdf_template_name]
+
+ def get_pdf_filename(self):
+ """
+ Return the pdf attachment filename.
+ If the filename is None, the pdf will not be an attachment.
+ """
+ return self.pdf_filename
+
+ def get_pdf_url(self):
+ """
+ This method is used to put the pdf url in the context.
+ """
+ querydict = self.request.GET.copy()
+ querydict[self.pdf_querydict_key] = self.pdf_querydict_value
+ return '%s?%s' % (self.request.path, querydict.urlencode())
+
+ def get_pdf_response(self, context, **response_kwargs):
+ return render_to_pdf(
+ request=self.request,
+ template=self.get_pdf_template_names(),
+ context=context,
+ encoding=self.pdf_encoding,
+ filename=self.get_pdf_filename(),
+ **self.pdf_kwargs
+ )
+
+ def render_to_response(self, context, **response_kwargs):
+ if self.is_pdf():
+ from django.conf import settings
+ context['STATIC_ROOT'] = settings.STATIC_ROOT
+ return self.get_pdf_response(context, **response_kwargs)
+ context[self.pdf_url_varname] = self.get_pdf_url()
+ return super(PDFTemplateResponseMixin, self).render_to_response(
+ context, **response_kwargs)
def forms_valid(self, form, inlines):
messages.info(self.request, _("You have successfully register your account."))
- user = form.save()
+ self.user = form.save()
user.username = get_unique_username(user.first_name, user.last_name)
user.is_active = False
user.save()
def get_context_data(self, **kwargs):
context = super(UserCompleteView, self).get_context_data(**kwargs)
- context['register_doc_print'] = Document.objects.get(id=settings.TELEFORMA_REGISTER_DEFAULT_DOC_ID)
+ # context['register_doc_print'] = Document.objects.get(id=settings.TELEFORMA_REGISTER_DEFAULT_DOC_ID)
+ context['username'] = kwargs['username']
return context
+
+
+class RegistrationPDFView(PDFTemplateResponseMixin, DetailView):
+
+ context_object_name = "student"
+ model = Student
+ template_name = 'teleforma/registration_pdf.html'
+ pdf_template_name = template_name
+
+ def get_context_data(self, **kwargs):
+ student = self.get_object()
+ if student.training and not student.trainings:
+ student.trainings.add(student.training)
+ student.save()
+ context = super RegistrationPDFView, self).get_context_data(**kwargs)
+ return context
+
+
+class RegistrationPDFViewDowload(RegistrationPDFView):
+
+ pdf_filename = 'registration.pdf'
+
+ def get_pdf_filename(self):
+ super(RegistrationPDFViewDowload, self).get_pdf_filename()
+ student = self.get_object()
+ prefix = unicode(_('Registration'))
+ filename = '_'.join([prefix, student.first_name, student.user.last_name])
+ filename += '.pdf'
+ return filename.encode('utf-8')