A Django site.
June 25, 2009

Kevin Kubasik
nonic
For Once I Oneder
» Django Windmill Tests – GSOC Progress Update

I feel that a status update is long overdue, but as the corpus of Windmill tests grows, so does the time it takes to run a complete instance of the regression suite. However, I do have some fun progress to report as well as a few questions/problems that are showing themselves now that all the fluff is over. First, let’s talk about the fun stuff!

I do have 3 of my major improvements/fixes/restructures to django.test somewhat complete. At the moment they are lacking most in documentation, a problem I intended to rectify later this week.

  1. Windmill Tests: Windmill test runners are nearly complete, threaded development server for AJAX widget testing complete.
  2. Code Coverage: Coverage.py support for runtests.py and management command. Extensible system is easily pluggable with other coverage systems.
  3. Test-Only Models: This is still a topic of discussion, but adding the property ‘test_models’ to a TestSuite will load and wipe the models. Has tests and limited docs.

My major TODO’s still outstanding:

  • Documentation!
  • Twill Runner Support (Utilizing the Windmill Threaded Server)
  • Windmill Admin Regression Tests (Healthy set of tests written, need to document and finish more)
  • Skip tests that are known to fail
  • Test new features/API’s

That’s it for now, more updates are available on the django-dev list!

May 27, 2009

Kevin Kubasik
nonic
For Once I Oneder
» Google Summer of Code 2009 - Django Testing - Coding Day 1

Among all the excitement of the past few weeks, the start of GSOC appears to have snuck up on me! Started work today on the coverage runner. My progress is easily followed on my GitHub Django fork (until we get real SVN branches). Can’t wait to start posting some real results!

April 28, 2009

Adam Olsen
synic
Vimtips Latest Articles
» Django: Using ModelAdmin to default to currently logged in user

Yeah, you may have noticed that I've been working on the blog lately. Poor openclue.org got flooded with already posted RSS feeds again. This happens all to often. Sorry guys.

Anyway, this blog system has the ability to have more than one person post articles. In the past, sjohannes used to post here too. The model for articles looks something like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
from django.contrib.auth.models import User
from django.db import models
import datetime

class Article(models.Model):
     title = models.CharField(max_length=250)
     slug = models.SlugField()
     article = models.TextField()
     pub_date = models.DateTimeField(
          default=datetime.datetime.now)
     publisher = models.ForeignKey(User)

As you can see, there's a ForeignKey to django.contrib.auth.models.User. The question here is: how do I make the "publisher" field default to the currently logged in user? It was harder than I thought it should be, but it can be done using hooks in the ModelAdmin for the Article model. Take a look:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
class ArticleAdmin(admin.ModelAdmin):
    list_display = ('pub_date', 'publisher', 'title', 'slug')
    search_fields = ('title', 'article')
    prepopulated_fields = {
        'slug': ('title',),
    }

    def get_form(self, req, obj=None, **kwargs):
        # save the currently logged in user for later
        self.current_user = req.user
        return super(ArticleAdmin, self).get_form(req, obj, **kwargs)

    def formfield_for_dbfield(self, field, **kwargs):
        from django import forms
        from django.contrib.auth import models
        if field.name == 'publisher':
            queryset = models.User.objects.all()
            return forms.ModelChoiceField(
                queryset=queryset, initial=self.current_user.id)
        return super(ArticleAdmin, self).formfield_for_dbfield(field, **kwargs)

admin.site.register(models.Article, ArticleAdmin)

As you can see, I overload "get_form" for one purpose: It takes the HttpRequest as the first argument, which we can use to save the currently logged in user. The other method that's overloaded, "formfield_for_dbfield" is called for every field in the model, and is made for the purpose of specifying your own custom form fields (and widgets). In this case, we use the same field type that the admin would have used - "ModelChoiceField" and give it an initial, which is the id of the currently logged in user.

There you have it. It's a little hacky, but it's the only way I could find to do it. If you've seen a cleaner way, let me know!"

April 21, 2009

