This file contains 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
# reference: https://goodcode.io/articles/django-download-url-to-file-field/ | |
from tempfile import TemporaryFile | |
from os.path import basename | |
from urllib.parse import urlsplit | |
from django.core.files import File | |
import requests | |
class Foo(models.Model): | |
This file contains 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
/** | |
* Sanitizer which filters a set of whitelisted tags, attributes and css. | |
* For now, the whitelist is small but can be easily extended. | |
* | |
* @param bool whether to escape or strip undesirable content. | |
* @param map of allowed tag-attribute-attribute-parsers. | |
* @param array of allowed css elements. | |
* @param array of allowed url scheme | |
*/ | |
function HtmlWhitelistedSanitizer(escape, tags, css, urls) { |
This file contains 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
# -*- coding: utf-8 -*- | |
# copied from django-cms | |
# https://github.com/divio/django-cms/blob/develop/cms/models/metaclasses.py | |
from cms.publisher.manager import PublisherManager | |
from django.db.models.base import ModelBase | |
class PageMetaClass(ModelBase): |
This file contains 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
# modified from https://gist.github.com/gavinballard/8513270 | |
from functools import wraps | |
import hashlib | |
import base64 | |
import hmac | |
import json | |
from django.conf import settings |