Posted
over 2 years
ago
Doing Local Right. The slides from my presentation at @media 2007.
Posted
over 2 years
ago
Наконец-то у снова дошли руки до Cicero. Реализацию поиска я, правда, решил отложить, чтобы немножко еще в голове уложить, чего же я от него
... [More]
хочу. Вместо этого я занялся модераторами и редактированием статей. [Less]
Posted
over 2 years
ago
When Django was first released, it was only straightforwardly possible to deploy it using mod_python, for which it was designed. ...
Posted
over 2 years
ago
There is a fantastic free service available to create screenshots of websites using an API at bluga.net. The problem is, there are no samples in Python. As part of a project I'm working on with the Django community, I've written a simple Python interface to the bluga.net webthumb API which lets you pass in a URL and receive back a screenshot.
Posted
over 2 years
ago
My employer has generously agreed to send me off to OSCON this year and I'm very excited. I'm doing the whole shebang, tutorial days and all. (Current tutorial picks: Learning Ruby, Django Master Class, Modern Web Development with Python and WSGI
... [More]
, and Time Management for System Administrators.)
I had a blast and learned a ton attending OSCON in 2005 and I expect this round to be even better. For one thing, my involvement in open source projects, notably Django, means I know more people. And the whole open source world -- dare I say movement? -- has only gotten more powerful and impressive. I get to become better at my job while learning cool stuff and meeting smart people. I'm a lucky guy.
I also plan to do some serious pinball playing at Ground Kontrol.
Are you with me? [Less]
Posted
over 2 years
ago
All of a sudden, more than a month has passed and I have not added any new entries. I've been working on and off on a markdown extension to handle abbr and acronym tags. So far it simply refuses to work (the code doesn't even seem to get executed).
... [More]
For the curious:
import re, markdown, random
class AcronymExtension (markdown.Extension):
def __init__ (self, configs) :
self.config = configs
def extendMarkdown(self, md, md_globals) :
self.md = md
ABBR_RE = re.compile(r'\[(. ?)\]\{([^{] ?)\}')
ACRONYM_RE = re.compile(r'\[([^\]]*)\]\{\{([^}] )\}\}')
md.inlinePatterns.append(AcronymPattern(ABBR_RE, self.config))
# md.inlinePatterns.append(AcronymPattern(ACRONYM_RE, self.config))
class AcronymPattern (markdown.BasePattern) :
def __init__ (self, pattern, config) :
markdown.BasePattern.__init__(self, pattern)
self.config = config
def handleMatch(self, m, doc) :
abbr = doc.createElement('abbr')
abbr.appendChild(doc.createTextNode(m.group(1)))
abbr.setAttribute('title', m.group(2))
return abbr
def makeExtension(configs=None) :
return AcronymExtension(configs=configs)
if __name__ == "__main__":
import doctest
doctest.testmod()
So, in the meanwhile, I'm not able to deliver on my promise to talk more about microformats.
However, if you're astute, you've noticed that the tag cloud on these pages has changed. John Buchanan recently released a distutils-enabled version of django-tagging.
He's implemented both the features I requested, which makes me greatly happy. I've added the first feature to this site already. Now, when you click on a specific user's blog, you will see the tag cloud that pertains to that user only. When you go back out to the main blog page you'll see an aggregate or global tag cloud. A lot of thanks to Mr. Buchanan for his work.
The other thing that this site now has is email. Jay Pfeifer has been helping me set up a lot of the back end of this site. He helped set up apache properly; he's been the signing authority for my SSL certificates; and this week he set up the email back-end. I'll have more to talk about when I do something with that (for now I'm just setting up imap access for my family members). Maybe the django-webmail project can move forward a little bit more.
Sorry to have kept so silent. If you have any feedback on the broken markdown extension code I pasted above, please leave me a comment. I'd love to get that working properly. [Less]
Posted
over 2 years
ago
Just to follow up on the last entry's mention of django-tagging, I thought I'd paste the ebuild I created for it (that I have in my own personal overlay. I'm opting for not providing a download because the version could change and this ebuild code
... [More]
should be valid for higher versions. I named the ebuild django-tagging-0.1.ebuild and threw it into /usr/local/portage/dev-python/django-tagging. After that, just go into that directory and run:
ebuild django-tagging-0.1.ebuild digest
emerge django-tagging
That should do it. Then in your settings.py file, you'd add tagging into your INSTALLED_APPS list, and you're off. Without further ado, here's the ebuild code:
# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $
inherit distutils
MY_P=${P/django-/}
S=${WORKDIR}/${MY_P}
DESCRIPTION="A generic tagging application for Django projects, which allows
association of a number of tags with any Model instance and makes retrieval of
tags simple."
HOMEPAGE="http://code.google.com/p/django-tagging/"
SRC_URI="http://django-tagging.googlecode.com/files/${MY_P}.zip"
LICENSE="MIT"
SLOT="0"
KEYWORDS="~x86"
IUSE=""
DEPEND="dev-python/django"
RDEPEND="dev-python/django"
src_install() {
distutils_src_install
dodoc *.txt docs/*.txt
}
All you gentoo django people can now enjoy the goodness of django-tagging with minimal fuss :) [Less]
Posted
over 2 years
ago
Deploying a Django app on the desktop. Silver Stripe used cx_freeze to package their commercial agile project management Django application as an easy to run Windows executable.
Posted
over 2 years
ago
I subscribe to feeds of items tagged with “django” on a couple of sites, and tonight I noticed a link which posed a hypothetical situation ...
Read full entry
Posted
over 2 years
ago
Following up to the part 3 of my series about implementing a multilingual interface for this blog, I now present the things to make the language-magic happen: Middleware and context processors.
Disclaimer
When I wrote this code, I
... [More]
wasn’t aware of the threadlocals pattern. In the next iteration of the code, I’ll make use of it. For now, it works good enough so it stays.
Views, part 2
Those who read carefully or tried to use the code I posted on my previous post, would notice that I was referencing request.url_lang, which of course would lead to an error, since it’s not obvious on when and where it’s set. So let’s present this:
Middleware
Here’s a little helper function that does this:
re_language = re.compile(r’^/(?P<lang>[a-z]{2})/.*’)
def put_language(request):
m = re_language.match(request.path)
if m:
lang = m.group(‘lang’)
request.url_lang = lang
#print request.url_lang
else: raise Exception()
return None
You can see that it uses a regular exception, so it’s trivial to set it up to suit different needs.
Now we have another problem, that our URLconfs and views would have to be aware of this URL scheme, and it would make it tedious. So, we go and rewrite request.path like this:
class LanguageMiddleware:
def process_request(self, request):
for key in exceptions:
if request.path.startswith(key):
request.url_lang = request.LANGUAGE_CODE
return exceptions[key](request)
try:
put_language(request)
request.oldpath = request.path
request.path = request.path[3:]
except Exception:
if request.POST: return None
return HttpResponseRedirect(“/” request.LANGUAGE_CODE request.path)
if request.url_lang != request.LANGUAGE_CODE:
request.different_lang = True
return None
Warning
Django documentation states clearly that I shouldn’t treat request.path as a writable property. Nevertheless I do. So this may break in the future.
This code does many little things:
It sets the request.url_path attribute
It removes the language part of the URL that django will use.
It stores the request.path into request.oldpath. I use this in my 404 template to show the URL a visitor will actually see. Try to put a random address and see that the path displayed is the correct one.
It redirects requests that don’t have any language information set, so that there are no links and searches directly. Try to delete the language from the URL, and see what happens.
It sets a flag if the URL language is different from the detected language, so we can present a message to the visitor. Try replacing the en part of the url for this post with el.
Finally a wart. For some views, I don’t want all this to happen, so I’ve setup an exceptions table:
exceptions = {
‘/i18n/’: ret_none,
‘/static/’: ret_none,
‘/feeds/’: ret_none,
‘/accounts/’: ret_none,
‘/en/about/’: put_language,
‘/el/about/’: put_language,
‘/google’: ret_none,
‘/robots.txt’: ret_none,
}
ret_none = lambda x: (None)
This isn’t so good, since if I want to add a new flatpage (like /el/about/) I’ll have to add another entry. I should move this to the database somehow, but I haven’t had the time to figure it out. If you have an idea, please tell :)
Context processors
Nothing big, really:
def language_note(request):
try:
if request.url_lang != request.LANGUAGE_CODE:
if request.LANGUAGE_CODE == ‘el’:
note = ‘Βλέπετε αυτή τη σελίδα στα Αγγλικά. Είναι επίσης διαθέσιμη στα <a href=”/el%s”>Ελληνικά</a>’%(request.path,)
else:
note = ‘You are viewing this page in Greek. It is also available in <a href=”/en%s”>English</a>’%(request.path,)
return {‘language_note’:note}
except AttributeError:
pass
return {}
I should make this handle more than one available language, but I have no need right now, so I won’t ;)
Epilogue
That’s all for now. This series is over. I have some ideas about making this a bit simpler, but I have no time to fool around right now. In fact, if I have to make another multilingual site, I’ll probably use django-multilingual and put some effort in improving that.
It was good scratching the itch, though :)
Comments [Less]