Modify views and templates for proceedings to work.
authorMadhusudan.C.S <madhusudancs@gmail.com>
Tue, 11 May 2010 03:48:47 +0530
changeset 96 3ece0de11641
parent 95 34e28994fec5
child 97 90b393042297
Modify views and templates for proceedings to work.
project/kiwipycon/proceedings/booklet/mk_booklet.py
project/kiwipycon/proceedings/booklet/mk_scipy_paper.py
project/kiwipycon/proceedings/views.py
project/kiwipycon/user/views.py
project/templates/proceedings/submit.html
--- a/project/kiwipycon/proceedings/booklet/mk_booklet.py	Tue May 11 03:47:41 2010 +0530
+++ b/project/kiwipycon/proceedings/booklet/mk_booklet.py	Tue May 11 03:48:47 2010 +0530
@@ -5,20 +5,6 @@
 import codecs
 import re
 
-try:
-    from sanum import model
-except:
-    root_dir = os.path.abspath(os.getcwd() + '/../../')
-    os.chdir(root_dir)
-    sys.path.append(root_dir)
-    from sanum import model
-
-import sanum
-
-import turbogears
-turbogears.update_config(configfile="dev.cfg",
-                         modulename="sanum.config")
-
 
 from mk_scipy_paper import tex2pdf, current_dir , copy_files, preamble, \
         render_abstract, addfile, sourcedir, outdir, outfilename
@@ -59,24 +45,24 @@
     #outfile.write(ur'\setcounter{page}{0}' + '\n')
 
     #from sanum.controllers import Root as Controller
-    abstracts = model.Abstract.select()
-    for abstract in abstracts:
-        if not abstract.approved:
-            continue
-        print abstract.title
-        # Hack: I don't use a stringIO, because it is not unicode-safe.
-        tmpout = MyStringIO()
-        # Hack: I don't wont to be bound to the controller, to be
-        # abstractle to run without cherrypy.
-        #attach_dir = Controller._paper_attach_dir(abstract.id)
-        attach_dir = os.path.abspath(os.sep.join(
-                    (os.path.dirname(sanum.__file__), 'static', 
-                    'papers', '%i' % abstract.id))) + os.sep
-        render_abstract(tmpout, abstract)
-        outstring = hack_include_graphics(tmpout.getvalue(),
-                            attach_dir)
-        outfile.write(outstring)
-        #outfile.write(ur'\fillbreak' + '\n')
+#    abstracts = model.Abstract.select()
+#    for abstract in abstracts:
+#        if not abstract.approved:
+#            continue
+#        print abstract.title
+#        # Hack: I don't use a stringIO, because it is not unicode-safe.
+#        tmpout = MyStringIO()
+#        # Hack: I don't wont to be bound to the controller, to be
+#        # abstractle to run without cherrypy.
+#        #attach_dir = Controller._paper_attach_dir(abstract.id)
+#        attach_dir = os.path.abspath(os.sep.join(
+#                    (os.path.dirname(sanum.__file__), 'static', 
+#                    'papers', '%i' % abstract.id))) + os.sep
+#        render_abstract(tmpout, abstract)
+#        outstring = hack_include_graphics(tmpout.getvalue(),
+#                            attach_dir)
+#        outfile.write(outstring)
+#        #outfile.write(ur'\fillbreak' + '\n')
 
     outfile.write(ur'\end{document}' + '\n')
 
--- a/project/kiwipycon/proceedings/booklet/mk_scipy_paper.py	Tue May 11 03:47:41 2010 +0530
+++ b/project/kiwipycon/proceedings/booklet/mk_scipy_paper.py	Tue May 11 03:48:47 2010 +0530
@@ -11,7 +11,7 @@
 
 conf_name = 'SciPy2009'
 
-current_dir = '/media/python/workspace/kiwipycon/project/kiwipycon/proceedings/booklet'
+current_dir = '/media/python/workspace/kiwipycon/project/static/proceedings'
 
 outdir = current_dir + os.sep + 'output'
 
