- We've got some components
A,BandCwhich provide different slots.const A = { template: `<div><slot name="a">Default A Content</slot></div>` }
const B = {
| from django.db.models import Q | |
| from django.db.models.constants import LOOKUP_SEP | |
| from django_filters import rest_framework as django_filters | |
| from django_filters.constants import EMPTY_VALUES | |
| class GroupFilterSet(django_filters.FilterSet): | |
| def filter_queryset(self, queryset): | |
| """ | |
| Group the fitlers by the first join table to |
| # Add this code in any Django app's admin.py | |
| # Works for all Task Statuses; you can filter them in line 12. | |
| import ast | |
| import importlib | |
| import json | |
| from django.contrib import admin | |
| from django.contrib import messages | |
| from django.utils.safestring import mark_safe |
| class GroupFilter: | |
| """ | |
| The work here is largely cherry-picked from this unmerged django-filters PR: | |
| https://github.com/carltongibson/django-filter/pull/1167/files | |
| """ | |
| def __init__(self, filter_names): | |
| self.filter_names = filter_names | |
| def set_parent(self, parent): |
| # -*- coding: utf-8; mode: django -*- | |
| import graphviz | |
| from optparse import make_option | |
| from django.core.management.base import BaseCommand | |
| from django.utils.encoding import force_text | |
| from django_fsm import FSMFieldMixin, GET_STATE, RETURN_VALUE | |
| try: |
| class CustomTask(Task): | |
| def on_failure(self, exc, task_id, args, kwargs, einfo): | |
| info = '[{0}] failed: {1}'.format(task_id, exc) | |
| logger.exception(info, exc_info=exc) | |
| super(CustomTask, self).on_failure(exc, task_id, args, kwargs, einfo) | |
| def on_success(self, retval, task_id, args, kwargs): | |
| global app | |
| if app.is_warm_shutdown: | |
| app.consumer.connection._default_channel.do_restore = False |
| # coding: utf-8 | |
| from __future__ import unicode_literals | |
| import os | |
| from pdfminer.pdfdocument import PDFEncryptionError | |
| from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter | |
| from pdfminer.converter import TextConverter | |
| from pdfminer.layout import LAParams | |
| from pdfminer.pdfpage import PDFPage | |
| from cStringIO import StringIO |
| // XPath CheatSheet | |
| // To test XPath in your Chrome Debugger: $x('/html/body') | |
| // http://www.jittuu.com/2012/2/14/Testing-XPath-In-Chrome/ | |
| // 0. XPath Examples. | |
| // More: http://xpath.alephzarro.com/content/cheatsheet.html | |
| '//hr[@class="edge" and position()=1]' // every first hr of 'edge' class |
Magic words:
psql -U postgresSome interesting flags (to see all, use -h or --help depending on your psql version):
-E: will describe the underlaying queries of the \ commands (cool for learning!)-l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)I'm going to cover a simple, but effective, utility for managing state and transitions (aka workflow). We often need to store the state (status) of a model and it should only be in one state at a time.