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
var myApp = angular.module('myApp').config(function($httpProvider) { | |
$httpProvider.defaults.headers.post['X-CSRFToken'] = $('input[name=csrfmiddlewaretoken]').val(); | |
}); |
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 template | |
register = template.Library() | |
# Truncate chars but leaving last word complete | |
@register.filter("smart_truncate_chars") | |
def smart_truncate_chars(value, max_length): | |
if len(value) > max_length: | |
# Limits the number of characters in value tp max_length (blunt cut) | |
truncd_val = value[:max_length] | |
# Check if the next upcoming character after the limit is not a space, in which case it might be a word continuing |
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 copy_model_instance(obj): | |
""" | |
Create a copy of a model instance. | |
M2M relationships are currently not handled, i.e. they are not copied. (Fortunately, you don't have any in this case) | |
See also Django #4027. From http://blog.elsdoerfer.name/2008/09/09/making-a-copy-of-a-model-instance/ | |
""" | |
initial = dict([(f.name, getattr(obj, f.name)) for f in obj._meta.fields if not isinstance(f, AutoField) and not f in obj._meta.parents.values()]) | |
return obj.__class__(**initial) |
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
class MyAdmin(admin.ModelAdmin): | |
list_filter = ['market'] | |
# Duplicate list_filter to assign on a pre request basis | |
_list_filter = list_filter | |
# Change list filter on the view depending on user | |
def changelist_view(self, request, extra_context=None): | |
if not request.user.is_superuser: | |
self.list_filter = None |
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 os | |
from django.contrib.sites.shortcuts import get_current_site | |
from django.conf import settings | |
def website_settings(request): | |
site = get_current_site(request) | |
data = { | |
'SITE_NAME': site.name, |
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
module.exports = function(grunt) { | |
grunt.initConfig({ | |
pkg: grunt.file.readJSON('package.json'), | |
copy: { | |
main: { | |
files: [ | |
{expand: true, cwd: 'components/bootstrap/', src: ['less/*.less', 'img/*'], dest: 'src/', filter: 'isFile'}, // includes files in path | |
{expand: true, cwd: 'components/bootstrap/js/', src: ['*.js'], dest: 'src/js/bootstrap/', filter: 'isFile'}, // includes files in path | |
{expand: true, cwd: 'components/jquery/', src: ['jquery.js'], dest: 'src/js/', filter: 'isFile'} | |
//{src: ['path/**'], dest: 'dest/'}, // includes files in path and its subdirs |
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
{ | |
"name": "deploy", | |
"version": "0.0.1", | |
"devDependencies": { | |
"grunt": "latest", | |
"grunt-contrib-uglify": "latest", | |
"grunt-contrib-jshint": "latest", | |
"grunt-contrib-watch": "latest", | |
"grunt-contrib-concat": "latest", | |
"grunt-contrib-copy": "latest" |
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.core.management.base import BaseCommand, CommandError | |
class Command(BaseCommand): | |
args = '<arg1 arg2 ...>' | |
help = 'Command to do ...' | |
def handle(self, *args, **options): | |
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.core.urlresolvers import reverse | |
from django.utils.translation import ugettext_lazy as _ | |
from admin_tools.menu import items, Menu | |
# to activate your custom menu add the following to your settings.py: | |
# | |
# ADMIN_TOOLS_MENU = 'my_project.menu.CustomMenu' | |
class CustomMenu(Menu): | |
""" |
OlderNewer