@@ -226,7 +226,7 @@
     else:
         author_list = abstract.authors
     authors = []
-    print dir(author_list[0])
+
     for author in author_list:
         # If the author has no surname, he is not an author 
         if author.surname:
@@ -372,8 +372,15 @@
     outfile.write(ur'\end{document}' + u'\n')
     outfile.close()
 
-    return tex2pdf(os.path.splitext(outfilename)[0], remove_tex=False)
+    error_file = tex2pdf(os.path.splitext(outfilename)[0], remove_tex=False)
 
+    if not error_file:
+      # Generate a preview image
+      command = ('convert', '-thumbnail', 'x400',
+                 '%s[0]' % (outbasename + '.pdf'), outbasename + '.png')
+      supervise_popen(command, timeout=10)
+
+    return error_file
 
 ##############################################################################
 # Code for using outside of the webapp.
--- a/project/kiwipycon/proceedings/views.py	Tue May 11 03:47:41 2010 +0530
+++ b/project/kiwipycon/proceedings/views.py	Tue May 11 03:48:47 2010 +0530
@@ -9,13 +9,16 @@
 from django.core.urlresolvers import reverse
 from django.shortcuts import render_to_response
 from django.template import RequestContext
+from django.utils import simplejson as json
 
+from project.kiwipycon.proceedings.booklet import mk_scipy_paper
+from project.kiwipycon.proceedings.forms import ProceedingsForm
 from project.kiwipycon.proceedings.models import Paper
 from project.kiwipycon.user.forms import RegisterForm
 from project.kiwipycon.user.models import UserProfile
+from project.kiwipycon.user.utils import kiwipycon_createuser
 from project.kiwipycon.utils import set_message_cookie
-from project.kiwipycon.proceedings.booklet import mk_scipy_paper
-from project.kiwipycon.proceedings.forms import ProceedingsForm
+from project import settings
 
 
 def handleUploadedFile(proceedings_form_data, rst_file):
@@ -25,15 +28,15 @@
     title = proceedings_form_data.get('title')
     abstract = proceedings_form_data.get('abstract')
     body = proceedings_form_data.get('body')
-    authors = proceedings_form_data.get('authors')
 
     if rst_file:
+        # TODO: using stating only for testing purposes.
         destination = open('some/file/name.txt', 'wb+')
         for chunk in rst_file.chunks():
             destination.write(chunk)
         destination.close()
 
-    return title, abstract, body, authors
+    return title, abstract, body
 
 
 @login_required
@@ -41,6 +44,8 @@
     """View to submit the proceedings paper.
     """
 
+    context = RequestContext(request, {})
+
     user = request.user
     if user.is_authenticated():
         try:
@@ -67,17 +72,17 @@
         if request.POST.get('action', None) == 'register':
             # add the new user
             if register_form.is_valid():
-
                 user = kiwipycon_createuser(request, register_form.data)
 
         proceedings_form = ProceedingsForm(data=request.POST,
                                            files=request.FILES)
-  
+
         if proceedings_form.is_valid():
             if user.is_authenticated():
                 # Data from reSt file is appended to the data in fields
