Commits

Joel Rivera committed 57ef040

Set html metatags, improve error handling in contact form and translate a few more missing messages.

  • Participants
  • Parent commits ef22477

Comments (0)

Files changed (6)

joelmx/locale/es/LC_MESSAGES/joelmx.mo

Binary file modified.

joelmx/locale/es/LC_MESSAGES/joelmx.po

 msgstr ""
 "Project-Id-Version: joelmx 0.0\n"
 "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
-"POT-Creation-Date: 2013-02-12 03:49-0600\n"
-"PO-Revision-Date: 2013-02-12 03:48-0600\n"
+"POT-Creation-Date: 2013-02-16 02:51-0600\n"
+"PO-Revision-Date: 2013-02-16 02:52-0600\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: es <LL@li.org>\n"
 "Plural-Forms: nplurals=2; plural=(n != 1)\n"
 "Content-Transfer-Encoding: 8bit\n"
 "Generated-By: Babel 1.0dev\n"
 
+#: joelmx/views.py:39
+msgid "The question is not valid."
+msgstr "La pregunta no es válida."
+
+#: joelmx/views.py:45
+msgid "This is wrong"
+msgstr "Esto es incorrecto"
+
+#: joelmx/views.py:47
+msgid "Invalid form fields."
+msgstr "Campos del formulario inválidos."
+
+#: joelmx/templates/base.mako:9 joelmx/templates/base.mako:11
+msgid "Personal website"
+msgstr "Sitio web personal"
+
+#: joelmx/templates/base.mako:11
+msgid "of"
+msgstr "de"
+
+#: joelmx/templates/base.mako:12
+msgid "software developer"
+msgstr "desarrollador de software"
+
+#: joelmx/templates/base.mako:12
+#, fuzzy
+msgid "software engineer"
+msgstr "ingeniero de software"
+
+#: joelmx/templates/base.mako:12
+msgid "python programmer"
+msgstr "programador python"
+
 #: joelmx/templates/home.mako:3
 msgid "Thank you!"
 msgstr "¡Gracias!"

joelmx/locale/joelmx.pot

 msgstr ""
 "Project-Id-Version: joelmx 0.0\n"
 "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
-"POT-Creation-Date: 2013-02-12 03:49-0600\n"
+"POT-Creation-Date: 2013-02-16 02:51-0600\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
 "Content-Transfer-Encoding: 8bit\n"
 "Generated-By: Babel 1.0dev\n"
 
+#: joelmx/views.py:39
+msgid "The question is not valid."
+msgstr ""
+
+#: joelmx/views.py:45
+msgid "This is wrong"
+msgstr ""
+
+#: joelmx/views.py:47
+msgid "Invalid form fields."
+msgstr ""
+
+#: joelmx/templates/base.mako:9 joelmx/templates/base.mako:11
+msgid "Personal website"
+msgstr ""
+
+#: joelmx/templates/base.mako:11
+msgid "of"
+msgstr ""
+
+#: joelmx/templates/base.mako:12
+msgid "software developer"
+msgstr ""
+
+#: joelmx/templates/base.mako:12
+msgid "software engineer"
+msgstr ""
+
+#: joelmx/templates/base.mako:12
+msgid "python programmer"
+msgstr ""
+
 #: joelmx/templates/home.mako:3
 msgid "Thank you!"
 msgstr ""

