Enterprise LAMP

CodeWorks – Jason E. Sweat

I am winding down my “tour of duty” with the MTA crew for CodeWorks 2009. This is a really ambitious adventure, seven cities in two weeks. I was a member of the A-Team, doing 3 hour long tutorials on the first day of each city, while the B-Team was arriving. The following [...]

Python News: Python 2.6.3rc1 released

A candidate for the third maintenance release of the 2.6 series is available.

Jack Diederich: Your Talk Proposal Here

As it turns out one of the marginal items that gets trimmed in a down economy is conference jaunts [Q: who would have guessed? A: everybody]. PyCon 2010 needs talks, so if you have something interesting to say to a few hundred people this is your chance. I didn’t volunteer for the program committee this year so I don’t know the exact numbers but the acceptance rate is going to be much higher than the 50% for past years.

This is a great opportunity to practice your chops; I got my start when PyCon was 300 people and talks had a 90% acceptance rate. The last few years PyCon has had 1000+ people and even the smallest talk room gets 200 people. If you have anything interesting to say, this is your chance to say it.

NB, hopefully PyCon won’t have to do what other conferences routinely do and say “we’ve extended the deadline, but this time we mean it!” For fuck’s sake the conference is in Atlanta in February – I’ll be happily golfing during the time I’m not speaking.

NB, by “golfing” I also mean “going to the shooting range” and “bowling” as weather dictates.

ENB: Anna Ravenscroft has a tidy short list of bogus reasons why you can’t give a talk. The title is pointed at women but the excuses are universal.

Greg Wilson: To Read Is To Learn

Lots of people have said that computer science students should read code as well as write it.  Not many people have gone the next step and designed a course around that idea, which is why I was excited to read Jason Montojo’s recent post, and the course outline he has put together.  Jason did several undergrad projects with me, is one of the co-authors on Practical Programming, and plans to finish his M.Sc. in a few months—if anyone can pull this off, he can, and I’m sure he’d welcome your feedback.

Roberto Alsina: Dear Lazyweb, what’s the pythonic cross-platform fc-match?

Here’s what fc-match does:

$ fc-match "Droid Sans"
DroidSans.ttf: "Droid Sans" "Regular"

Or even:

$ fc-match "Droid Sans" -v | grep file:
      file: "/usr/share/fonts/TTF/DroidSans.ttf"

So, how does one do that, going from a font family name or font name to a font file, where there’s no fontconfig?

I found code for this in matplotlib’s font_manager module but it looks hard to untangle, and requiring matplotlib is a bit over the top.

If there’s no portable solution, I would be happy enough with three standalone solutions instead, and promise to publish an abstraction layer over them ;-)

So, dear windows and mac pythonistas, any pointers?

Hector Garcia: Tweaking URLconf (2 named URLs, 1 view)

Introduction

In a project with an application named concerts that lists concerts from european cities, consider a classic two-level URLconf where the root urls.py module "includes" (i.e. uses the include method from django.conf.urls.defaults) a second URLconf module.

urls.py

from django.conf.urls.defaults import *urlpatterns = patterns('',    (r'^concerts/', include('concerts.urls')))

concerts/urls.py

from django.conf.urls.defaults import *urlpatterns = patterns('concerts.views',    url(regex=r'^list/$', view='my_view', name='concerts_list_all'))

Let’s say you want to extend the URLconf and have two kinds of URL to call the same view, the first to display all concerts, the second for concerts in a given city:

/concerts/list/

/barcelona/concerts/list/
/london/concerts/list/
/paris/concerts/list/

First attempt: easily discarded

urls.py

from django.conf.urls.defaults import *urlpatterns = patterns('',    (r'^concerts/', include('concerts.urls'))    (r'^barcelona/concerts/', include('concerts.urls'))    (r'^london/concerts/', include('concerts.urls'))    (r'^paris/concerts/', include('concerts.urls')))

With this solution, I would have to create a new pattern each time a city was added to the project database. Obviously, we should remember to update the URLconf in some manual or automatic way. No way.

Second attempt: creating two urls.py

The last 3 URLs can be done easily by creating a URL pattern with a keyword argument location in the root URLconf:

urls.py

from django.conf.urls.defaults import *urlpatterns = patterns('',    (r'^concerts/', include('concerts.urls'))    (r'^(?P<location>\w+)/concerts/', include('concerts.urls_location')))

Then we duplicate concerts/urls.py to create concerts/urls_location.py and modify this latest one to use another named URL name:

concerts/urls_location.py

from django.conf.urls.defaults import *urlpatterns = patterns('concerts.views',    url(regex=r'^list/$', view='my_view', name='concerts_list_location'))

If we wouldn’t change the name from the url and left it the same for both files, the Django URL dispatcher would mess up.

