This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
class Vector(object): | |
def __init__(self, *args): | |
""" Create a vector, example: v = Vector(1,2) """ | |
if len(args)==0: self.values = (0,0) | |
else: self.values = args | |
def norm(self): | |
""" Returns the norm (length, magnitude) of the vector """ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Add user created_by and modified_by foreign key refs to any model automatically. | |
Almost entirely taken from https://github.com/Atomidata/django-audit-log/blob/master/audit_log/middleware.py""" | |
from django.db.models import signals | |
from django.utils.functional import curry | |
class WhodidMiddleware(object): | |
def process_request(self, request): | |
if not request.method in ('GET', 'HEAD', 'OPTIONS', 'TRACE'): | |
if hasattr(request, 'user') and request.user.is_authenticated(): | |
user = request.user |