joelmx/static/js/main.js

     var $form = $('#contact');
     var $contactme = $('#contactme');
     $($form).submit(function(){
-	$.post($form.attr('action'), $form.serialize(), 
-	      function(data) {
-		  _clear_form($form);
-		  var $msg = $('<div class="success">' + SUCCESS_MSG + '</div>').hide();
-		  $msg.prependTo($contactme).fadeIn(2000).delay(2000).fadeOut(5000);
-		  $contactme.prepend();
-	      })
-	    .fail(function(){
-		var $msg = $('<div class="error">' + ERROR_MSG +'</div>').hide();
-		$msg.prependTo($contactme).fadeIn(1000);
-	    });
+	$.ajax({
+	    type: "POST",
+	    url: $form.attr('action'),
+	    data:  $form.serialize(),
+	    success: function(data){
+		_clear_form($form);
+		var $msg = $('<div class="success">' + SUCCESS_MSG + '</div>').hide();
+		$msg.prependTo($contactme).fadeIn(2000).delay(2000).fadeOut(5000);
+		$contactme.prepend();
+	    },
+	    error: function(XHR){
+		if (XHR.status == '400') {
+		    var $msg = $('<div class="error">' + XHR.responseText +'</div>').hide();
+		    $msg.prependTo($contactme).fadeIn(1000).delay(3000).fadeOut(7000);
+		} else {
+		    var $msg = $('<div class="error">' + ERROR_MSG +'</div>').hide();
+		    $msg.prependTo($contactme).fadeIn(1000);
+		}
+	    }});
 	return false;
     });
 }

joelmx/templates/base.mako

     <head>
         <meta charset="utf-8">
         <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
-        <title>Joel Rivera - Personal Website</title>
-	<link rel="shortcut icon" href="${request.static_url('joelmx:static/favicon.ico')}" />
-        <meta name="description" content="">
+        <title>Joel Rivera - ${_("Personal website")}</title>
+        <link rel="shortcut icon" href="${request.static_url('joelmx:static/favicon.ico')}" />
+        <meta name="content-language" content="${request.locale_name}" />
+        <meta name="description" content="${_('Personal website')} ${_('of')} Joel Rivera.">
+        <meta name="keywords" content="Joel Rivera ${_('software developer')},${_('software developer')},${_('software engineer')},${_('python programmer')}" />
         <meta name="viewport" content="width=device-width">
         <link rel="stylesheet" href="${request.static_url('joelmx:static/css/normalize.css')}">
         <link rel="stylesheet" href="${request.static_url('joelmx:static/css/main.css')}">
         <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.9.0.min.js"><\/script>')</script>
         <script src="${request.static_url('joelmx:static/js/plugins.js')}"></script>
         <script src="${request.static_url('joelmx:static/js/main.js')}"></script>
-
-        <!-- Google Analytics: change UA-XXXXX-X to be your site's ID. -->
         <script>
             var _gaq=[['_setAccount','${request.registry.settings['analytics']}'],['_trackPageview']];
             (function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
 
 @view_config(route_name='contact', renderer='string', request_method='POST')
 def contact_me(request):
+    _ = request.translate
     POST = request.POST
     if _is_a_valid_contact_form(POST):
         try:
             challenges = _get_challenges(request)
             challenge = challenges[cidx]
         except IndexError:
-            return HTTPClientError('Invalid challenge.')
+            return HTTPClientError(body=_('The question is not valid.'))
         else:
             if not _is_a_robot(challenge, response):
                 return _send_email(request)
             else:
-                return HTTPClientError(
-                    'This is not correct: "%s : %s"' %
-                    (challenge[0], response))
+                return HTTPClientError(body='%s: "%s : %s"' %  \
+                                       (_('This is wrong'),  challenge[0], response))
     else:
-        return HTTPClientError('Invalid form fields.')
+        return HTTPClientError(body=_('Invalid form fields.'))
 
 
 
 def _is_a_valid_contact_form(POST):
     reqfields = {'name', 'email', 'message', 'clg', 'cidx'}
     missing_fields =  reqfields - set(POST) 
-    return not missing_fields \
-           and POST['cidx'].isdigit()
+    if not missing_fields and  POST['cidx'].isdigit():
+        if not POST['message'].strip():
+            return False
+        else:
+            return True
+    else:
+        return True
+            
         
 
 def _is_a_robot(challenge, resp):
     recipients = (settings['mail_recipient'],)
     message = Message(sender=settings['mail_sender'],
                       recipients=recipients,
-                      subject='Contact via joel.mx'  ,
+                      subject='Contact via joel.mx',
                       extra_headers={'Reply-To':'%s<%s>' %
                                      ((POST['name'], POST['email'])),},
                       body=POST['message'])