So, if we make a request to /concerts/list/, concerts.urls would be included, and for a request like /barcelona/concerts/list/ concerts/urls_location.py would be.

Because we want to use the same view, a little bit of business logic must be implemented. So the function behaves differently if it receives the location keyword argument or not:

def my_view(request, location=None):    if location is not None:        # filter concerts QuerySet by location, for example    else:        # query all concerts    return render_to_response('base.html', {'location': location},        context_instance=RequestContext(request))

But it is stupid to have two files with so small changes between them (only the url name params). Also, every modification in one of them must be replicated in the other. It sucks.

Final solution #1

concerts/urls.py

from django.conf.urls.defaults import *

base_urls = ({
‘regex’: r’^$’,
‘view’: ‘my_view’,
‘name’: ‘my_view’,
},)

urls = [url(**base_url) for base_url in base_urls]

urlpatterns = patterns(’myapp.views’, *urls)

concerts/urls_location.py

from django.conf.urls.defaults import *from myapp.urls import urlpatterns as orig_urlpatterns

new_urlpatterns = orig_urlpatterns[:]

for u in new_urlpatterns:
u.name = ‘_’.join([u.name, 'alt'])

urlpatterns = patterns(”, *new_urlpatterns)

In the first URLconf module I create a tuple of url params dictionaries. This structure is the one to mantain. the patterns is automatically populated with it. Then, in the second one, before populating patterns we append a suffix into each url name param.

So, for example, in a template we can make unique calls:

{% url concerts_list_all %} {# renders '/concerts/list/' #}{% url concerts_list_location "barcelona" %} {# renders '/barcelona/concerts/list/' #}

Final solution #2

I recently came to a more simple and pythonic solution which also has the advantage that concerts/urls.py can be left in the common django syntax for URLconf modules:

concerts/urls.py

from django.conf.urls.defaults import *

urlpatterns = patterns(’myapp.views’,
url(
regex = r’^$’,
view = ‘my_view’,
name = ‘my_view’,
),
)

concerts/urls_location.py

from django.conf.urls.defaults import *from myapp.urls import urlpatterns as orig_urlpatterns

new_urlpatterns = orig_urlpatterns[:]

for u in new_urlpatterns:
u.name = ‘_’.join([u.name, 'alt'])

urlpatterns = patterns(”, *new_urlpatterns)

Kumar McMillan: PyCon 2010 – Get Your Proposals In

Proposals for talks at PyCon 2010 are due October 1st. That’s in two days! PyCon is really a little more like an unconference and is an excellent place to share your ideas or showcase your work to the Python developer community. If you’re having fun with something Python related then chances are it will make a great talk. Also, don’t be afraid to submit a proposal that you feel is unfinished. As long as you have a basic idea for a talk and can provide a decent outline then now is the time to sneak it in under the deadline.

I have given some talks at PyCon that I thought went pretty well over the past couple years: A talk about the Fixture module, Unicode In Python Completely Demystified (these slides still get a lot of traffic), and Strategies For Testing Ajax. All these talks were really fun. I considered proposing another talk but I’ve come to the realization that I have way too many spare-time projects on the go and I need every single minute of the next 12+ months to jam. I will of course be attending PyCon and hopefully can cook up a lightning talk on Fudge or one of my other pet projects in time.

Simon Willison: Python Logging 101

Python Logging 101. A really useful introduction to Python’s logging module by that module’s author, Vinay Sajip.

PHPBenelux Conference – Call for Papers – Zend Developer Zone

A brand new conference is on the horizon! PHP Benelux, one of the largest PHP user groups, is hosting a conference of their own in Antwerp, Belgium, on Saturday January 30th. They’ve announced their Call for Papers is open until October 31st.

Rene Dudfield: Spam detection on websites?

Assume you have a user content site – or you’re using software that can somehow get spam links inserted into it.

How do you find out if your website has spam put on it?

It seems a common enough problem these days… people putting spam links on websites. Surely there must be a service or piece of software to detect such a thing?

I can think of a few ways to go about writing one fairly easily (using existing spam detection tools… but applying them to a spiders crawl of your website). It would be much nicer if there’s already a tool which does such a thing though.

« go backkeep looking »

Warning: include(/home/remarkwit/enterpriselamp.org/wp-content/themes/Enterprise_LAMP/r_sidebar.php) [function.include]: failed to open stream: No such file or directory in /home/remarkwit/enterpriselamp.org/wp-content/themes/Enterprise_LAMP/archive.php on line 23

Warning: include() [function.include]: Failed opening '/home/remarkwit/enterpriselamp.org/wp-content/themes/Enterprise_LAMP/r_sidebar.php' for inclusion (include_path='.:/usr/local/lib/php:/usr/local/php5/lib/pear') in /home/remarkwit/enterpriselamp.org/wp-content/themes/Enterprise_LAMP/archive.php on line 23