abidibo.net

Weblog

Django chained selects with mootools

django forms mootools tips

Notice!

A due specification here!
Such method works, but IMHO should not be used with a large amount of data, since it uses a js mapping array, but is simple and requires a few lines of code, so why not to use it when we have a controlled set of data?

Introduction

This is just yet another method to implement chained (cascading) selects in django forms. I'm focusing here on the frontend form construction, not the admin area. If you're interested in the admin area instead, please take a look here.

Scenario

Imagine we have such models:

class ...

read the full post


Calculator mootools plugin

calculator math mootools

Some days ago I was developing a library to show and run mathematics exercises on the web, and I needed a simple calculator widget.

A search in the mootools forge led to 0 results, so I decided to write my own plugin, also because I needed only some basics operations (sum, difference, multiplication, division, percentage, pow and sqrt).

The result is the Calculator plugin, now available on the mootools forge.

demo

Such plugin let's you create a calculator instance ...

read the full post


Required class attribute in django ModelForm

django tips

Days ago' I was developing a front-end form in order to give users the opportunity to subscribe to a newsletter. I used the django ModelForm class because I didn't need nothing special except from hiding some model fields.

But I run into a problem, the compulsory fileds where handled properly in the sense that the form submission returned an error if such fields weren't filled, but there wasn't any attribute assigned to the label element in order to style it different from non-compulsory fields.

Nothing special here, nor complicated, but it costs me a while to find the reason for this, so I'll share it with you. The simple solution is to add a line ( required_css_class ...

read the full post


Low battery notification with fluxbox

bash battery conky fluxbox

I'm very happy with my fluxbox window manager, but there is a thing which causes me some problems, the lack of a notification message when my laptop battery has a really low charge.

I run conky as monitor display, which shows me battery information, but while I'm working I don't care of my desktop most of the times, I'm overwhelmed by all my opened windows and applications and so always happens that my machine shutdown because ...

read the full post


Fluxbox, configure an external monitor

fluxbox hdmi linux tips vga xrandr

One problem I still haven't solved with fluxbox is how to manage multiple monitors resolutions.
More specifically, I can stream the output over multiple monitors, I can have multiple resolutions, but fluxbox sizes itself considering only the first screen resolution.

For example if I boot my machine with an external VGA monitor connected, the system boots and both the VGA monitor and the laptop monitor work (even if the laptop monitor is closed). The problem here is that my laptop monitor has a 1366x768 resolution, while the external monitor is fullHD. So what happens is that I'll have the maximum resolution supported by all active monitors (1366x768) and so my fullHD monitor looks very ugly!

I learned playing ...

read the full post


Connect to WPA2 wireless network through command line

linux network tips

There is one rule I learned during my linux experience: If you want to learn things, you've to break things.
Trying to solve problems alone is the best way to increase your linux knowledge.

That said, almost every disaster can be recovered through your command line, so when X crashes, when you have broken your windows manager or display manager, you'll always be able to recover from terminal, BUT you need at least one thing: one active internet connection.

If you can go with a LAN cable ok, there is hopefully no problem, but what if only a WPA protected wlan network is available for you?
Clearly you've to connect to such network through command line in ...

read the full post


Convert select multiple widget to checkboxes in django admin form

django django-admin django-mptt jquery

I think this should be a nice post talking about the substitution of the default multiple select widget used in django admin interface to deal with m2m fields, with a multiple checkbox widget.

Yes I know, you may solve it this way, but I don't like such solution very much, and I think it is just not perfect for some reasons:

  • At the time of this writing the add related functionality (+) seems to be broken, throws an error, at least for me
  • It just can't be used with the django-mptt application, which is awesome to deal with data which have a tree like structure

So to graphically explain what we want to do here, say we want this ...

read the full post


Reverse selector engineering with mootools

css javascript mootools selectors

What if you need to get the css selector which targets a DOM element given the element itself?

This is the case for example when you want to store some added information over an element and show it after recharging the page. In this case you may store the information in the local storage object together with the path to the element, in other words you must be able to store the element position inside the DOM

In this scenario ...

read the full post


MySQL, bad preformance of INFORMATION_SCHEMA queries

cache mysql performance php

Recently I've discovered a quite big perfomance problem when running INFORMATION_SCHEMA queries on mysql.

In particular I found that on some systems (some mysql versions) a query like

SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'db_name' AND TABLE_NAME = 'db_table'

can take up to 0.1s to run!

Clearly such time interval is not acceptable, and I think it happens only with some versions of mysql because I've run some tests on my local machine and on the server where this site is running obtaining a result of 0.0007 seconds, we are talking about a difference of two orders of magnitude!

I've not investigated more about which mysql versions are affected and if there are any patches, I ...

read the full post


Glen Hansard, Milano 2013

glen hansard life me music

Dunque oggi sono scassato come una merda, ma sono contento perché ieri sera sono andato in una disco tamarra di Milano a sentire Glen Hansard in concerto.

Inizio concerto ore 20:00, ore 20:00 meno qualcosa parcheggiamo a poca distanza dal locale, 3 bottiglie di vino alle spalle, ci incamminiamo verso l'ingresso e santo Carlo "Oh, ma è Glen!", scorge Glen camminare verso di noi diretto probabilmente ad una birra e paninazzo.

Molliamo di brutto filtri e armamentari e lo placchiamo. Flu rotto in culo si fa firmare l'ukulele ora vero e proprio cimelio. Poi è il momento della foto ed inizio a blaterargli qualcosa di incomprensibile riguardo al fatto che anch'io avrei voluto fargli ...

read the full post


Your Smartwatch Loves Tasker!

Your Smartwatch Loves Tasker!

Now available for purchase!

Featured