Skip to content

Instantly share code, notes, and snippets.

View cheekybastard's full-sized avatar

cheekybastard

View GitHub Profile
@cheekybastard
cheekybastard / filtering.py
Created November 23, 2012 01:57 — forked from robgolding/filtering.py
Django Class-Based View Mixins: Part 2
class FilterMixin(object):
"""
View mixin which provides filtering for ListView.
"""
filter_url_kwarg = 'filter'
default_filter_param = None
def get_default_filter_param(self):
if self.default_filter_param is None:
raise ImproperlyConfigured(
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
import selenium.webdriver.support.wait
selenium.webdriver.support.wait.POLL_FREQUENCY = 0.05
import re
import random
import collections
class AdwordsAutomater(object):
from datetime import datetime
from datetime import timedelta
def queryset_generator(queryset, chunksize=1000):
"""
Iterate over a Django Queryset ordered by the primary key
This method loads a maximum of chunksize (default: 1000) rows in its
memory at the same time while django normally would load all rows in its
memory. Using the iterator() method only causes it to not preload all the
#-*- coding:utf-8 - *-
def load_dataset():
"Load the sample dataset."
return [[1, 3, 4], [2, 3, 5], [1, 2, 3, 5], [2, 5]]
def createC1(dataset):
"Create a list of candidate item sets of size one."
"""
https://groups.google.com/forum/#!topic/django-oscar/BMibGnLb6w0
I've replaced the Partner model. AbstractPartner already carries a ManyToMany field to users (which is not used as far as I can tell). My model instead got a OneToOne field to users and duck-typing to ensure compatibility with Oscar. https://gist.github.com/4690160
I create a Partner instance for every User via a post_save signal.
When a Product with StockRecord is created, Stockrecord.partner gets set to self.request.user.partner, and hence the connection is made.
The dirty work is overriding all the get_query_set functions in dashboard views to limit results to the logged in user. An example:
# views.py
# coding=UTF-8
import time
from gevent import monkey, spawn, sleep
monkey.patch_all()
import urllib2
import Tkinter as tk
run_forever = True
class App(object):
from django.contrib.auth.models import User
from django.db import models
from django.db.models.signals import post_save
from mezzanine.core.fields import RichTextField
from cartridge.shop.models import Product
from social_auth.signals import pre_update
from social_auth.backends.google import GoogleOAuth2Backend
import os
from PIL import Image
def extractFrames(inGif, outFolder):
frame = Image.open(inGif)
nframes = 0
while frame:
frame.save( '%s/%s-%s.gif' % (outFolder, os.path.basename(inGif), nframes ) , 'GIF')
nframes += 1

Icon ressources collection

#! /usr/bin/env python
import redis
import random
import pylibmc
import sys
r = redis.Redis(host = 'localhost', port = 6389)
mc = pylibmc.Client(['localhost:11222'])