Skip to content

Instantly share code, notes, and snippets.

View cwurld's full-sized avatar

Chuck Martin cwurld

View GitHub Profile
@cwurld
cwurld / container_with_items.py
Last active October 19, 2017 18:57
Django Container with Items - (e.g. inlineformset_factory)
from django.forms.models import inlineformset_factory
from django.shortcuts import render
def container_with_items(request, container_id):
ItemFormSet = inlineformset_factory(
models.Container, models.Item, form=forms.InlineItemForm, fk_name='container', extra=1
)
# Use this to layout the Item forms
@cwurld
cwurld / xlsxwriter_cheatsheet.py
Last active November 6, 2019 06:47
xlsxwriter Cheat Sheet
# xlsxwriter Cheat Sheet
#
# xlsxwriter is an awesome package for writing Excel spreadsheets. It's got excellent documentation. And it's got
# way more functionality than I need. This cheat sheet contains the basic functionality that I use all the time.
#
# While it is possible to put formulas in the spreadsheet, I have had some problems with spreadsheets as email attachments
# when the spreadsheet has formulas and the email client is on mobile.
import xlsxwriter
@cwurld
cwurld / django_model_formset.py
Last active April 22, 2022 01:56
Django model formset example
from django.forms.models import inlineformset_factory
from django.shortcuts import render
from django.http import HttpResponseRedirect
from django import forms
from crispy_forms.helper import FormHelper
# The forms ---------------------------------------------------------------------------------------------------------
@cwurld
cwurld / select2_for_selenium.py
Created July 7, 2020 17:07
Code to manipulate a Select2 widget from Selenium as if it were a normal Select
from collections import namedtuple
# Javascript scripts -----------------------------------------------------------------------------------------------
SELECT_BY_VALUE = \
'''
$(arguments[0]).val(arguments[1]);
$(arguments[0]).trigger('change');
'''