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
""" Django middleware that enforcess login for all urls except login and | |
additional exception defined via url regexp or django url names. | |
""" | |
from re import compile | |
from django.conf import settings | |
from django.http import HttpResponseRedirect | |
from django.utils.http import is_safe_url | |
from django.shortcuts import resolve_url | |
LOGIN_URL = resolve_url(settings.LOGIN_URL) |
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
from io import BytesIO | |
from PIL import Image, ImageOps | |
from django.core.files.base import ContentFile | |
from stdimage.models import StdImageField, StdImageFieldFile | |
class StdRescaledImageFieldFile(StdImageFieldFile): | |
def save(self, name, content, save=True): | |
img = Image.open(content) | |
file_format = img.format | |
img.thumbnail(self.field.image_size) |