Skip to content

Instantly share code, notes, and snippets.

View maxmumford's full-sized avatar

Max Mumford maxmumford

  • Cocept
  • Brighton
View GitHub Profile
<div class="_all_wplink_rwPUIFu9_cc" style="position:absolute;opacity:0.001;z-index:10;filter:alpha(opacity=0)">
... spammy text and links to knockoff fashion sites ...
</div>
<form action="//formspree.io/your@email.com" method="POST">
<input type="text" name="name">
<input type="email" name="_replyto">
<input type="submit" value="Send">
</form>
class Tenancy(models.Model):
building = models.ForeignKey(Building)
class Building(models.Model):
owner = models.ForeignKey(User)
class BuildingForm(CustomModelForm):
pass
class CustomModelForm(forms.ModelForm):
"""
Sandboxes user data for each reference field pointing to an
object with an "owner" field.
"""
def __init__(self, request, *args, **kwargs):
# cache the request object
self.request = request
init_result = super(CustomModelForm, self).__init__(*args, **kwargs)
@maxmumford
maxmumford / random-ean13.py
Created August 14, 2014 09:40
Random EAN13 Generator
#! /usr/bin/python
"""
This script generates a random EAN13 number and prints it to the standard out.
"""
from random import randrange
def generate_12_random_numbers():
numbers = []
for x in range(12):
numbers.append(randrange(10))
import base64
from osv import osv, fields
class my_class(osv.osv_memory):
def get_file(self, cr, uid, ids, field_name=None, arg=None, context=None):
result = dict.fromkeys(ids)
for record_browse in self.browse(cr, uid, ids):
f = open(record_browse.file_path)
result[record_browse.id] = base64.encodestring(f.read())