Skip to content

Instantly share code, notes, and snippets.

View collinanderson's full-sized avatar

Collin Anderson collinanderson

  • South Bend, Indiana
View GitHub Profile

Fix locale problem

Run the following command

$ update-locale LC_ALL="en_US.UTF-8"

If it failed, you will need to add the following to /var/lib/locales/supported.d/local file

en_US.UTF-8 UTF-8

@collinanderson
collinanderson / manage.py
Created August 12, 2014 12:43
manage.py + wsgi.py
#!/usr/bin/env python
import os
import site
import sys
sys.dont_write_bytecode = True # don't write .pyc files
sys.argv[0] = os.path.abspath(__file__) # show full path in ps and top
sys.path.append(os.path.dirname(__file__))
site.addsitedir('/path/to/virtenv/lib/python2.7/site-packages')
os.environ['DJANGO_SETTINGS_MODULE'] = 'demo.settings'
1:20 PM <collinanderson> i had one really, really crazy idea that i almost posted on the thread back in the day. why no just have a _meta.fields that _is_ an OrderedDict of _all_ (non related object?) fields. it would be name -> field_instance
1:21 PM <collinanderson> that way you don't even need .get_field() (singular). you just say _meta.fields['field_name']
1:21 PM <collinanderson> though you would likely do a lot of iterating over _meta.fields.values()
1:22 PM <collinanderson> that way it would preserve the order
server {
server_name example.com;
root /path/to/php;
location / {
index index.php;
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php5-fpm.sock;
@collinanderson
collinanderson / adminsearch.py
Last active August 29, 2015 14:11
admin search
qs = Model.objects.all()
for kw in q.split():
q = models.Q()
for f in fields:
q |= Q('%s__iexact' % f.name: kw)
qs = qs.filter(q)
@collinanderson
collinanderson / python3
Last active August 29, 2015 14:11
Alternative Packages with Python 3 support.
Most of these packages are forks of the original.
MySQL-python -> mysqlclient
suds -> suds-jurko
django-registration -> django-registration-redux
fabric -> no support yet?
gevent -> no support yet?
akismet -> pykismet3
django-storages -> django-storages-redux
xlwt -> xlwt-future
@collinanderson
collinanderson / user_hack.py
Last active August 29, 2015 14:13
username length hack
AbstractUser._meta.get_field('username').max_length = 75 # HACK
for v in AbstractUser._meta.get_field('username').validators:
if getattr(v, 'limit_value', '') == 30:
v.limit_value = 75
class User(AbstractUser):
class Meta:
db_table = 'auth_user'
Collins-MBP:tests collin$ PYTHONPATH=.. python3 ./runtests.py --failfast migrations.test_commands
Testing against Django installed in '/Users/collin/django1.8/django'
Creating test database for alias 'default'...
Creating test database for alias 'other'...
.....................F
======================================================================
FAIL: test_makemigrations_with_custom_name (migrations.test_commands.MakeMigrationsTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/collin/django1.8/tests/migrations/test_commands.py", line 691, in test_makemigrations_with_custom_name
Python 3.4.2 (v3.4.2:ab2c023a9432, Oct 5 2014, 20:42:22)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
sys.path[0] is '/Users/collin/django1.8/tests'
os.listdir('/Users/collin/django1.8/tests/migrations/migrations_22') is ['0001_my_initial_migration.py', '__init__.py']
self.migration_pkg is 'migrations.migrations_22'
Traceback (most recent call last):
import importlib
import os
import shutil
testmod = os.path.join(os.path.dirname(__file__), 'testmod')
os.mkdir(testmod)
with open(os.path.join(testmod, '__init__.py'), 'w') as f:
f.write('pass')
mod1 = os.path.join(testmod, 'mod1')