Skip to content

Instantly share code, notes, and snippets.

View bendavis78's full-sized avatar

Ben Davis bendavis78

  • O'Reilly Media
  • Dallas, TX
View GitHub Profile
class ProductAdmin(BaseProductAdmin):
list_display = ['_name_with_thumb', 'price', 'in_stock']
form = ProductForm
fields = ['name','description','price','product_line','categories']
prepopulated_fields = {}
def _thumb(self, obj):
thumbnail_opts = {'size': (150,150)}
if obj.images.count() == 0:
return '[no image]'
# Apply lookup parameters from the query string.
try:
qs = qs.filter(**lookup_params)
# Naked except! Because we don't have any other way of validating "params".
# They might be invalid if the keyword arguments are incorrect, or if the
# values are not in the correct type, so we might get FieldError, ValueError,
# ValicationError, or ? from a custom field that raises yet something else
# when handed impossible data.
except:
from django.db import models
from django.contrib.auth.models import User
from orderable.models import OrderableModel
class Client(models.Model):
name = models.CharField(max_length=100)
def __unicode__(self):
return self.name
class BuyerIntentMapBanner(CMSPluginBase):
model = CMSPlugin
name = "Buyer Intent Map Banner"
render_template = "plugins/buyerintentmap_banner.html"
text_enabled = True
def render(self, context, instance, placeholder):
return context
class Media:
class DonorDetail(detail.DetailView, edit.ProcessFormView, edit.FormMixin):
model = models.Donor
form_class = inlineformset_factory(models.Donor, models.DonorDocument)
def get_form_kwargs(self):
kwargs = super(DonorDetail, self).get_form_kwargs()
kwargs.update({
'instance': self.object
})
from __main__ import set_trace, post_mortem, pm
pm # please pyflakes
post_mortem # please pyflakes
set_trace # please pyflakes
traceroute to docs.python.org (82.94.164.162), 30 hops max, 60 byte packets
1 Farstar-AirPort-Extreme.local (10.0.1.1) 1.394 ms 1.457 ms 1.927 ms
2 10.72.49.1 (10.72.49.1) 18.693 ms 19.374 ms 31.278 ms
3 24.164.208.69 (24.164.208.69) 24.118 ms 24.339 ms 24.558 ms
4 70.125.217.52 (70.125.217.52) 25.627 ms 25.895 ms 26.182 ms
5 tengig.0-2-0-3.dllatxchn-rtr6.tx.rr.com (24.164.210.115) 29.729 ms 30.000 ms 30.228 ms
6 gig2-0-2.hstntxl3-rtr1.texas.rr.com (72.179.205.50) 32.555 ms 55.440 ms 22.401 ms
7 ae-4-0.cr0.hou30.tbone.rr.com (66.109.6.54) 22.630 ms 22.980 ms 23.372 ms
8 ae-4-0.cr0.sjc10.tbone.rr.com (66.109.6.11) 78.501 ms 101.008 ms 101.031 ms
9 ae-0-0.pr0.sjc10.tbone.rr.com (66.109.6.141) 76.176 ms 76.324 ms 77.453 ms
class OrderCobranderForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(OrderCobranderForm, self).__init__(*args, **kwargs)
self.fields['ship_to'].empty_label = None
class Meta:
model = models.OrderCobrander
widgets = {
'ship_to': forms.RadioSelect(),
}
# Reset
NoColor='\e[0m' # Text Reset
# Regular Colors
Black='\e[0;30m' # Black
Red='\e[0;31m' # Red
Green='\e[0;32m' # Green
Yellow='\e[0;33m' # Yellow
Blue='\e[0;34m' # Blue
Purple='\e[0;35m' # Purple
#!/bin/bash
DB=$1
USER=$2
if [[ ! ("$USER" && "$DB") ]]; then
echo "Usage: $0 <db> <user>"
exit 1;
fi
echo "\dt" | psql $DB -t | cut -d '|' -f 2 | sed -e 's/ //' | grep -v ^$ | while read t; do echo "GRANT ALL ON TABLE $t TO $USER" | psql $DB; done
echo "\ds" | psql $DB -t | cut -d '|' -f 2 | sed -e 's/ //' | grep -v ^$ | while read s; do echo "GRANT ALL ON SEQUENCE $s TO $USER" | psql $DB; done