This file contains hidden or 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.template import Variable, defaultfilters | |
| from django.http import HttpResponse | |
| import xlwt | |
| def render_to_xls(queryset, filename, fields): | |
| """ | |
| Output an XLS file of the queryset | |
| Usage : | |
| ------- |
This file contains hidden or 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
| #!/usr/bin/env python | |
| #-*- coding: utf-8 -*- | |
| import os | |
| import time | |
| def cls(): | |
| os.system(['clear', 'cls'][os.name == 'nt']) | |
| figure_repos = '.o.' |
This file contains hidden or 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 datetime import datetime | |
| from os.path import abspath, dirname | |
| import os | |
| import json | |
| phantom_script = """ | |
| var page = require('webpage').create(); | |
| page.open("%s", function (status) { | |
| page.render("%s"); | |
| phantom.exit(); |
This file contains hidden or 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 get_max_consecutive_number(datas): | |
| """ | |
| Retourne le nombre maximum de chiffres consécutifs | |
| dans une listes. (Y'a t'il un built-in pour ça ? Itertool ?) | |
| >> suit = [2003, 2008, 2007, 2001, 2010] | |
| >> print get_max_consecutive_number(suit) | |
| >>>> 2 | |
| >> suit = [2003, 2008, 2007, 2001, 2002, 2004] |
This file contains hidden or 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 itertools import groupby | |
| from django import template | |
| from django.template.base import TemplateSyntaxError | |
| register = template.Library() | |
| class RegroupListNode(template.Node): | |
| def __init__(self, target, expression, var_name): |
This file contains hidden or 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 refresh_after(seconds){ | |
| seconds--; | |
| if (seconds<=0){ | |
| alert('The page has expired, click OK to reload.') | |
| document.location.href = document.location.href; | |
| }else{ | |
| setTimeout(refresh_after, 1000, [seconds]) | |
| } | |
| } |
This file contains hidden or 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 time | |
| from datetime import datetime | |
| from subprocess import call | |
| def show_in_browser(response): | |
| """ | |
| Write the response content into a temporary HTML file and | |
| open it into your default browser. |
This file contains hidden or 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 functools | |
| def memoize_django_model_method(obj): | |
| @functools.wraps(obj) | |
| def memoizer(*args, **kwargs): | |
| # Get the model instance | |
| instance = args[0] |
This file contains hidden or 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.db import transaction | |
| from django.db.models import Model | |
| from django.contrib.contenttypes.generic import GenericForeignKey | |
| from django.apps import apps | |
| @transaction.atomic | |
| def merge_model_objects(primary_object, alias_objects=None, keep_old=False): | |
| """ | |
| Use this function to merge model objects (i.e. Users, Organizations, Polls, |
OlderNewer