Skip to content

Instantly share code, notes, and snippets.

Matt McClanahan mattmcc

  • Portland, OR
Block or report user

Report or block mattmcc

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
mattmcc /
Last active Oct 10, 2016
Django PDFResponse using weasyprint
from django.template.response import TemplateResponse
from django.views.generic import DetailView
from weasyprint import HTML
class PDFResponse(TemplateResponse):
def rendered_content(self):
template = self.resolve_template(self.template_name)
context = self.resolve_context(self.context_data)
View base.html
{% load sniplates %}
{% load_widgets core="widgets.html" _soft=True %}
{% block content %}
{% include "included_widget.html" %}
{% endblock %}
class ChoiceList(list):
def __init__(self, *args, **kwargs):
self.choices = kwargs.pop('choices')
super(ChoiceList, self).__init__(*args, **kwargs)
def items(self):
return [(k, v) for k, v in self.choices if k in self]
class ChoiceArrayField(ArrayField):
def __init__(self, *args, **kwargs):
mattmcc /
Created Mar 27, 2013
Quick & dirty "read-only" model for using SQL views
class ViewManager(models.Manager):
def bulk_create(self, *args, **kwargs):
raise NotImplementedError
def create(self, *args, **kwargs):
raise NotImplementedError
def get_or_create(self, *args, **kwargs):
raise NotImplementedError
mattmcc /
Created Jan 1, 2013
Preliminary ducktyping of ManyToManyField using django-orm-extensions' ArrayField and storing a list of PKs.
class QueryList(list):
A list of primary keys for a specified model which can act as a QuerySet
Takes a ``model`` keyword argument indicating which model the PKs are
associated with.
def __init__(self, *args, **kwargs):
self.model = kwargs.pop('model')
super(QueryList, self).__init__(*args, **kwargs)
You can’t perform that action at this time.