]> git.parisson.com Git - teleforma.git/commitdiff
add forms templates, first testimonial pdf view (no media)
authoryomguy <yomguy@parisson.com>
Thu, 20 Dec 2012 10:05:44 +0000 (11:05 +0100)
committeryomguy <yomguy@parisson.com>
Thu, 20 Dec 2012 10:05:44 +0000 (11:05 +0100)
teleforma/templates/forms/form_detail.html [new file with mode: 0644]
teleforma/templates/forms/form_sent.html [new file with mode: 0644]
teleforma/templates/forms/includes/built_form.html [new file with mode: 0644]
teleforma/urls.py
teleforma/views/pro.py

diff --git a/teleforma/templates/forms/form_detail.html b/teleforma/templates/forms/form_detail.html
new file mode 100644 (file)
index 0000000..3a160df
--- /dev/null
@@ -0,0 +1,17 @@
+<!doctype html>\r
+{% load forms_builder_tags %}\r
+<head>\r
+    <meta charset="utf-8">\r
+    <title>{{ form.title }}</title>\r
+    <style>\r
+        body {font-family:sans-serif; padding:1em 2em;}\r
+        p {width:50em; clear:both;}\r
+        label {display:block; float:left; width:8em; margin:0 1.2em 1.2em 0;}\r
+        li {list-style-type:none;}\r
+        li label {width:auto; cursor:pointer;}\r
+        .errorlist {color:#f00;}\r
+    </style>\r
+</head>\r
+<body>\r
+    {% render_built_form form %}\r
+</body>\r
diff --git a/teleforma/templates/forms/form_sent.html b/teleforma/templates/forms/form_sent.html
new file mode 100644 (file)
index 0000000..847cadf
--- /dev/null
@@ -0,0 +1,17 @@
+<!doctype html>
+<head>
+    <meta charset="utf-8">\r
+    <title>{{ form.title }}</title>\r
+    <style>\r
+        body {font-family:sans-serif; padding:1em 2em;}\r
+        p {width:50em;}\r
+        label {display:block; float:left; width:10em;}\r
+        .errorlist {color:#f00;}\r
+    </style>\r
+</head>\r
+<body>\r
+    <h1>{{ form.title }}</h1>\r
+    {% if form.response %}\r
+    <p>{{ form.response }}</p>
+    {% endif %}\r
+</body>
diff --git a/teleforma/templates/forms/includes/built_form.html b/teleforma/templates/forms/includes/built_form.html
new file mode 100644 (file)
index 0000000..1a36c60
--- /dev/null
@@ -0,0 +1,14 @@
+    {% if form.intro %}
+    <p>{{ form.intro }}</p>
+    {% endif %}
+
+    <form action="" id="_Form" method="post" 
+        {% if form_for_form.is_multipart %}enctype="multipart/form-data"{% endif %}>
+        {% csrf_token %}
+        {{ form_for_form.as_p }}
+        
+        <div class="form-button">
+        <a href="#" class="component_icon button icon_ok" onclick="$('#_Form').submit(); return false;"> {{ form.button_text }}</a>
+        </div>
+
+    </form>
index 8c001f8164fb0565bc7d9b56ffeb438765a39709..3ee3632c8782a297c4459a4563a79a35f13c8993 100644 (file)
@@ -47,6 +47,7 @@ user_export = UsersXLSExport()
 profile_view = ProfileView()
 document = DocumentView()
 media = MediaView()
+testimonial = TestimonialView()
 
 urlpatterns = patterns('',
 #    url(r'^$', HomeView.as_view(), name='teleforma-home'),
@@ -103,6 +104,10 @@ urlpatterns = patterns('',
     url(r'^forms/', include('forms_builder.forms.urls')),
     url(r'^desk/seminars/(?P<pk>.*)/form/$', evaluation_form_detail, name="teleforma-seminar-form"),
 
+    # Testimonial
+    url(r'^desk/seminars/(?P<pk>.*)/testimonial/$', testimonial.download, 
+                                                    name="teleforma-seminar-testimonial"),
+
     # Postman
     url(r'^messages/', include('postman.urls')),
 
index e4a128043efcbec4068d9e6cc7e089f47f98af7f..81da0816ebbd4dd058eebe56986cf99b95e640f8 100644 (file)
@@ -380,6 +380,7 @@ def evaluation_form_detail(request, pk, template='teleforma/evaluation_form.html
         else:
             entry = form_for_form.save()
             form_valid.send(sender=request, form=form_for_form, entry=entry)
+        messages.info(request, _("You have successfully sumitted your evaluation"))
         return redirect('teleforma-seminar-detail', seminar.id)
 
     context['seminar'] = seminar
@@ -393,56 +394,86 @@ def evaluation_form_detail(request, pk, template='teleforma/evaluation_form.html
 
 # Testimonials
 
-def fetch_resources(uri, rel):
-    """
-    Callback to allow xhtml2pdf/reportlab to retrieve Images,Stylesheets, etc.
-    `uri` is the href attribute from the html link element.
-    `rel` gives a relative path, but it's not used here.
+import StringIO
 
-    """
-    if uri.startswith(settings.MEDIA_URL):
-        path = os.path.join(settings.MEDIA_ROOT,
-                            uri.replace(settings.MEDIA_URL, ""))
-    elif uri.startswith(settings.STATIC_URL):
-        path = os.path.join(settings.STATIC_ROOT,
-                            uri.replace(settings.STATIC_URL, ""))
-    else:
-        path = os.path.join(settings.STATIC_ROOT,
-                            uri.replace(settings.STATIC_URL, ""))
+from xhtml2pdf import pisa
 
-        if not os.path.isfile(path):
-            path = os.path.join(settings.MEDIA_ROOT,
-                                uri.replace(settings.MEDIA_URL, ""))
+from django.conf import settings
+from django.http import HttpResponse
+from django.shortcuts import render
+from django.template.loader import get_template
+from django.template.context import Context
+from django.utils.html import escape
+from django.views.generic.detail import SingleObjectMixin
 
-            if not os.path.isfile(path):
-                raise UnsupportedMediaPathException(
-                                    'media urls must start with %s or %s' % (
-                                    settings.MEDIA_ROOT, settings.STATIC_ROOT))
 
-    return path
+class TestimonialView(DetailView):
+
+    model = Seminar
+    template_name = 'teleforma/seminar_detail.html'
+    mimetype = 'application/pdf'
+    extension = 'pdf'
+
+    @method_decorator(login_required)
+    def dispatch(self, *args, **kwargs):
+        return super(TestimonialView, self).dispatch(*args, **kwargs)
+    
+    def get_context_data(self, **kwargs):
+        context = super(TestimonialView, self).get_context_data(**kwargs)        
+        context['seminar'] = self.get_object()
+        return context
+
+    def download(self, request, pk):
+        """Function to render html template into a pdf file"""
+        
+        seminar = Seminar.objects.get(id=pk)
+        template = get_template(self.template_name)
+        
+        context = Context({'seminar': seminar, 'STATIC_URL': settings.STATIC_ROOT })
+        html = template.render(context)
+        result = StringIO.StringIO()
+
+        pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("UTF-8")),
+                                                dest=result,
+                                                encoding='UTF-8',
+                                                link_callback=self.fetch_resources)
+        if not pdf.err:
+            response = HttpResponse(result.getvalue(), mimetype=self.mimetype)
+            return response
+
+        return HttpResponse('We had some errors<pre>%s</pre>' % escape(html))
+
+    
+
 
 
-def render_to_pdf(template_src, context_dict):
-    """Function to render html template into a pdf file"""
-    template = get_template(template_src)
-    context = Context(context_dict)
-    html = template.render(context)
-    result = StringIO.StringIO()
+    def fetch_resources(self, uri, rel):
+        """
+        Callback to allow xhtml2pdf/reportlab to retrieve Images,Stylesheets, etc.
+        `uri` is the href attribute from the html link element.
+        `rel` gives a relative path, but it's not used here.
 
-    pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("UTF-8")),
-                                            dest=result,
-                                            encoding='UTF-8',
-                                            link_callback=fetch_resources)
-    if not pdf.err:
-        response = HttpResponse(result.getvalue(),
-                                                    mimetype='application/pdf')
+        """
+        if uri.startswith(settings.MEDIA_URL):
+            path = os.path.join(settings.MEDIA_ROOT,
+                                uri.replace(settings.MEDIA_URL, ""))
+        elif uri.startswith(settings.STATIC_URL):
+            path = os.path.join(settings.STATIC_ROOT,
+                                uri.replace(settings.STATIC_URL, ""))
+        else:
+            path = os.path.join(settings.STATIC_ROOT,
+                                uri.replace(settings.STATIC_URL, ""))
 
-        return response
+            if not os.path.isfile(path):
+                path = os.path.join(settings.MEDIA_ROOT,
+                                    uri.replace(settings.MEDIA_URL, ""))
+
+                if not os.path.isfile(path):
+                    raise UnsupportedMediaPathException(
+                                        'media urls must start with %s or %s' % (
+                                        settings.MEDIA_ROOT, settings.STATIC_ROOT))
+        
+        return path
 
-    return HttpResponse('We had some errors<pre>%s</pre>' % escape(html))
 
 
-def download_pdf(request):
-    """Build briefing packages format and export as HTML and PDF."""
-    response = HttpResponse(content_type='application/pdf')
-    return generate_pdf('app/test.html', file_object=response)
\ No newline at end of file