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
# A simple way to break out Apps within the Django settings.py | |
# file in a logical way. Third party and Local Apps will vary | |
# based on the project. | |
DEFAULT_APPS = ( | |
'django.contrib.auth', | |
'django.contrib.contenttypes', | |
'django.contrib.sessions', | |
'django.contrib.sites', | |
'django.contrib.messages', |
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.shortcuts import render_to_response | |
from django.template import RequestContext | |
def handler404(request): | |
response = render_to_response('404.html', {}, | |
context_instance=RequestContext(request)) | |
response.status_code = 404 | |
return response |
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 six | |
from django.conf import settings | |
from django.contrib.auth import REDIRECT_FIELD_NAME | |
from django.contrib.auth.views import redirect_to_login | |
from django.core.exceptions import ImproperlyConfigured, PermissionDenied | |
from django.http import HttpResponseRedirect | |
from django.utils.encoding import force_text | |
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
class PluginMount(type): | |
""" | |
A Meta Class plugin mount location for a list of plugin classes. | |
By creating this, on all subclasses of PluginMount, python will | |
instantiate a plugin attribute list and maintain it for the Class | |
using this Meta Class. | |
""" | |
def __init__(cls, name, bases, attrs): | |
if not hasattr(cls, 'plugins'): | |
cls.plugins = [] |
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.db import models | |
from django.core.exceptions import ValidationError | |
def validate_length(value): | |
if len(value) != 5: | |
raise ValidationError('%s is not five digits.' % value) | |
class MyModel(models.Model): |
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
I currently use Postgres and a Mac for my Django Dev environment. However, when I first started I was using a Windows machine with MySQL. When I looked through my notes just now, it was pretty easy to set up. (I didn't use xampp however). What I installed was: | |
1. MySQL workbench: http://dev.mysql.com/downloads/workbench/ | |
2. MySQL-python connector - I used pip install for this. So if you have "pip" then it's just: | |
pip install mysql-python | |
3. And, this is what my database settings looked like in my settings.py: | |
DATABASES = { |
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
# ---------------------------- None View Helper Functions ------------------------------------ | |
# Place to save image upload file | |
def handle_uploaded_file(f): | |
with open(content_file_name(f), 'wb+') as destination: | |
for chunk in f.chunks(): | |
destination.write(chunk) | |
# Attempt Imagefield | |
def content_file_name(instance, filename): |
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 requests | |
import xmltodict | |
def get_weather(url="http://weather.yahooapis.com/forecastrss?w=12795483&u=f"): | |
""" | |
Get the current weather for Las Vegas using Yahoo!'s Weather API | |
""" | |
try: | |
r = requests.get(url) | |
# parse bytes into a text string |
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
#pip | |
pip install redis | |
pip install celery[redis] | |
pip install django-celery | |
# redis server | |
# download here | |
http://download.redis.io/redis-stable.tar.gz | |
# follow install instructions here | |
http://redis.io/topics/quickstart |
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
''' | |
To convert zipcodes | |
------------------- | |
From the output on: http://www.freemaptools.com/find-zip-codes-inside-radius.htm | |
to a list of strings to use as a filter in SQL. | |
Change data initially in this format: | |
1111,2222,3333 | |
To this format: |
OlderNewer