-                title, abstract, body, authors = handleUploadedFile(
+                title, abstract, body = handleUploadedFile(
                     proceedings_form.cleaned_data, request.FILES.get('file'))
+                authors = request.POST.get('as_values_authors')
 
                 paper = edit(id, title=title,
                     abstract=abstract, body=body,
@@ -104,9 +109,11 @@
                 initial={'title': paper.title,
                          'abstract': paper.abstract,
                          'body': paper.body,
-                         'authors': ', '.join([
-                             author.username for author in paper.authors.all()])
                 })
+            context['initial_authors'] = json.dumps([
+                {'name': str(author.username),
+                 'value': '%s (%s)' % (author.get_full_name(), author.username)
+                } for author in paper.authors.all()])
         else:
             # Otherwise create a new form
             proceedings_form = ProceedingsForm()
@@ -114,13 +121,10 @@
         register_form = RegisterForm()
         login_form = AuthenticationForm()
 
-    context = RequestContext(request, {
-        'proceedings_form': proceedings_form,
-        'register_form' : register_form,
-        'message' : message,
-        'login_form' : login_form
-        })
-
+    context['proceedings_form'] = proceedings_form
+    context['register_form'] = register_form
+    context['message'] = message
+    context['login_form'] = login_form
     context['id'] = id if id else None
 
     return render_to_response(template, context)
@@ -159,7 +163,7 @@
     authors = kwargs.get('authors')
 
     if authors:
-        authors = authors.split(',')
+        authors = authors.strip(' ,').split(',')
         for author in authors:
             user = User.objects.get(username=author.strip())
             paper.authors.add(user)
@@ -172,32 +176,37 @@
 def show_paper(request, id):
     """Display the thumbnail of the rendered paper for download
     """
-    
+
     paper = Paper.objects.get(id=id)
 
+    # TODO: Address and country should be required field in the user forms
+    # henceforth. Also contact numbers.
     paper_data = {
       'paper_abstract': paper.abstract,
       'authors': [
           {'first_names': author.first_name,
             'surname': author.last_name,
-            'address': 'XXX',
-            'country': 'XXX',
-            'email_address': 'XXX@xx.com',
-            'institution': 'XXX'
+            'address': 'None',
+            'country': 'India',
+            'email_address': author.email,
+            'institution': author.registration_set.get().organisation,
+            'city': author.registration_set.get().city
            } for author in paper.authors.all()],
       'title': paper.title
       }
-    
+
     abstract = mk_scipy_paper.Bunch(**paper_data)
     abstract.authors = [mk_scipy_paper.Bunch(**a) for a in abstract.authors]
 
     abstract['paper_text'] = paper.body
 
-    outfilename = '/media/python/workspace/kiwipycon/project/kiwipycon/proceedings/booklet/output/paper.pdf'
-    attach_dir = os.path.dirname('/media/python/workspace/kiwipycon/project/kiwipycon/proceedings/booklet/output/')
+    out_dir = attach_dir = os.path.join(settings.STATIC_ROOT,
+                                        'proceedings', 'output')
+    outfilename = os.path.join(out_dir, 'paper%d.pdf' % (paper.id))
     mk_scipy_paper.mk_abstract_preview(abstract, outfilename, attach_dir)
 
-    from django.http import HttpResponse
-    return HttpResponse('Machi')
+    context = {'paper_id': paper.id,
+               'out_path': '/static/proceedings/output' }
+    template = 'proceedings/show_paper_preview.html'
 
- 
\ No newline at end of file
+    return render_to_response(template, context)
--- a/project/kiwipycon/user/views.py	Tue May 11 03:47:41 2010 +0530
+++ b/project/kiwipycon/user/views.py	Tue May 11 03:48:47 2010 +0530
@@ -3,25 +3,21 @@
 
 #python
 from urlparse import urlparse
-import json
-import urllib
 import os
 
 #django
 from django.conf import settings
-from django.db.models import Q
-from django.http import HttpResponse
-from django.shortcuts import render_to_response
-from django.template import RequestContext
-from django.core.urlresolvers import reverse
-from django.db.models.signals import post_save
-
-#django.contrib
 from django.contrib.auth.decorators import login_required
 from django.contrib.auth.forms import AuthenticationForm
 from django.contrib.auth.forms import PasswordChangeForm
 from django.contrib.auth.models import User
 from django.core.exceptions import ObjectDoesNotExist
+from django.core.urlresolvers import reverse
+from django.db.models import Q
+from django.http import HttpResponse
+from django.shortcuts import render_to_response
+from django.template import RequestContext
+from django.utils import simplejson as json
 
 #PIL
 from PIL import Image
@@ -32,7 +28,6 @@
 from project.kiwipycon.registration.models import Registration
 from project.kiwipycon.registration.models import Wifi
 from project.kiwipycon.registration.forms import WifiForm
-from project.kiwipycon.sponsor.models import Sponsor
 
 from .utils import kiwipycon_createuser
 from .utils import handle_uploaded_photo
@@ -62,8 +57,6 @@
     else:
         photo = '/img/user-default.png'
 
-    qstring = ""
-
     wifi_comment = None
     if wifiobj:
         wifi_form = False
@@ -248,31 +241,25 @@
     """
 
     get_params = request.GET
-    authors_str = get_params.get('input')
+    search_author = get_params.get('q')
 
-    if not authors_str:
+    if search_author:
+        search_author = search_author.strip()
+    else:
         return HttpResponse(json.dumps(''))
-
-    authors = authors_str.split(',')
-    search_author = authors[-1].strip()
+    
 
     users = User.objects.filter(
         Q(username__istartswith=search_author) | Q(
         first_name__istartswith=search_author) | Q(
         last_name__istartswith=search_author))
 
-    results = [{'id': '',
-                'info': 'plugin_header',
-                'value': 'User Names'
-              }]
+    results = []
     
     for user in users:
         results.append(
-            {'id': 'author_name',
-             'info': str(user.get_full_name()),
-             'value': str(user.username)
+            {'name': str(user.username),
+             'value': '%s (%s)' % (user.get_full_name(), user.username)
             })
 
-    json_response = {'results': results}
-
-    return HttpResponse(json.dumps(json_response))
\ No newline at end of file
+    return HttpResponse(json.dumps(results))
--- a/project/templates/proceedings/submit.html	Tue May 11 03:47:41 2010 +0530
+++ b/project/templates/proceedings/submit.html	Tue May 11 03:48:47 2010 +0530
@@ -2,38 +2,18 @@
 {% block title %}Submit Paper for Proceedings{% endblock %}
 
 {% block addscripts %}
-  <script type="text/javascript" src="/static/jquery/jquery.watermarkinput.js"></script>
-  <link rel="stylesheet" href="/static/css/autosuggest_inquisitor.css" type="text/css" media="screen" charset="utf-8">
-  <script type="text/javascript" src="/static/jquery/jquery.autosuggest.js"></script>
-  <script type="text/javascript">
-  /** Init autosuggest on Search Input **/
-  jQuery(function() {
+<link rel="stylesheet" href="/static/css/autoSuggest.css" type="text/css" media="screen" charset="utf-8">
+<script type="text/javascript" src="/static/jquery/jquery.autoSuggest.js"></script>
+<script type="text/javascript">
+  $(document).ready(function() {
+    var initial_authors_obj = eval("{{ initial_authors|escapejs }}");
+    $("#id_authors").autoSuggest("{% url kiwipycon_get_usernames %}",
+                                 {minChars: 2, asHtmlID: "authors",
+                                  selectedValuesProp: "name",
+                                  preFill: initial_authors_obj });
+  });
+</script>
 
-    // Set autosuggest options with all plugins activated
-    var options = {
-      script:"{% url kiwipycon_get_usernames %}?limit=10&",
-      varname:"input",
-      json:true,            // Returned response type
-      shownoresults:true,       // If disable, display nothing if no results
-      noresults:"No Results",     // String displayed when no results
-      maxresults:8,         // Max num results displayed
-      cache:false,          // To enable cache
-      minchars:2,           // Start AJAX request with at leat 2 chars
-      timeout:100000,         // AutoHide in XX ms
-      callback: function (obj) {    // Callback after click or selection   
-        // => TO submit form (general use)
-        //$('#id_authors').val('sucks'); 
-        //$('#form_search_country').submit(); 
-      }
-    };
-    
-    // Init autosuggest
-    var as_json = new bsn.AutoSuggest('id_authors', options);
-    
-    // Display a little watermak  
-    $("#id_authors").Watermark("Ex : alex, guido, travis");
-  });
-  </script>
 {% endblock %}
 
 {% block content %}