Skip to content

Instantly share code, notes, and snippets.

@RafGb
RafGb / channels_delayed_tasks_worker.py
Created July 13, 2016 07:53
Delayed task queue for django-channels
import channels
import time
import redis
import Queue
import select
from redis.exceptions import (
ConnectionError,
TimeoutError,
)
from channels.log import setup_logger
# Есть стандартный способ создавать динамические формы в django:
# http://jacobian.org/writing/dynamic-form-generation/
# Но если использовать такую форму в админке, динамические поля не будут показаны, тк BaseModelAdmin.get_fieldsets использует свойство # base_fields класса формы, а не fileds экземпляра.
# Я нашел такое решение (В данном случае это Inline, но можно использовать где угодно):
class AndswerInline(admin.StackedInline):
form = AndswerInlineForm
def __init__(self, *args, **kwargs):
@RafGb
RafGb / gist:8321212
Created January 8, 2014 17:55
django fixing photo orientation
import os
from django.core.files.uploadedfile import InMemoryUploadedFile, TemporaryUploadedFile
from PIL import Image
from PIL.ExifTags import TAGS
from cStringIO import StringIO
def orientation_rotation(im):
#take pil Image insctance and if need rotate it
orientation = None