Skip to content

Instantly share code, notes, and snippets.

View wwitzel3's full-sized avatar

Wayne Witzel III wwitzel3

View GitHub Profile
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title></title>
</head>
<body>
<h4>
Shipping Information
</h4>
<p>
@wwitzel3
wwitzel3 / horrible_idea.py
Created January 25, 2011 23:45
Is this a horrible idea?
>>> class Booltring(object):
... def __nonzero__(self):
... return False
... def __str__(self):
... return 'X'
...
>>> b = Booltring()
>>> bool(b)
False
>>> print b
@wwitzel3
wwitzel3 / pyramid_acl.py
Created January 26, 2011 18:12
Why forbidden? ..
class UserContainer(ModelContainer):
__acl__ = [
(Allow, 'admin', ('add', 'edit', 'delete')),
(Deny, Everyone, ALL_PERMISSIONS)
]
@view_config(renderer='users_browse.mako', context=UserContainer, permission='view')
def browse(request):
return dict()
@wwitzel3
wwitzel3 / forms.py
Created January 26, 2011 20:09
formencode examples ...
class UniqueEmailChange(formencode.FancyValidator):
def validate_python(self, values, c):
account = meta.Session.query(Account).filter_by(email=values['email']).first()
if account and values['profile_id'] not in [profile.id for profile in account.profiles]:
raise formencode.Invalid(
'That email address is already in use.',
values, c, error_dict=dict(email='That email address is already in use.'))
class EditProfileForm(formencode.Schema):
allow_extra_fields = True
@wwitzel3
wwitzel3 / root.py
Created January 27, 2011 00:14
like dis? like dat?
from pyramid.security import Allow, Deny
from pyramid.security import Authenticated, Everyone
from pyramid.security import ALL_PERMISSIONS
from pyramid.security import unauthenticated_userid
import ordereddict
from riotoustools.models import DBSession
from riotoustools.models.dayzero import DayZeroList
from riotoustools.models.dayzero import DayZeroItem
@wwitzel3
wwitzel3 / super hack.py
Created January 28, 2011 02:13
add this to my SA objects
@property
def __parent__(self):
class Root(object):
__name__ = None
__parent__ = None
class Item(object):
__name__ = 'dayzeroitem'
__parent__ = Root()
Traceback (most recent call last):
File "/Users/wwitzel/code/riotoustools/tests/functional/test_default_views.py", line 7, in setUp
self.app = TestApp(main({}, **settings))
File "/Users/wwitzel/code/riotoustools/riotoustools/__init__.py", line 39, in main
config.scan('riotoustools.models')
File "/Users/wwitzel/.envs/pyramid/lib/python2.6/site-packages/pyramid-1.0a10-py2.6.egg/pyramid/config.py", line 1804, in scan
scanner.scan(package, categories=categories)
File "/Users/wwitzel/.envs/pyramid/lib/python2.6/site-packages/venusian/__init__.py", line 40, in scan
invoke(name, ob)
File "/Users/wwitzel/.envs/pyramid/lib/python2.6/site-packages/venusian/__init__.py", line 33, in invoke
@wwitzel3
wwitzel3 / blogofile master
Created March 1, 2011 23:40
default blog init / build
(riotous)boi-mac-wwitzel:riotousbeta wayne.witzel$ blogofile build
ERROR:blogofile.post:Error reading post: _posts/001 - post 1.markdown
Traceback (most recent call last):
File "_controllers/blog/post.py", line 329, in parse_posts
bf.config.controllers.blog.post_encoding)
TypeError: decode() argument 1 must be string, not HierarchicalCache
Traceback (most recent call last):
File "/Users/wayne.witzel/.virtualenvs/riotous/bin/blogofile", line 8, in <module>
load_entry_point('Blogofile==1.0.0-DEV', 'console_scripts', 'blogofile')()
File "/Users/wayne.witzel/code/blogofile/blogofile/main.py", line 134, in main
@wwitzel3
wwitzel3 / parse_yaml_snippet.py
Created March 7, 2011 20:57
automatically scale and make thumbs of a featured image set in the yaml header.
try:
image = y['image']
image_fd = os.path.join(bf.config.blog.media_path, image)
from PIL import Image
pImage = Image.open(image_fd)
image_path = image.split(os.sep)
image_name = image_path[-1]
@wwitzel3
wwitzel3 / pop.py
Created July 20, 2011 14:36
saving an in memory file to disk
# Minus some boiler plate for validity and variable setup.
import os
import shutil
memory_file = request.POST['upload']
disk_file = open(os.path.join(save_folder, save_name),'w')
shutil.copyfileobj(memory_file.file, disk_file)
disk_file.close()