brew install imagemagick
convert image.png output.pdf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def write_csv_from_queryset(queryset, fields, output=None): | |
""" | |
>>> from django.contrib.auth.models import User | |
>>> qs = User.objects.all()[:5] | |
>>> write_csv_from_queryset(qs, 'username') | |
>>> write_csv_from_queryset(qs, ['username', 'is_superuser']) | |
""" | |
import csv | |
import datetime |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
from io import TextIOWrapper | |
from collections import namedtuple | |
class InvalidCSVFileException(Exception): | |
pass | |
class MissingCSVHeadersException(Exception): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import datetime | |
import logging | |
from pathlib import Path | |
logger = logging.getLogger(__name__) | |
def write_csv_from_queryset(queryset, fields, output=None): | |
output_filename = Path(str(output) if isinstance(output, (Path, str)) else f'{queryset.model._meta.model_name}_{datetime.datetime.now():%Y-%m-%d__%H_%M_%S}.csv') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib.auth.models import AbstractUser | |
from django.db.models import CharField, Field, Model | |
from django.urls import reverse | |
from django.utils.translation import gettext_lazy as _ | |
class AliasField(Field): | |
# based on https://djangosnippets.org/snippets/10440/ | |
def __init__(self, alias_from, editable=True): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pycallgraph import PyCallGraph | |
from pycallgraph import Config | |
from pycallgraph import GlobbingFilter | |
from pycallgraph.output import GraphvizOutput | |
class ProfilerMiddleware(object): | |
includes = [] | |
def can(self, request): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.DEFAULT_GOAL := help | |
define PRINT_HELP_PYSCRIPT | |
import re, sys | |
output = [] | |
for line in sys.stdin: | |
match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line) | |
if match: | |
target, help = match.groups() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io | |
from django.core.mail import EmailMessage | |
from wkhtmltopdf.views import PDFTemplateView | |
class MyPDFTemplateView(PDFTemplateView): | |
def render_to_response(self, context, **response_kwargs): | |
response_instance = super(MyPDFTemplateView, self).render_to_response(context, **response_kwargs) | |
pdf_content = io.BytesIO(response_instance.rendered_content) | |
pdf_content.seek(0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Step 7/10 : RUN echo -e "\n\nInstalling Bookdown...\n\n" && Rscript -e "install.packages('bookdown', repository='http://mirror.utexas.edu/ctan/')" && echo -e "\n\nInstalling Tinytex...\n\n" && Rscript -e "install.packages('tinytex', repository='http://mirror.utexas.edu/ctan/')" && echo -e "\n\nInstalling Latex packages via Tinytex...\n\n" && Rscript -e "tinytex::install_tinytex(repository='http://mirror.utexas.edu/ctan/', extra_packages=c('luahbtex', 'lm-math', 'unicode-math'))" && echo -e "\n\nReinstalling Latex packages via Tinytex...\n\n" && Rscript -e "tinytex::reinstall_tinytex()" | |
---> Running in 06a01042e395 | |
-e | |
Installing Bookdown... | |
Installing package into ‘/usr/local/lib/R/site-library’ | |
(as ‘lib’ is unspecified) | |
also installing the dependencies ‘glue’, ‘magrittr’, ‘stringi’, ‘digest’, ‘Rcpp’, ‘rlang’, ‘evaluate’, ‘highr’, ‘markdown’, ‘stringr’, ‘yaml’, ‘base64enc’, ‘jsonlite’, ‘mime’, ‘htmltools’, ‘knitr’, ‘rmarkdown’, ‘xfun’, ‘tinytex’ |
The install command:
RUN Rscript -e "install.packages('bookdown', repository='http://mirror.utexas.edu/ctan/')" \
&& Rscript -e "install.packages('tinytex', repository='http://mirror.utexas.edu/ctan/')" \
&& Rscript -e "tinytex::install_tinytex(repository='http://mirror.utexas.edu/ctan/')" \
&& Rscript -e "tinytex::tlmgr_install(c('lm-math', 'unicode-math'))"