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 DictToObject: | |
def __init__(self, data): | |
for name, value in data.iteritems(): | |
setattr(self, name, self._wrap(value)) | |
def _wrap(self, value): | |
if isinstance(value, (tuple, list, set, frozenset)): | |
return type(value)([self._wrap(v) for v in value]) | |
else: | |
return Struct(value) if isinstance(value, dict) else value |
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 re | |
from django.utils.html import strip_spaces_between_tags | |
from django.conf import settings | |
RE_MULTISPACE = re.compile(r"\s{2,}") | |
RE_NEWLINE = re.compile(r"\n") | |
class MinifyHTMLMiddleware(object): | |
def process_response(self, request, response): | |
if 'text/html' in response['Content-Type'] and settings.COMPRESS_HTML and not re.match('^/admin/.*$', request.path): |
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
#admin.py | |
from django.contrib.sites.models import Site | |
class ExtendedFlatPageAdmin(FlatPageAdmin): | |
fieldsets = ( | |
(None, {'fields': ('url', 'title', 'content', 'sites', )}), | |
) | |
def formfield_for_manytomany(self, db_field, request=None, **kwargs): |
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.contrib.admin.widgets import FilteredSelectMultiple | |
from django import forms | |
def widget(model_reference, field, title, titlew): | |
class WidgetForm(forms.ModelForm): | |
vars()[field] = forms.ModelMultipleChoiceField(queryset=model_reference.objects.all(), | |
label=(title), | |
widget=FilteredSelectMultiple( | |
(titlew), | |
False, |
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
<!DOCTYPE html> | |
<head> | |
<title></title> | |
<style> | |
html { | |
position: relative; | |
min-height: 100%; | |
} | |
body { | |
margin: 0 0 100px; /* bottom = footer height */ |
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
Local: | |
./manage.py dumpdata all.json | |
Remote: | |
./manage.py syncdb | |
psql [DBNAME] | |
delete from auth_group_permissions; delete from auth_permission; delete from django_admin_log; delete from django_content_type; |
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
header("Cache-Control: must-revalidate"); | |
header("Pragma: must-revalidate"); | |
header("Content-type: application/vnd.ms-excel; charset=URF-16LE"); | |
header("Content-disposition: attachment; filename=file.csv"); | |
echo chr( 0xFF ) . chr( 0xFE ) . mb_convert_encoding( $content, 'UTF-16LE', 'UTF-8' ); |
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
def translit(locallangstring): | |
conversion = { | |
u'\u0410' : 'A', u'\u0430' : 'a', | |
u'\u0411' : 'B', u'\u0431' : 'b', | |
u'\u0412' : 'V', u'\u0432' : 'v', | |
u'\u0413' : 'G', u'\u0433' : 'g', | |
u'\u0414' : 'D', u'\u0434' : 'd', | |
u'\u0415' : 'E', u'\u0435' : 'e', | |
u'\u0401' : 'Yo', u'\u0451' : 'yo', | |
u'\u0416' : 'Zh', u'\u0436' : 'zh', |
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
var secret = $('<div>').attr('id', 'secret-meter'), | |
loadNow = 0, | |
loadTotal = 0; | |
$('body').prepend(secret); | |
$('.dialog').click(function(){ | |
var url = $(this)[0].href, | |
loadWindow = function() { | |
$.nmData(secret.html(), { | |
closeButton: '<a href="#" class="nyroModalClose nyroModalCloseButton nmReposition" title="close"></a>', |
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
{% extends "admin/base.html" %} | |
{% load i18n %} | |
{% block extrahead %} | |
<script type="text/javascript" src="/static/ckeditor/ckeditor.js"></script> | |
<script type="text/javascript"> | |
grp.jQuery(function(){ | |
config = { | |
'toolbar': [ | |
[ |