Skip to content

Instantly share code, notes, and snippets.

@smithdc1
smithdc1 / class.patch
Created October 26, 2021 14:57
Patch to add class level attributes for error_css_class and required_css_class
commit 554a7430a2947f67e2316a6775654c66070d75a2
Author: David Smith <smithdc@gmail.com>
Date: Tue Oct 26 15:55:57 2021 +0100
Sample class attribute patch
diff --git a/django/forms/boundfield.py b/django/forms/boundfield.py
index 5bbfcbe41c..a971407d0c 100644
--- a/django/forms/boundfield.py
+++ b/django/forms/boundfield.py
@smithdc1
smithdc1 / crispy_form_bench.py
Last active July 6, 2021 19:26
A benchmark for crispy-forms
import pyperf
import django
from django.conf import settings
from django.forms import CharField, FloatField, Form, HiddenInput, IntegerField
from django.template.base import Template
from django.template.context import Context
from django.utils.functional import SimpleLazyObject
from crispy_forms.helper import FormHelper
@smithdc1
smithdc1 / bench_decminal_field.py
Created January 15, 2021 16:32
Benchmark for DecimalField.to_python()
from django.conf.global_settings import INSTALLED_APPS
import django
from django.conf import settings
from django.forms import DecimalField
import pyperf
settings.configure(INSTALLED_APPS= ('__main__',))
django.setup()
@smithdc1
smithdc1 / bench_get_parent_list.py
Created January 15, 2021 13:15
Benchmark for `get_parent_list()`
from django.conf.global_settings import INSTALLED_APPS
import django
from django.db import models
from django.conf import settings
import pyperf
settings.configure(INSTALLED_APPS= ('__main__',))
django.setup()
# models
@smithdc1
smithdc1 / bench_Media_merge.py
Last active January 11, 2021 20:46
Benchmark for merging widget media
import django
from django import forms
from django.conf import settings
from django.forms import Media
settings.configure()
django.setup()
@smithdc1
smithdc1 / bench_resolve.py
Created January 7, 2021 20:04
Benchmark Django's resolve()
import pyperf
import django
from django.conf import settings
from django.urls import re_path, resolve
settings.configure(ROOT_URLCONF=__name__)
django.setup()
@smithdc1
smithdc1 / bench_cached_property_decorator.py
Last active March 11, 2021 11:44
Benchmark of Django and Python's cached_property decorators
import pyperf
from django.utils.functional import cached_property as dj_cached_property
from functools import cached_property as py_cached_property
class TestClass:
@dj_cached_property
def dj_cached(self):
return "Test"
@smithdc1
smithdc1 / bench_list_comprehension_generator.py
Created January 2, 2021 10:43
Benchmark of list comprehension and generator being provided to tuple()
import pyperf
small_data = {"a": 1, "b": 2, "c": 3}
large_data = {}
for k, v in enumerate(range(100_000)):
large_data[k] = v
def list_comprehension(loops, data):
repos:
- repo: https://github.com/timothycrosley/isort
rev: 5.6.4
hooks:
- id: isort
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
hooks:
- id: flake8
- repo: https://github.com/pre-commit/pre-commit-hooks
@smithdc1
smithdc1 / build_error_dict.py
Created August 3, 2020 21:15
#24782 -- Added TestCase.assertFormValid
from django.utils.translation import ngettext_lazy
from django.core.validators import validate_email
from django.forms import Form, CharField, IntegerField, PasswordInput
from django.conf import settings
from django.forms.utils import ErrorList, ErrorDict, ValidationError
import django
settings.configure()
django.setup()