Posts About Code

Getting RequestContext in Your Templates

May 10, 2008 | code, django | 10 comments

Lately, we’ve been taking over projects from people who began building their first site in Django, but either got in over their head or just found they didn’t have the time to continue. As I review the existing code, the first issue I typically see is using the render_to_response shortcut without including the RequestContext, preventing context processors from being used in the templates. The standard symptom is when people can’t access MEDIA_URL in their templates.

Here are a few ways to add RequestContext to your templates.

Option #1: Adding RequestContext to render_to_response

The Django documentation recommends passing RequestContext as an argument to render_to_response like this:

from django.shortcuts import render_to_response
from django.template import RequestContext

def my_view(request):
    # View code here...
    return render_to_response('my_template.html',
                              my_data_dictionary,
                              context_instance=RequestContext(request))

This works, but as you can see, it adds a fair amount of repetitive code to your views ...

Full post →

Google App Engine First Impressions

April 8, 2008 | code, django | 2 comments

For those of you that have been hiding under a rock for the last 12 hours, App Engine is Google’s answer to Amazon Web Services. While it is less flexible in some senses (you don’t have a complete OS at your disposal), it does provide tighter integration for web applications and even includes a (somewhat crippled) version of Django out of the box.

I’m pretty excited about this mainly because I’m not a big fan of server administration, so I took a couple hours this morning to test it out. Here are some quick notes:

The Good

The ...

Full post →

Reusable Django Apps and Forking

April 4, 2008 | code, django | 15 comments

One of the things that drew me towards Django was the idea of being able to create reusable applications that would sit on my PYTHONPATH instead of copied across multiple sites. Coming from WordPress, the constant security updates that required me to revisit old projects began to drive me mad.

Trouble in Paradise

With some real world Django experience under my belt, I find myself re-using apps all the time, but not how I originally expected. A fair amount of my client work comes from building content management systems, so I started out building a generic app like flatpages but more extendable and a blogging app. I dropped them in my PYTHONPATH and started adding them to INSTALLED_APPS on my projects.

Over time, they evolved and improved, but they started to handcuff me. I started thinking things like, “This would be a great feature for Project X, but it would ...

Full post →

Serving Django via CherryPy

March 25, 2008 | code, django | 10 comments

Download django-cpserver

Background

A few months ago, I got sick of trying to deploy Django sites on my cPanel server and got a VPS at Slicehost. Thanks to SuperJared, setting up Apache/mod_python behind an Nginx frontend was a snap.

I started deploying and migrating sites to the new server and kept an eye on my server resources via Munin. I had about 10 sites running on a 1GB Slice, but the Apache processes were hogging all the RAM. Restarting Apache would bring memory usage down to around 500MB, but within a couple of hours, it would be using all my available RAM, with individual proceesses using as much as 120MB.

I started asking questions and trying different options including mod_wsgi, verifying projects weren’t in debug mode, etc. Nothing made a difference.

CherryPy to the Rescue

I came across Loic d’Anterroches’ script to run Django via CherryPy and ...

Full post →

Django FormMail Clone

March 13, 2008 | code, django | 4 comments

Here’s a little nugget I just posted to Django Snippets. It emulates the behavior of an old Perl script I used way back when, FormMail.pl.

I often find myself needing to build a form whose contents get emailed to the site owner(s). This class let’s you call form.notify() on any form that is a subclass of it to have the fields ordered and sent in a plain text email to all users that are flagged as staff.

from django import newforms as forms
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.core.mail import send_mail

class FormMail(forms.Form):
    def notify(self):
        """
        Sends an email to all members of the staff with ordered list of fields
        and values for any form that subclasses FormMail
        """
        site_name = Site.objects.get_current().name
        form_name = self.__class__.__name__
        subject = '%s %s Submission ...

Full post →

Better Use of Newforms

March 13, 2008 | code, django | 4 comments

The newforms library is a huge time-saver, but when I first started using it, I still found myself writing tedious repetitve code to get it to function how I wanted. While I could get away with it on smaller sites, I recently built a site with some big forms on it and decided to improve my process.

HTML Rendering

First off, {{ form }} or {{ form.as_p }}, rarely cut it in real world apps. We need to be able to customize our forms to improve the layout or add extra information. I started using inclusion tags to render the form fields and labels. Here is my trivial inclusion tag:

