close forgot it?
close
Login with password or OpenID

All articles, tagged with “None”

Vim actually seems to be quite nice for Python/Django development

In the past days there was a quite nice discussion on Editors of choice on the list, and this encouraged me to give Vim another try. This time, it seems to be rather fruitful!

 continue reading

Getting donations from PayPal

During my trip in Bulgaria starting in a couple of weeks we will take part in a fund-raising mountain hiking for the Karin Dom foundation. As besides our participation we would like to help them financially as well we decided to put together a small website where friends and colleagues might sponsor us, so we can transfer their donations to Karin Dom.

To accomplish this task, I wrote a small django application, django-donation. This application let’s you easily receive donations on your website, and tries to show some relevant information about your sponsors, like to total amount collected. Moreover, depending on the sponsors’ wishes you might show their name and donation as well.

During this work I have learned several things:

Circumventing PayPal’s security checks is a breeze (but still annoying to have to) For the donation I thought I will need a Business type account. Probably I was wrong as a Premium account would suffice, but when I realised this my account was already changed into a Business account, and PayPal was asking for all kind of weird papers. For some reason, they were not very eager to change back my account type, thus I went on and asked all kind of recommendations from Karin Dom, and explained to PayPal that actually I am not affiliated to them, we are just collecting funds for them. Finally they allowed my account, and now I can collect the donations. The twist in this story is that Karin Dom struggles getting the Business status, thus despite the PayPal button on their site, you can donate to them only via direct transfers.

Use the identifier if you can Unfortunately django-donation still has some flaws. The main problem is that I am not saving the unique identifiers of every transaction, and several of our donors were registered twice or even more times. I will fix this once I have some more time (might be tonight?), or feel free to do it, if you have some free time. :)

Finally, you can check out our Karin Dom sponsorship site here.

Export to CSV with Django

The past week as a sub-project of django-conference, I’ve built a really simple and hopefully useful application to make csv exporting extremely easy.

It uses python’s csv library, and can be set up for example with the following code in your urlconf:

from export_csv.views import export_csv 

export_attendees = {
    'queryset': Attendee.objects.all(),
    'filter_by': 'conference__pk',
    'export_data': {'is_presenter': 'Presents',
        'user.get_full_name': 'Attendee',
        'conference': 'Conference',
        'user.get_profile.affiliation': 'Affiliation',
        },
    'require_permission': 'conference.delete_attendee',
}

urlpatterns = patterns('',
    url(r'^export/attendees/(?P<object_id>\d+)/$', export_csv, 
    export_attendees, name='export_attendees'),
)

This code was taken from an ongoing project to build a conference administering application for django (and for the Hungarian Economists Association).

Basically, the above setting will take a queryset by default that can be further filtered to get the data to be exported, and the export_data dictionary describes the columns to be exported. As the example shows, the columns can be either callable or simple properties, and will be evaluated from the instances of the exported queryset, like attendee_instance.is_presenter(). While column headers are given as the values for export_data.

The view code is really simple, the only tricky part was to construct the callable/non-callable object paths described in export_data, this is done by the following method

def get_attr(object, attrs=None):
    if attrs == None or attrs == []:
        return object
    current = attrs.pop(0)
    try:
        return get_attr(callable(getattr(object, current)) and 
                    getattr(object, current)() or 
                    getattr(object, current), attrs)
    except ObjectDoesNotExist:
        return not_available

If you would like to add some extra functionality, like date based exporting, or just would like to play with the code, go and grab it from launchpad:

What to test in django?

I’m continuously trying to get used to test driven development, as I agree with its many advantages cited around the web. Still, I often find it hard to come up with a necessary (and hopefully sufficient) list of tests. Moreover, as I often code for fun only, I don’t pay much attention to the question. This has changed now as I got a paying project. Here are my first insights, I hope it will help other django enthusiasts as well. :)

The bottom line is test every method you write, including output variables and inside logic. Moreover, write tests that pass as they mimick normal usage, and then start to think about tests that fail if someone tries abnormal usage (like setting a start date after an end date).

 continue reading

Mert lokálpatriótának lenni jó!

Emlékszem, hogy mennyire megütköztem azon, amikor Karácsonyi Imi egyetemi évfolyamtársam Győrről mesélt. Ekkor éreztem először, hogy valóban létezhez “lokálpatriotizmus”. Azóta sok év eltelt már, és ha más okokból is, de egyre jobban érdekelnek engem is a különböző helyi hírek. Persze, miután Toulouseban élek, ezért kicsit furcsa magyar hírek után érdeklődni, de ez most lényegtelen.

A lényeg inkább az, hogy van egy-két kezdeményezés, amit olyan jó lenne otthon is látni megvalósulni, megvalósítani. Gondoljatok bele, hogyha a nagyjából Magyarország lakosságú New York helyi szinten jelentős adatait össze lehet gyűjteni egy honlapon, akkor mondjuk egy magyar kisvárosét (pl: Győr) miért nem? Illetve, ha egy Magyarország méretű városét össze lehet gyűjteni, akkor Magyarországét miért nem?

Az EveryBlock.com honlap célja, hogy minden háztömbről minél több információt adjon neked. Sajnos csak néhány amerikai nagyváros szerepel benne egyelőre. De június végén a projekt forráskódját közkincsé teszik majd. Ekkor már mindenkinek lehetősége lesz, hogy a hazai — ma még valószínűleg nem létező — adatokat összegyűjtsük, és kulturált formában megjelenítsük a neten. A projektet a projekt gazdája az alábbi videón részletesebben is bemutatja.

Hogy milyen adatok is érhetőek el? Nagyjából bármi, ami beszerezhető. A legegyszerűbb a fényképek kipakolása, de az alapötlet a különböző bűnesetek bemutatása volt. Mára azonban, étteremértékelések és kiadott építési engedélyek is szerepelnek a rendszerben. Figyelembe véve a hazai (potenciálisan legális, de mindenképpen undorító) lenyúlásokat és csalásokat, talán egy ilyen honlap is hozzájárulna a helyzet megváltoztatásához. A kérdés már csak az, hogy lesz-e valaki, aki megcsinálja, illetve lesznek-e elérhető adatok. Ha netán volna kedved egy ilyen projekt haza megvalósításán dolgozni, írd meg lent, vagy e-mailben (fent), hátha sikerül kitalálnunk valamit!

Egyébként más hasonló projektek is vannak. Én hirtelen egyről tudok. Ez a fentihez hasonlóan djangot használ, és kizárólag a helyi képviselőkre koncentrálnak, de az alkalmazásuk már ma is nyílt kódú.