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
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( |
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 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): |
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 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 |
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
#-*- 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." |
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
""" | |
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 |
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
# 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): |
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
Using Scrapy to Scrape a Page and a Subpage from a list | |
from scrapy.contrib.spiders.init import InitSpider | |
from scrapy.http import Request, FormRequest | |
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor | |
from scrapy.contrib.spiders import CrawlSpider, Rule | |
from scrapy.spider import BaseSpider | |
from scrapy.selector import HtmlXPathSelector | |
from selenium import selenium |
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
#Using Scrapy with Selenium to scape a rendered page [Updated] | |
from scrapy.contrib.spiders.init import InitSpider | |
from scrapy.http import Request, FormRequest | |
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor | |
from scrapy.contrib.spiders import CrawlSpider, Rule | |
from scrapy.spider import BaseSpider | |
from scrapy.selector import HtmlXPathSelector | |
from selenium import selenium |
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.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 |
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 scrapy.contrib.spiders import CrawlSpider, Rule | |
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor | |
from scrapy.selector import HtmlXPathSelector | |
from myspider.items import CraigslistSampleItem | |
class MySpider(CrawlSpider): | |
name = "craigs" | |
allowed_domains = ["sfbay.craigslist.org"] | |
start_urls = ["http://sfbay.craigslist.org/"] |
OlderNewer