Kevin Kubasik
nonic
For Once I Oneder
» Google Summer of Code 2009: Django Testing Updates!

So my Google Summer of Code: 2009 project proposal was accepted! I will be working on a 2 phase project revolving around Django’s testing framework, and regression suite. Most notebly, I plan to:

  • Implement Windmill test coverage for Django’s Infamous contrib.admin
  • Provide several missing features/conveniences to the Django testing tools

While it may not be the most glamorous project, I’m excited for it! When paired with my epic mentors, (the ever-infamous Eric Holscher and notorious George Song) it looks to be a solid summer. You can expect me to post weekly status updates here, as well as anything else relevant to the project. As my ‘get to know Django and make sure I can conform with coding standards etc.’ ticket, I’m planning to add an assertion which checks for dead links after template rendering. Or, as its better known, Django Ticket #5418.

I want to also give a quick thanks to Jacob Kaplan-Moss, Eric Holscher, Jannis Leidel and all the other PyCon 2009 Sprinters who helped me create the proposal.

March 12, 2009

Kevin Kubasik
nonic
For Once I Oneder
» Finally! A Django IDE with Real Code Completion and Template Support

Now it seems like forever ago, but I have been on the hunt for a good Django IDE for a very long time. I have tried PyDev, Aptana, Komodo, TextMate, Vim, Emacs, Wing IDE and every variation in between, but was never satisfied with the featurset. I wanted complete python language support and completion, complete support for Django Templates, total HTML support, as well as complete Javascript (specifically jQuery) support. Most editors made the mistake of having support for some of those individually, but I can’t get javascript support inside of a Django Template etc.

The magical and awesome app that represents the first real attempt at a complete Django development environment? Netbeans!

I know it sounds crazy, but progress is being made, and while its a boatload of effort to get it built, and even then, not much of the promised featureset actually works. But those are just details, examination of the code available at:

http://code.google.com/p/netbeans-django/

shows some real work being done towards a Django project type. Moreover, a recent blog post from someone at Sun alludes to this support being available as soon as Netbeans 7.0.

Perhaps this is just another let down waiting to happen, but the existing Python code support is fantastic, and significant strides appear to already have been made towards the goal of total Django integration. If you want to try out the existing language support, just grab the Netbeans 7M2 build and install the Python plugin!

January 5, 2009

Jordan Gunderson
jordy
Jordy Blog
» Got Contract Work?

Gabe and I want to be sure that our start up company, Izeni, has a cash runway that’s long enough to ensure that we can have a proper lift off. To that end we’ve been doing some consulting and contract work (mostly low-hanging fruit) to slow our burn rate, and it’s worked fairly well because we’re in bootstrapping mode and our expenses are relativity low. So, although we’ve never really sought contract work, we do like it; and I thought I’d do a quick post officially soliciting it.

So without further ado, Izeni will be accepting all kinds of technical consulting and contract work. Our specialities are Python coding; website development (particularly using the Django framework); Linux systems administration (Apache, *SQL, Postfix, Mailman, IPtables, Samba, Bash, etc.); and VoIP-based telephony (Asterisk and Freeswitch).

We can also do general computer and network support, online marketing, and a myriad of other technical and business odds and ends.  :)

Izeni is based out of Utah, but we can also telecommute.

Please let me know if you have any contracting and consulting opportunities or know of any companies looking for web guys, programmers, or other technical contractors. Otherwise, feel free to repost this (pass the word along), or just keep us in mind.

October 12, 2008

Adam Olsen
synic
Vimtips Latest Articles
» Posting articles to Twitter via Django

