Skip to content

Instantly share code, notes, and snippets.

<script type="text/javascript">
// function used to make AJAX calls
function ajaxFormCall(event, formObject, successFunction, errorFunction) {
var data = new FormData(formObject.get(0));
event.preventDefault();
$.ajax({
data: data,
type: formObject.attr('method'),
url: formObject.attr('action'),
cache: false,
@lightstrike
lightstrike / gist:85c6b40589c01c0b0c72
Last active August 29, 2015 14:02
Setting up Testing with Django-Nose, Coverage, Model Mommy and Selenium
1. Add following to requirements (recommend pip freeze after install and putting version numbers in file - ie coverage==3.7.1):
model_mommy
django-nose
coverage
selenium
2. Add Django Nose to INSTALLED APPS:
INSTALLED_APPS = (
...
'django_nose',
@lightstrike
lightstrike / gist:6704e8586d8b839389c1
Created June 16, 2014 22:44
Testing ModelForm template tag with Factory Boy
### factories.py ###
from factory.django import DjangoModelFactory
from django.forms import ModelForm
from .models import Product, ProductQuerySet
class TestProduct(Product):
@function assign-inputs($inputs, $pseudo: null) {
$list : ();
@each $input in $inputs {
$input: unquote($input);
$input: if($pseudo, $input + ":" + $pseudo, $input);
$list: append($list, $input, comma);
}
@return $list;
@lightstrike
lightstrike / days_until.py
Created July 17, 2014 15:37
Days Until Filter in Django
# Inspiration from https://djangosnippets.org/snippets/116/
from django import template
import datetime
register = template.Library()
def days_until(value):
"""
@lightstrike
lightstrike / get_classes_from_html.py
Last active August 29, 2015 14:04
Simple CSS class extraction script from HTML file
"""
Usage: get_classes_from_html.py path/to/file.html
"""
def convert_html_to_string(html_file_path):
html_file = open(html_file_path, 'r')
return html_file.read()
def get_css_classes(html_string, attribute='class'):
@lightstrike
lightstrike / icons.html
Last active August 29, 2015 14:05
Embedded Icon in Bootstrap 3 Input
<!--
See http://codepen.io/lightstrike/pen/tswme for demo
Example markup and inspiration from http://jsfiddle.net/KyleMit/cyCFS/
-->
<p>Full Size:</p>
<div class="left-inner-addon ">
<i class="glyphicon glyphicon-user"></i>
<input type="text"
class="form-control"
@lightstrike
lightstrike / _parsley.scss
Created October 20, 2014 23:20
Adapting base Parsley CSS into SASS mixins
/* Adapting base Parsley CSS into SASS mixins - http://parsleyjs.org/src/parsley.css */
/*
Use this mixin to define success and error classes
Default class names: parsley-success, parsley-error
*/
@mixin parsleyValidated($name, $textColor, $bgColor, $borderColor) {
input.#{$name},
select.#{$name},
textarea.#{$name} {
@lightstrike
lightstrike / parsley_selectors
Created October 28, 2014 20:12
Experimenting with how to customize django-parsley
def get_selector(*args):
return ''.join([a for a in args])
def get_parsley_errors_data(parsley_attr, fields):
parsley_extras = dict()
for field in fields:
field_dict = {}
field_slug = slugify(field)
field_dict[parsley_attr] = get_selector(
@lightstrike
lightstrike / CBV Access
Created November 3, 2014 18:38
User View Mixins
class UserDetailAccessMixin(UserPassesTestMixin):
def test_func(self, user):
"""
Tests if user should be allowed access to DetailView if one of two conditions:
1. Has staff permissions
2. Is the customer associated with the object in a DetailView
"""
if user.is_staff:
return True
else: