Skip to content

Instantly share code, notes, and snippets.

View readevalprint's full-sized avatar
🤠
code is life

Tim readevalprint

🤠
code is life
View GitHub Profile
@readevalprint
readevalprint / serializer.py
Created September 25, 2013 20:39
django-haystack SearchResultSerializer from django-rest-framework
==== SNIP ====
class DistanceSerializer(serializers.Serializer):
km = serializers.FloatField()
m = serializers.FloatField()
mi = serializers.FloatField()
ft = serializers.FloatField()
class SearchResultSerializer(serializers.Serializer):
diff --git a/rest_framework/reverse.py b/rest_framework/reverse.py
index a51b07f..ceed09f 100644
--- a/rest_framework/reverse.py
+++ b/rest_framework/reverse.py
@@ -4,6 +4,9 @@ Provide reverse functions that return fully qualified URLs
from __future__ import unicode_literals
from django.core.urlresolvers import reverse as django_reverse
from django.utils.functional import lazy
+from django.core.urlresolvers import resolve
+from django.http import Http404
Environment:
Request Method: POST
Request URL: http://www.thefingo.com/payment/success
Django Version: 1.4.1
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
@readevalprint
readevalprint / gist:5222061
Last active December 15, 2015 07:18
seems legit!

Greetings : Watts

On behalf of the Trustees and Executor of the estate of Late (Engr . A Watts) I once again try to notify you as my earlier letter were returned undelivered. I wish to notify you that my late cleint made you a member of his family beneficiary before he died.He left the sum of (US$7 million) to you in the Codicil and lasttestament to his WILL.and also where these huge deposits were lodged declared as Family treasures of Gold Jewelry and personal precious effects.

As the personal lawyer of the deceased and the trustee of his estate, all I needed is your honest cooperation to standing as the only living relation and put claim over the release of the fund to you for our sharing. so if you response I will present you for the claim of (US$7 million) he left in a bank here in our country. I will inform you more once I receive positive response from you.Please as I directed this message to you personally, so treat as urgent and confidential.Reply to my private email ( jimabu10@live.fr )

Finally,

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="generator" content="CoffeeCup HTML Editor (www.coffeecup.com)">
<meta name="dcterms.created" content="Mon, 29 Oct 2012 22:24:36 GMT">
<meta name="description" content="">
<meta name="keywords" content="">
<title>Banana 1.1.1</title>
@readevalprint
readevalprint / su.py
Created June 13, 2012 21:21
make me a super users
# pip this to manage like $ cat su.py | ./manage.py shell
from user.models import User
u = User.objects.get(email="me@example.com")
u.is_staff = True
u.is_superuser = True
u.save()
@readevalprint
readevalprint / models.py
Created May 16, 2012 20:46
EmailAddress class
EMAIL_TYPE_CHOICES = (
('work', 'Work'),
('home', 'Person'),
('other', 'Other'),
)
class EmailAddress(models.Model):
email = models.EmailField(db_index=True, max_length=254, unique=True)
# Allows us to remove the choices and be backwards compatible
type = models.CharField(max_length=10, choices=EMAIL_TYPE_CHOICES)
@readevalprint
readevalprint / login_to_mozillians.py
Created May 1, 2012 22:01
Simple Webdriver & BrowserID login example for Mozillians
#!/usr/bin/env python
# To run this make sure you have selenium and bidpom
# pip install -U selenium
# git clone git://github.com/davehunt/bidpom.git
from selenium import webdriver
from bidpom.browser_id import BrowserID
browser = webdriver.Firefox()
browser.get('http://mozillians.allizom.org')
def _remap_date_counts(**kwargs):
"""Remap the query result.
From: [{'count': 2085, 'month': 11, 'year': 2010},...]
To: {'<label>': 2085, 'date': '2010-11-01'}
"""
for label, qs in kwargs.iteritems():
yield dict((date(x['year'], x['month'], 1), {label: x['count']})
for x in qs)
@readevalprint
readevalprint / django-sudo.py
Created December 14, 2011 19:49
Log in as a user in Django
from django.shortcuts import get_object_or_404
from django.contrib.auth import SESSION_KEY
from django import http
from django.contrib.auth.models import User
from django.contrib.auth.decorators import user_passes_test
@user_passes_test(lambda u: u.is_staff)
def su(request, username, redirect_url='/'):
su_user = get_object_or_404(User, username=username)
if su_user.is_active: