Skip to content

Instantly share code, notes, and snippets.

@danleyb2
danleyb2 / cirm.py
Created August 15, 2017 05:20
Plot a given number of equally spaced circumferance cordinates on a x,y center with given radius
import math
from math import pi
def points_on_circumference(center=(0, 0), r=50, n=100):
return [
(
center[0]+(math.cos(2 * pi / n * x) * r), # x
center[1] + (math.sin(2 * pi / n * x) * r) # y
@twidi
twidi / drf_utils.py
Created December 21, 2016 14:34
Make Django Rest Framework correctly handle Django ValidationError raised in the save method of a model
"""
Sometimes in your Django model you want to raise a ``ValidationError`` in the ``save`` method, for
some reason.
This exception is not managed by Django Rest Framework because it occurs after its validation
process. So at the end, you'll have a 500.
Correcting this is as simple as overriding the exception handler, by converting the Django
``ValidationError`` to a DRF one.
"""
from django.core.exceptions import ValidationError as DjangoValidationError