Skip to content

Instantly share code, notes, and snippets.

View dfalk's full-sized avatar

Dmitry Falk dfalk

  • freelancer
  • Russia, Yoshkar-Ola
View GitHub Profile
@dfalk
dfalk / gist:3071831
Created July 8, 2012 17:11
mez meta
meta_title = models.CharField(_("Html title"), max_length=500, blank=True)
add_suffix = models.BooleanField(_("Add suffix with site title"),
help_text=("If checked, site title will be added to the end of "
"html title tag."), default=True)
@dfalk
dfalk / adminthumbnail.py
Created April 16, 2012 11:22 — forked from h3/adminthumbnail.py
AdminThumbnailMixin
from django.contrib import admin
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from easy_thumbnails.files import get_thumbnailer
class AdminThumbnailMixin(object):
thumbnail_options = {'size': (60, 60)}
thumbnail_image_field_name = 'image'
thumbnail_alt_field_name = None
@dfalk
dfalk / README.rst
Created February 29, 2012 11:39
Using django-floppyforms with django-sekizai

This is a bridge between django-floppyforms and django-sekizai.

This lets you define custom floppyforms widgets and move the css / js parts to the top or the bottom of the page.

Just write a floppyforms widget with a custom template. In that template, use {% addtoblock "js" %} to inject some data in a sekizai block. In the template that renders your form, make sure you use iterate over your fields and use {% widget field %} to render instead of {{ field }}.

Note that to render your widget separately in the console, you'll need to add enable_sekizai in one of your app's templatetags and do {% load enable_sekizai %}{% enable_sekizai %}. Note that anything inside the {% addtoblock %} tags will disappear but your widgets can be rendered in the console.

Not sure this plays well with hidden widgets. Use at your own risk.

@dfalk
dfalk / postprocess_sekizai.py
Created February 28, 2012 04:43 — forked from timmyomahony/postprocess_sekizai.py
django-sekizai postprocessor for enabling django-compressor compatibility
"""
Get django-sekizai, django-compessor (and django-cms) playing nicely together
re: https://github.com/ojii/django-sekizai/issues/4
using: https://github.com/jezdez/django_compressor.git
and: https://github.com/ojii/django-sekizai.git@0.5
"""
from compressor.templatetags.compress import CompressorNode
from django.template.base import *
def compress(data, name):
@dfalk
dfalk / abstract.py
Created February 7, 2012 04:46 — forked from patrys/abstract.py
Parametrized apps for Django
class AbstractMixin(object):
_classcache = {}
@classmethod
def contribute(cls):
return {}
@classmethod
def construct(cls, *args, **kwargs):
attrs = cls.contribute(*args, **kwargs)
@dfalk
dfalk / gist:1740720
Created February 4, 2012 22:29
django site in context
#myproject/context_processors.py:
from django.contrib.sites.models import Site
def site(request):
'''
A context processor to add the current site to the current Context
'''
try:
site = Site.objects.get_current()
@dfalk
dfalk / __init__.py
Created February 4, 2012 22:18 — forked from SmileyChris/__init__.py
a Django site_settings app
from django.conf import settings
from django.contrib.sites.models import Site
from django.core.cache import cache
from project.apps.site_settings import models
KEY = 'site-settings-%d' % settings.SITE_ID
def get_settings(from_cache=True):
"""
@dfalk
dfalk / gist:1536295
Created December 29, 2011 21:31
django subdomains
class SubdomainMiddleware:
""" Make the subdomain publicly available to classes """
def process_request(self, request):
domain_parts = request.get_host().split('.')
if (len(domain_parts) > 2):
subdomain = domain_parts[0]
if (subdomain.lower() == 'www'):
subdomain = None
domain = '.'.join(domain_parts[1:])
@dfalk
dfalk / gist:1532789
Created December 29, 2011 07:58
django 404 context
# File handlers.py
from django.shortcuts import render_to_response
from django.template import RequestContext, Context
from functools import partial
def base_error(request, template_name=None):
try:
context = RequestContext(request)
except:
@dfalk
dfalk / gist:1527620
Created December 28, 2011 11:23
django admin utf8 usernames
# -*- coding: utf-8 -*-
from django import forms
from django.utils.translation import ugettext, ugettext_lazy as _
from django.contrib.auth.models import User
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
import re