Printing emails in Django

When developing applications in Django, it may be nice to print emails instead of sending them. If you send them you have to be careful which addresses you use. Just being on the safe side and always using @example.{com,org,net} is not enough, you have to use an address you can actually retrieve emails for. And you have to configure your development environment to actually deliver mails. And then wait for the whole thing in each code-try iteration.

So, basing myself on the testing code, I’ve added this to settings.py and mails are now printed:

if DEBUG:
 from utils import BogusSMTPConnection
 from django.core import mail
 mail.SMTPConnection = BogusSMTPConnection

Of course you’ll also need the BogusSMTPConnection class, I’ve defined it as following:

from textwrap import wrap
class BogusSMTPConnection(object):
  """Instead of sending emails, print them to the console."""

  def __init__(*args, **kwargs):
    print("Initialized bogus SMTP connection")

  def open(self):
    print("Open bogus SMTP connection")

  def close(self):
    print("Close bogus SMTP connection")

  def send_messages(self, messages):
    print("Sending through bogus SMTP connection:")
    for message in messages:
      print("tFrom: %s" % message.from_email)
      print("tTo: %s" % ", ".join(message.to))
      print("tSubject: %s" % message.subject)
      print("t%s" % "nt".join(wrap(message.body)))
      print(messages)
      return len(messages)

And that’s it.

Advertisements

What is a blog?

Going back to Plone, after using WordPress for a long while, and yet again inflicting a painful migration on myself, I ended up asking myself this question: What is a blog? and I’ve found an answer that really surprised me.

I’m a very structured person. Do you remember how everybody had a folder named MP3 back in 1999 or 2000, when MP3  became popular and people started to store music on their computers? Well, I didn’t have such a folder. My folder was called “music”. MP3 was only the format, what I had in that folder was, actually, music. And I even tried and convinced some people about doing the same. Continue reading “What is a blog?”

Who are Conor O'Brien and James McMahon?

Conor O’Brien of the Raglan Clinic and James McMahon of Hassett are the people that own me €1250, the deposit of the apartment I rented for more than a year in 4, Windermere, Gilford Road, Dublin 4, Ireland. That I returned in perfect condition and was accepted as such, more than a month ago.

Now that we got to the point, let me tell you the story. I’ll try not to sidetrack with issues like Conor arriving more than outrageously late when I had to handover the apartment and had very little time (moving to Zürich, where I live now) or that James published the apartment as having dishwasher and cable TV which it didn’t (nor was there hot water as well, or fire alarm, or the two set of keys, etc). Ooops, sidetracked. Or that when I went there with James and my wife to see the apartment, there was a guy taking a shower, in the apartment, that shouted “don’t come” and we had to return the day after. Ooops, sidetracked again. Continue reading “Who are Conor O'Brien and James McMahon?”

Typing Esperanto in Ubuntu (or any other X)

I’ve got tired of not being able to easily type in Esperanto in Linux. There are some articles out there explaining it how and the are always convoluted and I’ve never seen one that gets to the point of typing “ŭ”, the always try very hard to get “ĝ”.

There’s an Esperanto layout in Ubuntu and I suppose other X Window Systems as well, but there are two things I don’t like about it. One is having to find out where the keys are, I could re-label them, but then I would only be able to type in Esperanto (which might be educational but not what I want, at least for now). I also don’t like the fact that it is Qwerty, not Dvorak. And even if it was Dvorak, one should make the statistics about Esperanto to make a proper Esperanto Dvorak-style keyboard. Continue reading “Typing Esperanto in Ubuntu (or any other X)”

The single most important feature of Git

My favorite versioning system was Darcs for a long time, but it didn’t really took off and a new competitor is taking off amazingly fast: Git. I believe the single most important feature of Git is to be able to clone (checkout in Subversion jargon) repositories from other systems, particularly SVN. That means that your favorite project may be using SVN, but you just clone it and work with Git, in a distributed way, and then send back the changes. Or that you can clone the SVN-repo and basically you already migrated. Amazing!

Playing with Ruby

This is a remake of Installing Rails 2 on Ubuntu but targeting Ruby in general and with some improvements. Essentially the same, actually, but more usable, at least for myself.

Ubuntu, like many other free operating systems, have a beautiful package management system that will track what depends on what, what is installed, what is not, what is not longer needed, which versions of each. If you tamper with it, you are asking for trouble. If you do a manual upgrade, from sources, eventually a package upgrade will downgrade your version or some other application being incompatible will not work. And once you start throwing files in /usr, you start to ask for trouble. I’ve been using this type of operating systems for years and I’ve learned this by experience.

Continue reading “Playing with Ruby”

Pylons or Django?

I am trying to decide whether to use Pylons or Django. Both are frameworks for building Python web applications, but with opposing philosophies.

Django tries to be everything. It comes with its own ORM, its own template engine, its own everything. That gives you a nice developing experience because everything fits together and because very nice applications can be built on top of all those components, like the admin tool, which is amazing. Continue reading “Pylons or Django?”