27
Announcing djangoembed, rich media consuming and providing with Django
2 Comments | Tags: django oembed
I'm pleased to announce the release of djangoembed, a django app for consuming and providing rich media.
What is OEmbed?
OEmbed is a format for allowing a rich representation of a url. If you've used Facebook you've probably seen this feature before -- linking a YouTube video will embed an actual video player in the news feed, automatically. The player is represented by some HTML, plus there may be additional metadata like the author, a link to their channel, the title of the video, or even a thumbnail.
03
Using virtualenv, pip and django-site-gen to quickly start new Django projects
4 Comments | Tags: django pip virtualenv
Last week, after several false starts, I moved all the sites I maintain into virtualenvs, with their own pip requirements files. My reasons for doing so are pretty simple:
- Experimenting with new/different versions of software is a pain in the ass without isolation
- A pip requirements file for each site is a very nice thing to behold
- I symlink 3rd party apps into a custom directory on my PYTHONPATH and it was getting huge
- Profit
There are quite a few great tutorials out there for getting started with these tools. I will only discuss how I got over some of the hurdles involved in using these tools, as well as a tool for automating the creation of "skeleton" django sites.
Apache Solr is a fast, open-source search solution. People are doing some very cool things with Solr. I personally have only begun to scratch the surface of what is possible with Solr, but have seen amazing returns with a relatively small investment (thanks entirely to Daniel Lindsley's excellent search framework, django-haystack). There are instructions for getting up and running with Solr + Jetty -- the purpose of this blog entry is to walk through setting up multi-core Solr with Apache Tomcat.
To get the benefit of Django 1.2's new CSRF protection, all POST forms will need a special token. Here is a quick command that runs through templates adding the token:
find . -type f -name "*.html" -exec sed -i \
's|\(<form[^>]*method="post"[^>]*>\)\({% csrf_token %}\)\?|\1{% csrf_token %}|g' \
{} \;
This post will be very brief, but I want to show a little trick I'm using on my different servers so I can tell them apart at a glance. I use a custom bash prompt which gives the hostname of each server a different color:
[charles@alpha ~] $[charles@beta ~] $
22
Generating aggregate data across generic relations
7 Comments | Tags: django aggregation gfk
Aggregation support was added to django's ORM in version 1.1, allowing you to generate Sums, Counts, and more without having to write any SQL. According to the docs aggregation is not supported for generic relations. This entry describes how to work around this using the .extra() method.
Most django sites I create have quite a lot in common. Beyond the handful of files generated by django-admin startproject, my projects all have a database, wsgi file, apache and nginx confs, static media and templates. All these building blocks of a site vary very little from project-to-project. django-site-gen allows you to automate the creation of the stuff that doesn't vary.
cue is a simple queue abstraction along the lines of the command pattern, and provides django apps with a way to decouple the creation of a request from its execution.
A collection of a few snippets I've made use of recently.
Topeka, the state capitol of Kansas, is about 30 minutes down the road from Lawrence, KS where I work. In a recent publicity stunt, they've been talking about renaming the capitol to 'Google' in order to bring Google fiber-optics to the city. Here's Google's response.
I recently posted on writing an app that allows you to create flexible and descriptive relationships between Django's built-in auth.users.
django-relationships is the result.
22
Hacking on relationships between django's auth.User
3 Comments | Tags: django relationships
Doing a quick search on the Django Developers group for 'user model' yields a bunch of requests for extensible user models. There's also an epic ticket, #3011, opened 3 years ago on this topic. I don't really feel one way or the other about it -- this is just a roundabout way of excusing the hack you're about to see.
Reusable code is one of the most talked-about silver bullets in our toolkit. Django has a huge ecosystem of reusable apps, but not nearly so many reusable fields. Apps and fields generally solve different problems, though, and while an app can be retemplated or modified to fit your use case, a field is often times so specialized or exact in its purpose that either you need it or you don't. In this entry I'll discuss a great use-case for a field we had at work building out live March Madness coverage, and a popular field that is also an app.
Writing simple templatetags is only marginally less painful that writing complex tags. django-simpletags aims at making writing simple tags simple.
Object-oriented programming stresses the idea of code reuse, through concepts like inheritance and polymorphism. View programming in django can sometimes get a boost from class-based design.
How to implement self-referencing many-to-many relationships in Django. Example use cases are modeling asymmetrical following (a-la twitter) or symmetrical friendship (a-la facebook).
Django uses several types of registration patterns for some of its most notable features. This entry looks at the way django implements its different types of registries.
django-github is a Django app for integration with GitHub.
Amazing CG!
OEmbed is a pretty neat idea. A site that serves up content decides that it wants to allow users elsewhere to integrate with their site. What's missing is the discovery step.
My site is now powered by Django! I added some features, trimmed some bloat, and hopefully have a leaner, cleaner site.
Github, the premier social coding site, has a new REST API. I've written a small API client in Python to handle retrieving data on repos, commits, and gists.
When I interviewed for my first web development job one of the first questions was "Are you comfortable using linux?" I thought "Why would I need to know how to use that?" -- newb mistake.
17
Hooking into django's login and logout - two approaches
2 Comments | Tags: authentication django
Hooking into django's authentication system using two approaches: a custom authentication_backend and signals.
14
How-to work around your home server's dynamic IP
0 Comments | Tags: ddclient dyndns home-server
DynDNS provides an awesome free service - a hostname that points at your home server. Most of us have a dynamic IP provided by our internet service provider, and running a home server can be a pain whenever your IP address should happen to change. DynDNS allows you to create a hostname that will point to your dynamic IP.
13
Remove profanity (or any words) with a regular expression
0 Comments | Tags: python regular-expressions snippets
If you have comments on your site, or allow use generated content to appear in prominent places, it's a good idea to remove profanity. This regular expression matches case-insensitive for any bad words, and strips the entire word to the leading and trailing whitespace.
One of the biggest barriers to entry on the web might be the "register -> check email -> login -> remember account info" paradigm. At work I recently developed a proof-of-concept app that allows a single login to work with multiple sites. How? iframe
04
Merges from the Crypt - or, how I learned to stop worrying and love SQL
0 Comments | Tags: django databases postgresql
Outlining how I merged two databases for django-powered sites using a combination of SQL, django-multidb, and pg_dump.
03
Describing Relationships: Django's ManyToMany Through
0 Comments | Tags: django python databases many-to-many
How to implement many-to-many relationships with extra fields, or, Many-to-Many Through. Covers django models and admin.
I am just beginning the process of merging two fairly large databases. This merge is complicated by the fact that there are a number of shared tables between the two databases. I've written a short python script to generate lists of tables for each dat
Poker hand evaluator written in Python.
05
BBCode and Syntax Highlighting with Django
0 Comments | Tags: django bbcode regular-expressions syntax-highlighting
Lightweight BBCode parser and syntax highlighting for Django. Code blocks set off with the tag will be automatically highlighted.
My first github repo -- a collection of PHP Snippets.
I've been lucky enough to have spent this week attending Jacob Kaplan-Moss's Django Training. One of the topics we covered a bit later in the week was middleware, which in the Django usage is somewhat of a misnomer. Middleware in Django allows you to pre-process requests, post-process responses, and handle exceptions.
Project Euler is a web site devoted to mathematical problems solved through the use of computer software.
Use Django to calculate most popular tags, or any query that makes use of an aggregation function.
I use Apache's mod_rewrite extensively on my site to generate clean URLs. It is basically matches a regex to a url (similar to Django's URLConf). This snippet will automatically try adding a backslash to any URL that initially generates a 404.
Query WHOIS using PHP.
Yesterday, while trying to set up a public-facing form for a recipes app, I ran into the issue of combining Django's ModelForm (for the Recipe model) with an inline for the foreign key Ingredients. One of my astute coworkers (there are many of them) poi
This post describes how to get Live Android 0.2 up and running on Ubuntu using VirtualBox. I've got an Asus X83V notebook running Ubuntu 8.10 64-bit. Step-by-step howto with some screenshots.
PHP function to decode keywords used by search engines. Determine what search keywords drive traffic to your site.
03
BBCode, Syntax Highlighting and more
0 Comments | Tags: php source-code blog bbcode regular-expressions
Add BBCode support and Syntax highlighting using PHP. To make the blog even easier to use, I thought I'd get away from using HTML in my entries altogether. I also wanted a way to easily paste code and have it highlighted. Works on nested tags!
Count how many lines of code are in a project using this PHP script. Searches directories recursively.
01
Regular Expression Replace in All Files and Subdirs
0 Comments | Tags: php source-code regular-expressions
Recursively search and replace in files using this PHP script. Follows subdirectories and uses regular expressions for search and replace. Allows file extensions to be specified.
Learn how to build a blog system using PHP and MySQL. I thought I'd share my experience after rebuilding the site blog system. This entry will cover building a simple blog system like the one found on this site, using code that is also available on thi
Added News section to the site, which acts as a simple PHP RSS aggregator (with really nice URLs). Rewrote the PHP Blog System and published the code online. Added a contact form.
1337 fluxbox desktop, showing conky, root-tail and of course DooM.
The site has been in stasis for about three months, so it's probably time to start developing a new version. After looking at the site for a while, I think it's fair to say that many aspects of this site have been (paradoxically) both over-engineered a