I noticed that every time Clint Savage makes a blog update, he posts the URL to Twitter twice (yeah, that's you herlo :P). The URLs for each Twitter post are different, so I figured it must be some sort of automated Wordpress script with a bug in it.

So, I decided to write something to do the same for my own blog. Clint's passes the URL through tinyurl to get an address that's not too long for Twitter, but in my blog's case, http://vimtips.org/article_id works just fine.

Here's the code I used to do it:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from vimtips import settings

try:
    import twitter
except ImportError:
    twitter = None

def twitter_post(article_id, title):
    """
        Posts an article update to twitter
    """
    
    if not twitter or not hasattr(settings, 'TWITTER_USER') or \
        not hasattr(settings, 'TWITTER_PASS'):
        return

    try:
        api = twitter.Api(settings.TWITTER_USER, settings.TWITTER_PASS)
        api.PostUpdate(
            "Blog Update: %s (http://vimtips.org/%d)" % (title, article_id)
        )
    except Exception, e:
        if settings.DEBUG:
            raise(e)

class Article(models.Model):
    """
        The model representing each news article on the blog
    """
    
    # ... model fields here ...

    def save(self, *args):
        """
            Saves the article.  If this is a new article, it also posts to
            twitter
        """
        post = not self.id

        models.Model.save(self, *args)

        if post:
            twitter_post(self.id, self.title)

This requires that you install the python-twitter module from http://code.google.com/p/python-twitter/.

September 6, 2008

Adam Olsen
synic
Vimtips Latest Articles
» Django 1.0!!!

Django 1.0 is finally here!!!

I figured I'd just announce my excitement. So far, I've migrated two websites to it (one being this blog, the other being a much larger app for work), and haven't really had any problems. Following the Backwards Incompatable Changes on their Wiki made it fairly painless.

Congratulations to the Django Project!

P.S. I know I'm going to get some guff for this, but it's a breath of fresh air to be working in Python/Django at work instead of our hacked together CGI/Perl system.

September 9, 2008

Clint Savage
herlo
» Over the last few days

Quite a bit has transpired this weekend.  Thought I had better get caught up on it before I forget.

Missing Teeth

My Son Shaun lost his fourth tooth this past week.  He was so excited about it, he called me as soon as it happened.  Unfortunately, I wasn’t there to experience it, but I’ve been assigned to be in LA three times in the next 3 months, plus one or two trips back to Utah should help.  I’m excited to head out and see his more holey head :)  I’m expecting some pictures to appear soon.

Djangocon 2008

On Friday, I left with a friend of mine, Seth House to Djangocon 2008, the first ever.  While I was happy to go, I wasn’t particularly excited that I would miss an entire day due to a clerical messup.  I learned quite a bit about Django and the community, I’m grateful I could go.

Django is a great framework and I’m excited to learn more about it this weekend.  I’m also grateful Google let me come back onto their campus (without incident this time, I might add), they are such great hosts.  I also got to meet Leslie Hawthorne and introduce myself, she seems pretty awesome even though I hollered at her while she was on the phone (oops, sorry Leslie).

First UTOSC Videos Released

Another great bit of news from UTOSC 2008.  The first evening keynote videos of Mac Newbold and Paul Frields have been released.  I’m excited and grateful to KnowledgeBlue and OpenSourceTV for their help with this project.  Things are rolling great on the video, thanks to Doran Barton and Nick Bauman at KnowledgeBlue for doing the video.

UTOSC Pictures keep piling up

Make sure to take a moment and have a look at the UTOS flickr group.  There’s tons of pictures there and maybe you are in one.  I’ve been tagging like crazy and hope to have them all done later this week.  I’d love to see more tags than what I’ve

A Goodbye

Also, today I found out one interesting thing, my friend Christer, who I referred to come work at Guru Labs, has left for another position.  I’m glad he’s happy and wish him luck.  Sounds like a great change for him and his family.

September 6, 2008

Adam Olsen
synic
Vimtips Latest Articles
» Django 1.0!!!

Django 1.0 is finally here!!!

I figured I'd just announce my excitement. So far, I've migrated two websites to it (one being this blog, the other being a much larger app for work), and haven't really had any problems. Following the Backwards Incompatable Changes on their Wiki made it fairly painless.

Congratulations to the Django Project!

P.S. I know I'm going to get some guff for this, but it's a breath of fresh air to be working in Python/Django at work instead of our hacked together CGI/Perl system.

