This file contains 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
##### yabl/settings.py | |
ROOT_URLCONF = 'yabl.urls' | |
TEMPLATE_DIRS = ( | |
"/Users/jacob/training/yabl/templates", | |
) | |
##### yabl/urls.py |
This file contains 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
###### yabl/urls.py | |
from django.conf.urls.defaults import * | |
# Uncomment the next two lines to enable the admin: | |
from django.contrib import admin | |
admin.autodiscover() | |
urlpatterns = patterns('', | |
(r'^authors/', include('yabl.authors.urls')), |
This file contains 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
##### yabl/entries/models.py | |
import datetime | |
from django.db import models | |
from yabl.authors.models import Author | |
class EntryManager(models.Manager): | |
def future(self): | |
return self.filter(pub_date__gt=datetime.datetime.now()) | |
This file contains 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
##### yabl/entries/templatetags/entry_tags.py | |
from django import template | |
from yabl.entries.models import Entry | |
register = template.Library() | |
@register.inclusion_tag('entries/latest_snippet.html') | |
def latest_entries(num): | |
return { |
This file contains 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
##### yabl/urls.py | |
from django.conf.urls.defaults import * | |
# Uncomment the next two lines to enable the admin: | |
from django.contrib import admin | |
admin.autodiscover() | |
urlpatterns = patterns('', | |
(r'^authors/', include('yabl.authors.urls')), |
This file contains 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 operator | |
from django.db.models import Q | |
def search(model_or_qs, search_fields, search_string): | |
""" | |
Perform a quick and dirty model "search", similar to how the admin's | |
`search_fields` works (see http://tinyurl.com/66xz2n):: | |
>>> search(Entry, ['summary', 'body'], 'content') | |
[...] |
This file contains 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
### Install some packages. Ignore the errors. | |
aptitude install binutils libgdal1-1.5.0 postgresql-8.3-postgis postgresql-server-dev-8.3 python-psycopg2 python-setuptools | |
### Make connecting to postgres easier | |
echo "local all all trust" > /etc/postgresql/8.3/main/pg_hba.conf | |
invoke-rc.d postgresql-8.3 reload | |
### Become the Postgres user to create a spatial template database: |
This file contains 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
# Poll interval of 2 minutes | |
set daemon 120 | |
set logfile /var/log/monit.log | |
set mail-format { | |
from: [email protected] | |
subject: [monit] $SERVICE - $EVENT | |
} | |
# Global notify list |
This file contains 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 tabletest(table): | |
def decorator(func): | |
def _inner(): | |
for args in table: | |
yield tuple([func] + list(args)) | |
_inner.__name__ = 'test_'+func.__name__ | |
return _inner | |
return decorator | |
table = [(1, 2), (3, 4)] |
This file contains 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.auth.models import User | |
>>> import datetime | |
>>> User.objects.filter(date_joined__lte=datetime.datetime.now) | |
[<User: jacob>] |