This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import forms | |
from django.core.mail import EmailMultiAlternatives | |
from django.conf import settings | |
from django import template | |
register = template.Library() | |
class ContactForm(forms.Form): | |
name = forms.CharField(error_messages={ 'required':'Please enter your name'}) | |
email = forms.EmailField(error_messages={'invalid': 'This email is not valid', 'required':'Please enter your email'}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Django settings for {{myproject}} project. | |
Generated by 'django-admin startproject' using Django 1.8.3. | |
For more information on this file, see | |
https://docs.djangoproject.com/en/1.8/topics/settings/ | |
For the full list of settings and their values, see | |
https://docs.djangoproject.com/en/1.8/ref/settings/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Namespace to handle disclaimer display depending on the user's cookies | |
// Written by Guillaume Piot gpiot.com | |
// Inspiration from W3 Schools http://www.w3schools.com/js/js_cookies.asp | |
// Example use for a cookie disclaimer | |
// Cookies disclaimer | |
// var cookie_info = new InfoMessage($('.alert-cookies'), 'cookies_policy'); | |
// $('.close-disclaimer').click(function(e){ | |
// e.preventDefault(); | |
// cookie_info.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
head.js('/static/js/jquery-1.7.1.min.js', '/static/js/jquery.form.js', function(){ | |
// bind 'myForm' and provide a simple callback function | |
var formdiv = '#form-id' | |
var options = { | |
beforeSubmit: function(){ | |
$('#form-edit-basecamp #submit').attr('value','{% trans "Saving..." %}'); | |
}, | |
success: function(data) { | |
// Remove prior error messages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This code is licensed under Creative Commons Attribution 3.0 * | |
* You may share and remix the script so long as you attribute the * | |
* original author, Andrew January. * | |
* http://creativecommons.org/licenses/by/3.0/ */ | |
$(document).ready(function() { | |
// Check to see if the browser already supports placeholder text (introduced in HTML5). If it does, | |
// then we don't need to do anything. | |
var i = document.createElement('input'); | |
if ('placeholder' in i) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sortByKey(array, key) { | |
return array.sort(function(a, b) { | |
var x = a[key]; var y = b[key]; | |
return ((x < y) ? -1 : ((x > y) ? 1 : 0)); | |
}); | |
} | |
// Example use | |
// Will update the `my_data` array | |
//sortByKey(my_data, 'order_id'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
identifier = re.sub('\W+', ' ', identifier).strip() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Extension for unslider.js, add a thumbnail trailer | |
// HOW TO USE | |
// Include this script in your page first, after unslider.js | |
// Then output the thumbnails as follows: | |
// <div class="slide-control"> | |
// <a href="#prev" class="unslider-arrow prev"></a> | |
// <a href="#next" class="unslider-arrow next"></a> | |
// <div class="thumbnail_slider" style="width: 368px;"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This script will load a Google map in #map_canvas (div) | |
// | |
// You must include the Google map library in the head of your document: | |
// <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> | |
// | |
// The #map_canvas must have a minimim height to show. | |
// eg: #map_canvas { height:300px; } | |
// | |
// Then, at the bottom of the page, or after <div id="map_canvas"></div> | |
// Include the following JS: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def export_profile(request): | |
import csv, StringIO, datetime | |
date = datetime.datetime.now() | |
# Create the HttpResponse object with the appropriate CSV header. | |
response = HttpResponse(content_type='text/csv') | |
response['Content-Disposition'] = 'attachment; filename="profiles-%s.csv"' % (date.strftime('%d-%m-%Y')) | |
writer = csv.writer(response) |