September 5, 2008

Scott Paul Robertson
spr
Spr: The Ramblings
» Blog Update | Django 1.0

The blog code has been updated to be compliant with the recent release of Django 1.0. And a small patch from Jeff.

June 13, 2008

Scott Paul Robertson
spr
Spr: The Ramblings
» Drafts Do Not Go Into The Feed

Remember kids, do not feed your feed drafts. It is unprofessional.

Blog updated to filter out drafts in the RSS feed.

May 21, 2008

Scott Paul Robertson
spr
Spr: The Ramblings
» Yet More Blog Upgrades

Well I've added a few more improvements to the blog software.

  1. Drafts can now be viewed on a login restricted url.
  2. The README file now has details of template tags, an example blog.html, and the CSS used.
  3. Improved doc strings so you can read template tag info in the admin.

There are other things I'd like to see, but this works well for now.

May 20, 2008

Scott Paul Robertson
spr
Spr: The Ramblings
» Updates to the Blog Code

I've made some updates to the software that runs this blog. A few changes that make for good reasons to update:

  1. The subtitle block no long adds the <h2> tag. You'll need to adjust your blog.html to put tags around the subtitle block.
  2. Fixed the way it references your settings. I'm now doing it correctly by writing from django.conf import settings.
  3. Some minor other cleanup.

Share and Enjoy.

May 17, 2008

Seth House
nonic
» Pimping out your .pythonrc.py

I don’t wanna be hatin’ on IPython, but I don’t use it. I often favor fairly extreme minimalism in computing. Why install something if you can accomplish the same (or good enough) with what you have available? IPython has quite a lot of features and syntactic-sugar, but it is overkill for my needs. Instead I’ve been slowly crafting my ~/.pythonrc.py [...]

January 28, 2007

Seth House
nonic
» Learning Django with IPython

IPython is invaluable for learning Django if you don't know much about Python or anything about object-oriented prgramming.

March 6, 2008

Matt Harrison
no nic
Matt Harrison's blog
» Ask Matt: Java, PHP or Python for beginning web development?

I recently received the email below. At the risk of starting a flame war, I'm posting my response here. Hi Matthew, Sorry to bug you, but I was reading your blog and was hoping you could help me with some advice. I am new to programming and can't q

March 5, 2008

Kevin Kubasik
nonic
For Once I Oneder
» Can Someone Get Us A Real Django IDE?


So the more I work with Django the more I long for a solid development environment to work in. I use Wingware for much of my python development, with its rockin debugger and code completion, its more than I could ask for. Until the curse of the Java class. This quarter I’m taking a Java projects course, most of the class uses Eclipse but a few use Netbeans. My problem is, I got spoiled so fast by the incredible templates support, content suggestions, quick fixes and always dead on code completion. Going back to Wing feels like a halfway-there IDE. I know that pythons interpreted nature makes source completion much more difficult, now I would argue that with an interpreter, you could actually step through the code to some extent. However, I respect that dynamic objects are never gonna be easy to support. My beef is with the lack of support for super-popular frameworks (this goes for everybody!) Ruby on Rails has literally dozens of solid IDEs and a few that are just spectacular (see Aptana, or Netbeans). Why can’t I get even basic highlighting support for my Django templates? Why can’t I get any completion options on Models except my own?

Its just frustrating, Django is still a pleasure to develop in, even with just Gedit and a terminal, but is it really out of the question to consider providing a big pretty environment for those of us that like that?

I did dig up this and this. I guess its a step in the right direction, but its almost embarrassing next to the Rails environments.

February 3, 2008

Doran Barton
fozzmoo
Fozzolog
» Two new interview videos from UTOSC 2007

I've uploaded two more videos to YouTube for OpenSourceTV.tv.

First, we have an interview with Clint Savage of the Utah Open Source Foundation and the main driving force behind last year's first Utah Open Source Conference.

Next, we have an interview with Scott Paul Robertson (AKA "spr") who gave a presentation at UTOSC 2007 on Django and who is also the author of one of my favorite open source utilities: oggify.

