Fernando Correia’s Weblog

November 10, 2008

First experience with BlueTripCSS Framework

Filed under: Software Development — Fernando Correia @ 9:54 pm
Tags: , ,

A few days ago I went looking for info on CSS frameworks. I found a very interesting article that led me to the BlueTripCSS Framework by Mike from Capsize Designs.

Today I wanted to create a simple and clean website and I decided to try BlueTrip.

I was very impressed with how simple and easy it was. I highly recommend BlueTrip for its great typography that it inherits from Tripoli and for the easy-to-use grid that comes from Blueprint.

I just didn’t like the icons on the Web links and I decided to get rid of them. I could do that easily by just writing a custom style.css file to override the defaults:

a[href^="http:"]:visited { background:none; padding:0; margin:0; }

I tested the page in Firefox in Ubuntu and in Firefox, Internet Explorer 7 and Chrome in Windows XP and I got nearly identical results in all of them.

So, I’m very satisfied with BlueTrip. Mike did a great job by putting together two of the best CSS frameworks.

Thanks, Mike!


November 8, 2008

Exploring Pinax Series

Filed under: Software Development — Fernando Correia @ 8:26 am
Tags: ,

Pinax is an integrated collection of selected Django reusable applications. It can be used as a head start for website projects and also to experiment patterns of Django applications.

As I learn how to leverage Pinax to build Web applications, I’m writing about my experiences. I plan to update this article and to use it as an index:

  • Part 1: Installing Pinax.
  • Part 2: Creating a new tab.
  • Part 3: Creating a new application inside a Pinax website.
  • Part 4: The main domain object of the sample application.
  • Part 5: A form for submitting new items.
  • Part 6: Comments on approaches to revision control.
  • Part 7: Notifications.

The source code for the sample application is hosted on GitHub.

I also have a feed for my Pinax-related articles.

Exploring Pinax – Part 7

Filed under: Software Development — Fernando Correia @ 8:22 am
Tags: ,

I’m proceeding in my quest to learn how to create a Django application using Pinax as a base. I’m writing a sample paste bin application called Oxybeles. It’s main feature will be the ability to send pasted items to another user and to receive new pasted items as responses.

I want a user to be notified when another user sends an item or responds to one. So I went looking how the applications integrated into Pinax do that. For instance, the Inbox feature in Pinax can be used to send a message to another website user:

The Propose Swap feature of the Swaps application will also notify another user:

Those notifications can be seen in the Notices feature of the Inbox:

By inspecting the source code for these features, I found out that they use the django-notification app. There is some documentation about it on the Pinax project website. So, I started following it.

Creating notice types

Following samples and documentation, I created the file apps/oxybeles/management.py that creates notice types at syncdb time:

from django.db.models import signals, get_app
from django.utils.translation import ugettext_noop as _
from django.core.exceptions import ImproperlyConfigured

    notification = get_app('notification')

    def create_notice_types(app, created_models, verbosity, **kwargs):
            _("Pasted Item Received"),
            _("you have received a pasted item"))
            _("Pasted Item Sent"),
            _("you sent a pasted item"))

    signals.post_syncdb.connect(create_notice_types, sender=notification)
except ImproperlyConfigured:
    print "Skipping creation of NoticeTypes as notification app not found."

Then I ran syncdb:

$ python manage.py syncdb
Created pasteditem_received NoticeType
Created pasteditem_sent NoticeType

Notification templates

Then I created the templates that will be used to format the notifications. Each set is composed by three files: short.txt, full.txt and notice.html. For each notification type I created a directory under apps/oxybeles/templates/notification. For instance:


{% load i18n %}{% blocktrans with pasted_item.get_absolute_url as pasted_item_url %}
{{ sender }} sent you a pasted item:

http://{{ current_site }}{{ pasted_item_url }}{% endblocktrans %}


{% load i18n %}
{% blocktrans with pasted_item.get_absolute_url as pasted_item_url %}
You sent a <a href="{{ pasted_item_url }}">pasted item</a> to {{ recipient }}.
{% endblocktrans %}

Sending notification

After that I should be able to notify a user when someone sends a pasted item. The first step is to add an appropriate field to the pasted item detail template:


<h1>Pasted Item</h1>
<p>{{ object.text }}</p>
<div id="basic-form">
<legend>{% trans "Send Item" %}</legend>
<form id="pastebin_send_form" method="POST" action="">
<div>{{ form.non_field_errors }}</div>
<div>{{ form.recipient.errors }}</div>
<div>Send to another user: {{ form.recipient }}</div>
<div><input type="submit" value="send" class="button" /></div>
<input type="hidden" name="action" value="send" />
<input type="hidden" name="uuid" value="{{ object.uuid }}" />

And a form to deal with the submitted data:

In apps/oxybeles/forms.py:

class SendItemForm(forms.Form):
    uuid = forms.CharField(max_length=36)
    recipient = forms.CharField(max_length=30)

The view that shows a pasted item now will also act on this form’s data:

In apps/oxybeles/views.py:

def detail(request, uuid, form_class=SendItemForm, template_name='oxybeles/pasteditem_detail.html'):
    form = form_class()
    if request.method == 'POST':
        if request.POST["action"] == "send":
            form = form_class(sender=request.user, data=request.POST)
            if form.is_valid():
                    message=ugettext("The pasted item was sent."))
                url = form.pasted_item.get_absolute_url()
                return HttpResponseRedirect(url)
    pasted_item = get_object_or_404(PastedItem, uuid=uuid)
    return render_to_response(template_name,
                              { 'object': pasted_item, 'form': form },
detail = login_required(detail)

The form.save() function will notify the recipient and also the sender.

In apps/oxybeles/forms.py:

def save(self):
    self.pasted_item = self.cleaned_data['uuid']
    self.recipient_user = self.cleaned_data['recipient']
    if notification:
        notification.send([self.sender], "pasteditem_sent",
                            {'pasted_item': self.pasted_item,
                            'recipient': self.recipient_user,})
        notification.send([self.recipient_user], "pasteditem_received",
                            {'pasted_item': self.pasted_item,
                            'sender': self.sender,})

django-notification does all the work. It creates the notifications and will also mail the user if the preference is enabled. The email will only be sent when we run manage.py send_mail, though.

Now I can send a pasted item I’m seeing:

Sending a pasted item

Those sendings are recorded as notifications:

Item sent notification

And the recipient is notified when someone sends an item:

Item received notification

Pinax is an integrated collection of selected reusable Django apps, and I’m starting to learn how to leverage it. Seems pretty nice so far.

The code for this article is hosted at GitHub. Feedback is welcome.

Create a free website or blog at WordPress.com.