Skip to content

Instantly share code, notes, and snippets.

@saidimu
saidimu / gist:1024184
Created June 14, 2011 02:19
Redirecting Scrapy log messages to standard Python logger
## Add the following lines to your Scrapy project's settings.py file
## This will redirect *all* Scrapy logs to your standard Python logging facility
from twisted.python import log
observer = log.PythonLoggingObserver()
observer.start()
@saidimu
saidimu / gist:1024207
Created June 14, 2011 02:36
Generating URLs to crawl from outside a Scrapy spider
from scrapy import log
from scrapy.item import Item
from scrapy.http import Request
from scrapy.contrib.spiders import XMLFeedSpider
def NextURL():
"""
Generate a list of URLs to crawl. You can query a database or come up with some other means
Note that if you generate URLs to crawl from a scraped URL then you're better of using a
@saidimu
saidimu / models.py
Created January 20, 2012 01:15 — forked from mbrochh/models.py
Attach the django-shop cart to a User that started shopping anonymously
# add this soewhere where it gets loaded very early, i.e.
# your shop's models.py
from django.contrib.auth import login
from django.contrib.auth.signals import user_logged_in
from django.dispatch import receiver
from registration.signals import user_activated
from shop.models.defaults.cart import Cart
@saidimu
saidimu / gist:1644253
Created January 20, 2012 01:16 — forked from mbrochh/gist:1055461
SkipShippingBackend
# -*- coding: utf-8 -*-
"""Shipping backend that skips the whole shipping process."""
from django.conf.urls.defaults import patterns, url
class SkipShippingBackend(object):
backend_name = "Skip Shipping Backend"
url_namespace = "skip-shipping"
@saidimu
saidimu / gist:1644263
Created January 20, 2012 01:16 — forked from mbrochh/gist:1055458
Hiding billing_shipping_form from seletion.html template
<html>
<body>
<h1>Shipping and Billing</h1>
<form method="POST">
{% csrf_token %}
<h3>Your shipping address</h3>
{{ shipping_address.as_p }}
<h3>Your billing address</h3>
{{ billing_address.as_p }}
<input type=hidden name="shipping_method" value="skip-shipping" />
@saidimu
saidimu / gist:1644272
Created January 20, 2012 01:17 — forked from mbrochh/gist:1055445
SHOP_CART_MODIFIER setting
SHOP_CART_MODIFIERS = [
'shop_simplevariations.cart_modifier.ProductOptionsModifier',
'myshop.modifiers.FixedShippingCosts',
'myshop.modifiers.FixedTaxRate',
]
@saidimu
saidimu / gist:1644288
Created January 20, 2012 01:17 — forked from mbrochh/gist:1055440
FixedShippingCosts cart modifier
class FixedShippingCosts(BaseCartModifier):
"""
This will add a fixed amount of money for shipping costs.
"""
def add_extra_cart_price_field(self, cart):
cart.extra_price_fields.append(
('Shipping costs', decimal.Decimal(
settings.SHOP_SHIPPING_FLAT_RATE)))
return cart
@saidimu
saidimu / gist:1644296
Created January 20, 2012 01:17 — forked from mbrochh/gist:1055432
Adding Tax to your cart
""" Cart modifierts for the myshop app of django-shop-adventures."""
import decimal
from django.conf import settings
from shop.cart.cart_modifiers_base import BaseCartModifier
class FixedTaxRate(BaseCartModifier):
"""
@saidimu
saidimu / gist:1644307
Created January 20, 2012 01:18 — forked from mbrochh/gist:1053339
Catching shop/cart/ URL for overriding django-shop's view class
from django.conf.urls.defaults import *
from django.contrib import admin
from shop import urls as shop_urls
from shop_simplevariations import urls as simplevariations_urls
admin.autodiscover()
@saidimu
saidimu / gist:1644328
Created January 20, 2012 01:21 — forked from mbrochh/gist:1053339
Catching shop/cart/ URL for overriding django-shop's view class
from django.conf.urls.defaults import *
from django.contrib import admin
from shop import urls as shop_urls
from shop_simplevariations import urls as simplevariations_urls
admin.autodiscover()