I've got at least one more interview to edit and upload and we also have other content coming soon as well.

You can see Clint's interview and Scott's interview and many others by going to my YouTube Open Source TV playlist, or by visiting the UTOSF YouTube group.

February 1, 2008

Clint Savage
herlo
» UTOSF HackNight: Part Deux - Tonight

Well, right on the heels of last weekends uber successful HackNight, it looks like the snow may keep some people from coming up, but we’re still planning on having a mostly ad-hoc HackNight tonight.  The project again will be ConMan.

We’re meeting at my place @6:00 in Murray and we’ll have food and hack for a long, long time!

See you all tonight for an awesome hackfest!

January 26, 2008

Clint Savage
herlo
» UTOSF HackNight - Tonight: New Location: Guru Labs

UPDATE!

A quick update for those who are planning on attending tonight’s UTOSF HackNight. Its been moved to Guru Labs in Bountiful. If you still need a ride, feel free to email me, herlo1@gmail or you can twitter me at http://twitter.com/herlo.

If you still need a ride up, we’ll carpool/caravan up from my place @6:30 (instead of 7pm) in Murray. I’ll be leaving promptly at 6:30, however. If you’ve never been to Guru Labs, here’s a map.

See you all tonight for an awesome hackfest!

Cheers,

Herlo

» UTOSF HackNight - Tonight: Possible Change of Venue

Well, it appears that I am one of the many victims of Qwest and their lurid line noise issues, thus no DSL for me! Because of this, I’m in the process of scrambling for a new location for our UTOSF HackNight this evening. If anyone who’s coming would like to donate their location, or know of some place central to those in Salt Lake County with free wireless and open all night, let me know. I accept emails at herlo1@gmail or you can twitter me at http://twitter.com/herlo.

If nothing pans out, fear not, I do have a possible alternate location for this event, which I should be able to arrange for by the end of the day as a backup plan. As it stands now, everyone should just arrive at my place @6:30 (instead of 7pm) in Murray and we’ll carpool and caravan as desired.

See you all tonight for an awesome hackfest!

Cheers,

Herlo

January 18, 2008

=Utah Open Source=
Utah Open Source
Utah Open Source Blog
» UTOSF Hacking Night

Its coming soon, the Utah Open Source Conference 2008!

and we need some help getting our registration system off the ground!

If you are interested in working on a really cool project, want to learn Django and enjoy some good food, come on over and hack.

The Hackfest will be held at my new home in Murray, Utah! So come and enjoy the new surroundings and hopefully we’ll have the projector and screen up, which means movies and video games. I’m also working on internet access (its Qwest/XMission for now. Soon to be UTOPIA/XMission), but it should be installed by Saturday. If not, we’ll let everyone know an updated location nearby.

Here’s the details:

Date/Time: Saturday, January 26, 2008 / 7pm

Location: Herlo’s house: 5225 Gravenstein Park, Murray, Utah 84123 - Map

Please feel free to ping me on IRC if you have any question.

Cheers,

Clint

January 10, 2008

Kevin Kubasik
nonic
For Once I Oneder
» Scripted Web Frameworks, and why Django Got it Right

So, I've been working on a few small web projects for an assortment of businesses, pretty standard fair stuff, so I've seized the opportunity to finally do something of a personal analysis of the enormous mass of web frameworks out there (Rails, TG, Django etc). Before anyone gets the wrong idea, this is _NOT_ a comparison, its an opinion. I've just been working with Django for the past several days, and I feel like I owe it a little bit of word-of-mouth.

Let me first explain, Django is really a completely different beast than either Rails or TurboGears. In my experiance, it seems that the real goal of those systems is to make sure we have to code as little as often, so massive slews of differently formatted configuration files, naming conventions and templates are really to be expected. Here's the problem, I'm a developer. I _like_ coding. Now, sometimes it is nice to design a SQL schema, and find your objects already waiting for you. Its also nice to have an authentication framework, templates are fine too, as long as its not a whole new language. The problem I started to run into fairly early on was I didn't know the 'Ruby on Rails' way to do it, but knew perfectly well how I might have done it in a chitzy CGI.

