You're viewing all posts tagged with python

Automatically converting urls to html links

Here’s simple Python snippet for converting urls to links in single text line:

import re

link_re = re.compile('(\s+\(?|^)((http|ftp|https)://[-\w\#$%&~/.;:=,?@+]+)', re.IGNORECASE)

def autolinks(line):
    return link_re.sub(r'\1<a href="\2" target="_blank">\2</a>', line)

It’s simple yet smart enough:

  • doesn’t touch urls inside html links <a href=”some url”>some text</a>
  • can be used with Markdown, as it doesn’t touch Markdown links

To enable auto links replacement in Markdown, you may use autolink extension.

Tags: python markdown html  
Comments: 45

Highway to brilliant wiki, part 1. Brillixy.

Hey!

I am unsatisfied.

It’s 21st century, the age of perfect web-frameworks and rapid development. But there’s no good wiki-like engine to satisfy reasonable requirements.

There are Trac, DokuWiki and many others and others. By the way, I really appreciate Trac and DokuWiki. But I need less. And more.

So, I just need an engine which:

  • has wiki-like basis: users can create, edit and delete pages,
  • has hierarchical pages structure,
  • can be easily themed, design is really matters,
  • is written in Python / Django and uses best web-development practices.

Brillixy

I started project to make such engine. I called it “Brillixy”. It’s hosted here: http://bitbucket.org/rudi/brillixy

Some design goals are defined:

  • keep specific part as tiny as possibe, reuse proven Django applications, write new ones for generic tasks
  • it should has multiple-project structure, so single installation may be used by some team for a number of projects

And some design decisions are done:

What’s next?

I’m planning to release v0.1 with most basic functions:

  • creating, editing, deleting pages
  • commenting pages
  • simple tagging, no AJAX
  • simple permissions scheme, allow everything to authenticated users
  • no changesets view at this point

It should be enougth to start use it for some project. I’m planning to complete it before 9 May 2010.

Comments: 45

Rewritable Django apps

The common good approach in designing applications for Django is write them to be reusable. Another approach is to build rewritable applications on top of reusable ones.

What’s the point?

There’re number of specific tasks, which can be splitted to generic blocks. But it seems, some “generic” blocks better not to be generic by theirs nature, because they need “a little bit specific” usage for every project.

We can build such apps in two ways:

  • make big reusable application with customization settings or
  • build rewritable application

Reusable vs Rewritable

Here’s comparison table of approaches.

Reusable Rewritable
Try to cover most generic use cases “out-of-box” and provide settings Set of “sketches” to provide basic use cases with examples for usages and possible extendings
Source code is redundant as it covers different use cases Source code is minimalistic
Usually depends only on Django and extra generic Python libs Usually are build on top of other proven applications
You’d better not modify application source Application source can be rewritten or extended using provided basis

Examples

Reusable:

Rewritable:

  • django-accounts-basic
  • (… actually, it’s hard to find examples, as that’s not common practice to publish such apps, but they MAY be useful! Here may be: basic e-shop application, basic wiki application, etc. Yes. I know, there ARE e-shops and wikis, but they are designed to be reusable, not to be rewritable).

Conclusions

Both approaches are for applications made by programmers for programmers.

Reusable applications are good for providing “out-of-box” solutions for generic tasks, they are rather “solid”, so fine customization is hard or can cause overcomplication.

Rewritable applications are good for providing code basis on top of reusable apps. They must be clean and as small as possible and it’s critical to provide working examples.

Comments: 45