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
<!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
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
#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
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
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
<? | |
function MYMODULE_form_node_admin_content_alter(&$form, &$form_state, $form_id) { | |
$column_alias = 'my_cool_column'; | |
$column_title = 'Header of my cool column'; | |
// Load the nodes. This incurrs very little overhead as | |
// "$nodes = node_load_multiple($nids);" has already been run on these | |
// nids in node_admin_nodes(). The static cache will be used instead of | |
// another db query being invoked | |
$nodes = node_load_multiple(array_keys($form['admin']['nodes']['#options'])); |
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
# pluralize for russian language | |
# {{someval|rupluralize:"товар,товара,товаров"}} | |
@register.filter(is_safe = False) | |
@stringfilter | |
def rupluralize(value, arg): | |
bits = arg.split(u',') | |
try: | |
value = str( 0 if not value or value <= 0 else value )[-1:] # patched version | |
return bits[ 0 if value=='1' else (1 if value in '234' else 2) ] | |
except: |
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
# bash | |
alias rr=". ~/.bash_profile" | |
alias ..="cd .." | |
alias ...="cd ../.." | |
alias ....="cd ../../.." | |
alias .....="cd ../../../.." | |
alias ......="cd ../../../../.." | |
alias c=clear | |
function freem() { |