Turbo Gears wasn't much better, again, the goals of the project seems to be as little code as possible, but code is a wonderful common denominator, chances are if I'm using a python web framework, I already know python, why do I need a slew of other random file formats and templating systems? While Turbo Gears did offer an interesting GUI API (all AJAX'ed up of course) its still fairly new, and as a result, wasn't really featureful enough for my needs, and I was stuck with it, so I ventured onward.

Now, I had passed over Django initially because some reading left me with the impression that it wasn't nearly as much of a 'Magical Framework' as the other 2. It turnes out, thats what makes it rock. While Django doesn't have a flashy "Build ____ in 10 min screencast', and doesn't try to make decisions for you, its basically a nice pythonic wrapper around all the nasty bits of working with the web. Django only has 1 real config file, and its just python declarations, to handle url mapping, you get regular expressions. I know it doesn't sound glamorus, but after only an hour or so with Django, its abundantly obvious it was designed by real web developers. Theres an incredibly powerful and sleek caching system, a down right dirt easy templating system (its basically python, 20 minutes and you have it down).

I think perhaps the single most defining design decision (and one that does a great job embedding the usefulness of Django) is the lack of 'toolkit' like elements in the API. Instead, JSON and XML serialization are made fast and easy to use. Django doesn't shove a website on you, its really just a set of libraries and tools but with a little more polish and glue. Not to short what Django offers, on the contrary,  I think it brilliant. I know python, so why shouldn't I define my models in SQLObject?

<offtopic> I wanted to apologize for the blog bumps I've been having, I think a post or 2 got reposted to some Planets, I hope it wasn't too irritating! </offtopic>


January 1, 2008

Scott Paul Robertson
spr
Spr: The Ramblings
» My Blog Code

Well, I've cleaned up the Django app that runs this blog. If you look at it, you need to read the README file first. Trust me.

Highlights:

  1. Comments system that uses akismet to filter spam. After-the-fact comment filtering.
  2. RSS feeds on a per-tag basis and one of recent entries.
  3. Uses only the Django admin.
  4. Uses django-svn revision 5994. Probably broken with current versions.
  5. Shamelessly used calendar snippet.
  6. Provided templates that assume all sorts of CSS you probably aren't using! Luckily you only really need to override templates/blog/entry_abbr.html, templates/blog/entry.html, and templates/blog/calendar.html.

Available at hg.scottr.org via Mercurial: hg clone http://hg.scottr.org/blog

November 15, 2007

Adam Olsen
synic
Vimtips Latest Articles
» Django template autoescaping

Vimtips.org is running the SVN version of Django. This morning I ran an svn update, and I ran into my first API change. While looking at my site later on in the day, I noticed that both of my template filters were being HTML escaped, IE, things like < were showing up as &lt;.

My two filters are the pygments highlighting filter (you can see that in action in this article) and the filter that creates the category list at the end of every article (Under this article, it says "Filed Under: Programming, Python, Django").

Looking through the svn changelog, I noticed that they implemented a new feature, called autoescape, which will make every template variable and custom filters autoescape for safety. Using:

1
2
3
{% autoescape off %}
<a href='{{ link.url }}'>{{ link.name }}</a>
{% endautoescape %}

... you can turn off autoescaping. You can also use the Django template filter safe. As for custom filters, to make it so your returned string isn't autoescaped, you have to mark it as safe. Here I'm showing my category list filter with the new safestring.mark_safe() function:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
from django.utils import safestring

@register.filter(name='category_list')
def category_list(categories):
    """
        Shows all categories as a list of links separated by commas
    """
    c = []
    for category in categories:
        c.append("<a href='/category/%d'>%s</a>" % (category.id,
            category.name))

    return safestring.mark_safe(", ".join(c))

November 6, 2007

Adam Olsen
synic
Vimtips Latest Articles
» Feed Problems

Sorry about the weird RSS problems my blog has been having. Moving to a new system caused all the GIDs to be different, so all the old articles showed up as new in readers. Also, I'm fairly new to Django, so I forgot things like "categories" and "pub date" in the Feed class (I know, I'm an idiot), so all the feeds showed up in the incorrect order on http://www.openclue.org

