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
class DeferredHTMLMiddleware): | |
"""Adds `deferred_html` to request. | |
Use with the defer and render_deferred template tags. | |
""" | |
def __init__(self, get_response: Callable): | |
self.get_response = get_resposne | |
def __call__(self, request: HttpRequest) -> HttpResponse: |
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
- name: Install K3s | |
hosts: kubernetes | |
remote_user: root | |
become: false | |
vars: | |
ansible_user: root | |
vars_files: | |
- vars/config.yml | |
- vars/secrets.yml | |
tasks: |
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
- name: Install dependencies | |
ansible.builtin.apt: | |
name: "{{ item }}" | |
state: present | |
update_cache: true | |
loop: | |
- apt-transport-https | |
- ca-certificates | |
- curl | |
- gnupg-agent |
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 | |
class CSVBuffer: | |
"""Handles CSV output.""" | |
def write(self, value): | |
"""Handles file-like write, just returning the value""" | |
return value | |
def download_csv(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
{# | |
class ReviewForm(forms.ModelForm): | |
class Meta: | |
model = Review | |
fields = ( | |
"comment", | |
"score", | |
) | |
help_texts: ClassVar = { |
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
class TestMarkdown: | |
@pytest.mark.parametrize( | |
("value", "expected"), | |
[ | |
pytest.param(None, "", id="none"), | |
pytest.param("", "", id="empty"), | |
pytest.param("test", "<p>test</p>\n", id="text"), | |
pytest.param(" ", "", id="space"), | |
pytest.param("<p>test</p>", "<p>test</p>", id="html"), | |
pytest.param("<p>test</p> ", "<p>test</p>", id="html and spaces"), |
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
class CoverImage extends HTMLElement { | |
/* | |
Usage: | |
<cover-image placeholder="placeholder.jpg"> | |
<img src="cover.jpg" loading"lazy"> | |
</cover-image> | |
*/ | |
connectedCallback() { | |
const images = this.querySelectorAll("img"); | |
const placeholder = this.getAttribute("placeholder"); |
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.http import HttpRequest, HttpResponse | |
from django.template.response import TemplateResponse | |
from render_block import render_block_to_string | |
def render_template_fragments( | |
request: HttpRequest, | |
template_name: str, | |
context: dict | None = None, | |
*, |
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
# https://docs.djangoproject.com/en/4.2/topics/forms/ | |
# original example | |
def get_name(request): | |
# if this is a POST request we need to process the form data | |
if request.method == "POST": | |
# create a form instance and populate it with data from the request: | |
form = NameForm(request.POST) | |
# check whether it's valid: | |
if form.is_valid(): | |
# process the data in form.cleaned_data as required |
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
# example from Django docs https://docs.djangoproject.com/en/4.2/topics/forms/ | |
def get_name(request): | |
# if this is a POST request we need to process the form data | |
if request.method == "POST": | |
# create a form instance and populate it with data from the request: | |
form = NameForm(request.POST) | |
# check whether it's valid: | |
if form.is_valid(): | |
# process the data in form.cleaned_data as required | |
# ... |
NewerOlder