@register.inclusion_tag('_display_field.html')
def display_field(field, alt_label=''):
    """
    Print HTML for a newform field. 
    Optionally, a label can be supplied that overrides the default label generated for the form.
    
    Example:
    {% display_field form.my_field "My New Label" %}
    """

    if alt_label:
        field.label = alt_label
    return { 'field ...

Full post →

Basecamp SVN Integration

May 4, 2007 | code, subversion | 3 comments

Basecamp/SVN As promised, here is the follow-up to the SVN for Web Developers post, Basecamp integration.

Why?

Transparency is very important to my business. The #1 complaint I hear about web developers is that they rarely meet deadlines and the client has no idea what is happening with the work until one day it magically appears. To combat that, I use Basecamp to lay out milestones for all my projects. I’ve found that even if a project takes longer than a client would like, as long as they can count on a date that it will be delivered, they’re happy.

Milestones are usually pretty spread out and don’t give clients a good idea of what I’m doing day-to-day to meet them. Writing each Subversion commit to Basecamp gives my clients quick access to the current status of their project.

How?

Luckily, all the hard work is done ...

Full post →

WordPress Plain Text Paste Plugin Version 0.3

January 25, 2007 | code, wordpress | 13 comments

Word!Now compatible with WP 2.1!

Get it while it’s hot:

This plugin adds buttons to the WordPress rich text editor (TinyMCE) for pasting in clipboard content as plain text. Don’t trash your layout by pasting in text from Microsoft Word anymore.

Thanks to the TinyMCE paste plugin now being a part of the WordPress distribution, the plugin is now just one file. Extract nds-paste.php and upload it to your wp-content/plugins folder.
If you have a previous version of the plugin installed, delete the nds-paste folder from your plugins directory.

This plugin is only compatible with WordPress versions 2.1 and newer. Here is the 2.0x compatible version.

Full post →

WordPress Plain Text Paste Plugin

August 31, 2006 | code, wordpress | 49 comments

This plugin is currently incompatible with WP 2.1. I hope to update it shortly. Check back here for updates. Version 0.3 is compatible with WordPress 2.1

This plugin adds buttons to the WordPress rich text editor (TinyMCE) for pasting in clipboard content as plain text.

plain text paste screenshotThis solves the problem of users needing to paste Microsoft Word documents, web pages, or any other rich text content into a plain text editor such as notepad to strip out the HTML nasties that have a tendency to ruin a blog's layout. By using TinyMCE's "paste plugin":http://tinymce.moxiecode.com/tinymce/docs/plugin_paste.html, the plugin is smart enough to maintain some basic formatting.

Go ahead and take it for a spin. Extract nds-paste folder from the archive and copy it to wp-content/plugins.
nds-paste-0.2.zip
nds-paste-0.2.tar.gz

Developers note: You should be able to ...

Full post →

eCheck.net Module for ZenCart

January 10, 2006 | code | No comments yet.

This is an add-on payment module for Zen Cart that will allow you to accept electronic checks via Authorize.net’s eCheck.net service. It was built using the existing Authorize.net (AIM) module as a template.

This module is released under GPL and is provided on a “works for us” basis. We accept no responsibility for any issues that may arise from using or installing this module.

Zen Cart eCheck.net Payment Module

Full post →

Our Products

Premier Real Estate Websites
Our simple and easy real estate CMS. Now open for full developer access.
Trailmapping
Still in development, Trailmapping is a GPS enabled trail guide and trip logger.

Categories

Archives

Elsewhere

What I’ve been up to online

  • @37signals I'm seeing a lot of this in Basecamp right now http://skitch.com/t/ejx
    3 days, 16 hours ago #
  • I'm drowning in contracts
    3 days, 20 hours ago #
  • django-reversion - Google Code
    Need to look into this. Version control throughout an entire Django project.
    3 days, 20 hours ago #
  • InfiniteRed - Fun and profit by modifying your Bash startup files...
    Been looking for something like this for a while. Pretty colors in Terminal.app and lots of nice little hacks for .bashrc
    5 days, 9 hours ago #
  • Bluetooth between Apple wireless kbd and Macbook Air is awful. Regular disconnects only solved by reboots. http://skitch.com/t/eg1
    5 days, 21 hours ago #
  • Connection Lost
     
    6 days, 4 hours ago #
  • virtualenv with OSX -
    Little trick to get virtualenv to find your site-packages in OS X. The issue is fixed in trunk, but not in the current PyPI release.
    6 days, 20 hours ago #
  • lazyweb screencast/blog request: getting the most out of Terminal.app (keyboard shortcuts, color, vim styling, etc.) @ericholscher? @jlilly?
    6 days, 21 hours ago #
  • Custom Django Views for Happier Ajax @ Irrational Exuberance
    Nice writeup on using creating AJAX views w/ Django & jQuery
    1 week, 3 days ago #
  • OpenSolaris nailed to a wall with a $100 offer | Dennis Clarke with vi and coffee
    Good primer on getting a stock OpenSolaris install updated and prepped for server duty.
    1 week, 5 days ago #
  • @bkroeze tried to get in touch with you via your web form. Drop me a line, pete@lincolnloop.com
    1 week, 6 days ago #
  • Double billed by Hotel Avante during #djangocon. Looking forward to wasting an hour of my day to get this fixed.
    1 week, 6 days ago #
  • Hey lazyweb, any recommendations on an quality SEO/Online Marketing specialist I can recommend to clients in the States?
    2 weeks ago #
  • django-rcsfield - Google Code
    Store database changes in bazaar or subversion. Very cool, I've wanted something like this for an app I've had in my head for a while.
    2 weeks, 3 days ago #
  • @jtauber http://tinyurl.com/5uvvyf
    2 weeks, 6 days ago #

Interested in working with us?
Fill out the form below or contact us at:

PO Box 774441
Steamboat Springs, CO
80477

970.879.8810
info@lincolnloop.com