Anyway, I think I've finally gotten it all figured out, so hopefully you shouldn't see these oddities anymore.

October 31, 2007

Adam Olsen
synic
Vimtips Latest Articles
» Thoughts on Django

Django is a "high-level Python Web framework that encourages rapid development and clean, pragmatic design." So far, I have absolutely no complaints... and much praise.

Going from never using Django to entirely rewriting my blog and converting all the old entries took me only a few days. I only had to write the HTML templates and a little Python code, and Django does the rest for me, including the entire administration panel where I can edit articles, article categories, links and etc.

Initial impressions are this: I can tell that this is going to be one of those things (like VIM) that is going to make me think "why, oh why, didn't I learn this earlier?"

I had a bit of trouble installing it on my Dreamhost account, but nothing that wasn't covered in their wiki (http://wiki.dreamhost.com/index.php/Django). I basically just had to contact support and ask them to configure my site for Python+FCGI. They were quick to respond and I had it working in a few hours from begin to end.

I am VERY pleased at this point :)

vim tip: Django template syntax definition

Searching Google for helpers for Django developers, I found a few things, but the only thing I've actually decided to use is the syntax definition file, which you can find here: http://www.vim.org/scripts/script.php?script_id=1487

October 29, 2007

Adam Olsen
synic
Vimtips Latest Articles
» Converting from TextPattern to Django

I like TextPattern a lot, but it doesn't seem to work well for programmers. I couldn't ever find a syntax highlighting plugin (that worked) for it, and even when I did figure out a way to post code TextPattern would try to format it.

So, I finally had a reason to learn Django, and here is the product. I even implemented my own syntax highlighting filter (Josh Simpson's idea to do this is actually what finally made me want to switch away from TextPattern in the first place):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from django import template
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter
from django.template import Context, loader
from django.template.defaultfilters import stringfilter
import re

register = template.Library()

@register.filter(name='code_highlight')
@stringfilter
def code_highlight(value):
    """ 
        Checks for <source lang='lang'> tags in the article, and runs them
        through pygments for syntax highlighting
    """
    t = loader.get_template('codeblock.html')

    regex = re.compile(r'(<source lang=([\'"])(\w+)\2>(.*?)</source>)',
        re.DOTALL)
    items = regex.findall(value)

    for (all, crap, lang, text) in items:
        lexer = get_lexer_by_name(lang, stripall=True)
        formatter = HtmlFormatter(linenos=True, cssclass="syntax")
        result = highlight(text, lexer, formatter)

        c = Context({
            'code_block': result
        })

        value = value.replace(all, t.render(c))

    return value

There's still a lot of work to do on it, but I'll get the old posts migrated soon.

November 2, 2007

Scott Paul Robertson
spr
Spr: The Ramblings
» Month of Django Tips

James Bennett is going to try to blog everyday for the month of November with a new Django tip each day. Let me just say that the first post is quite good, and I can only hope the rest of the month is filled with such useful information. His blog archives will quickly become an excellent reference.

February 25, 2007

Matt Harrison
no nic
Matt Harrison's blog
» Lessons in Open Source from the Django project [pycon]

I feel a little bad for just posting these notes. But I think they can be useful for others. These are notes learned about running an open source project from the Django project. Jacob Kaplan Moss - Lessons learned from Django Arguments for

February 23, 2007

Matt Harrison
no nic
Matt Harrison's blog
» Web Framework Panel notes [pycon]

Here's some notes from the web framework panel at Pycon, discussing various attributes of the frameworks and why python tends to have so many frameworks. Web Framework Panel Discussion led by Titus Brown featuring: * Zope - Jim Fulton * Che