Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## views.py
- def learn_more(request):
- form = LearnMoreForm(request.POST or None)
- if form.is_valid():
- form.save()
- if request.is_ajax():
- return HttpResponse(simplejson.dumps({
- 'success':True,
- 'message':'Thank you for signing up!'}), mimetype='application/json')
- messages.success(request, 'Thank you for signing up!')
- form = None
- return HttpResponseRedirect(request.META['HTTP_REFERER'])
- if request.is_ajax():
- return HttpResponse(simplejson.dumps({
- 'success':False,
- 'message':'There was an error processing your email'}), mimetype='application/json')
- messages.error('There was an error processing your email')
- return HttpResponseRedirect(request.META['HTTP_REFERER'])
- ##javascript
- $(function(){
- $('a.email').click(function(){
- var v = Base64.decode(unescape($(this).attr('data-hash')));
- $(this).text(v);
- $(this).removeClass('email');
- $(this).addClass('decoded-email');
- return false;
- });
- $('a.decoded-email').live('click', function(){
- $(this).attr('href', 'mailto:'+$(this).text());
- return false;
- });
- $('a.addthis').each(function(){
- addthis.button($(this).get());
- });
- $('html').ajaxSend(function(event, xhr, settings) {
- function getCookie(name) {
- var cookieValue = null;
- if (document.cookie && document.cookie != '') {
- var cookies = document.cookie.split(';');
- for (var i = 0; i < cookies.length; i++) {
- var cookie = jQuery.trim(cookies[i]);
- // Does this cookie string begin with the name we want?
- if (cookie.substring(0, name.length + 1) == (name + '=')) {
- cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
- break;
- }
- }
- }
- return cookieValue;
- }
- if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url)) || /localhost:*/.test(settings.url)) {
- // Only send the token to relative URLs i.e. locally.
- xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
- }
- });
- //need to limit it to the scope of signup yo
- if($('form.newsletter').length){
- //apply the goodies - ajax up in there
- $("form.newsletter #id_email").labelify({labelledClass: "inputHighlight"});
- $('form.newsletter').each(function(){
- $(this).validate({
- rules: {
- email: {
- required: true,
- email: true
- }
- },
- messages: {
- email: "Email address is required!"
- },
- errorElement: 'span',
- errorPlacement: function(error, element){
- error.insertBefore(element.prev());
- },
- submitHandler: function(form){
- $('input[type="submit"]', $(form)).attr('disabled', 'true');
- //form.submit();
- $.post($(form).attr('action'),$(form).serialize(),function(data, textStatus){
- if(data.success){
- //empty form contents
- $(form).empty();
- $(form).append('<p class="message success">'+data.message+'</p>');
- }else{
- $(form).append('<p class="message error">'+data.message+'</p>');
- }
- });
- }
- });
- });
- }
- });
Add Comment
Please, Sign In to add comment