abidibo.net

Posted in "tips"

Bootstrap progress bar animation

bootstrap javascript tips

Boostrap progress bar is a nice component that comes in handy when loading async contents, large images or, for example, when rendering a complex google map.

But as is, it is quite useless if you want to implement a dynamic loader, which progress value changes over time. There are two major problems:

  1. when updating the value there is no animation, but just a jump to the new provided value;
  2. if the value updates are set immediately one after another, you ...

read the full post




Pretty raw_id_fields with django-salmonella and django-grappelli

django django-admin programming tips grappelli

Sometimes, when dealing with m2m relationships, we need to use the raw_id_fields property of the ModelAdmin class, in order to choose the related objects in a new page, where we can sort and filter the available items.

Without doubt the information that the widget used by django to treat such fields gives us is a bit poor. We only see the related objects's ids, it would be nicer to have the string representation of the object.

Here comes django-salmonella:

A raw_id_fields widget replacement that handles display of an object's string ...

read the full post


Add links to django admin changelist view

django django-admin programming tips

Sometimes you may need to add one or more links for each table row in your admin changelist view. There are many ways to do it, and here we'ss see a simple one. So this post is nothing more than a tip.

In my case I had to add a link opening a pdf view of the model item detail, here comes my implementation:

- app/models.py

from django.db import models
from django.core.urlresolvers import reverse
from django.utils.html import mark_safe

class MyModel(models.Model):
    title = models.CharField('title', max_length=255)
    # ...

    def pdf_link(self):
        return mark_safe('<a class="grp-button" href="%s" target="blank">view pdf</a>' % reverse('archiviocr-opera-pdf', args=[self.id]))
    pdf_link.short_description = _('PDF')

- app/admin ...

read the full post


Check if user belongs to a group in django templates

django tips

Generally when implementing some "authentication logic" inside a django template it's enough to check if a user has some permissions, and in such cases you can use the variable perms, which is available if (from django site):

Technically, these variables are only made available in the template context if you use RequestContext and your "django.contrib.auth.context_processors.auth", which is default. For more, see the RequestContext docs.

But could happen that you need to check if a user belongs ...

read the full post


How to create your own speech recognition application with tasker

android tasker tips

Tasker is an awesome android app which let's you create and execute deep level tasks based on context in user-defined profiles, or widgets

What captured my attention is its javascript API which let's you interact with many phone functions through javascript, so you can imagine how many nice job you can accomplish with this app.

Here we'll see how you can implement your own speech recognition application so that your phone will answer to your defined commands!

We'll see how to get it through tasker interface, but then we'll see that it is possible to use javascript(let) to enhance our application.

Create the speech recognition task

Ok, let's start by creating our main task, here comes the description:

A1 ...

read the full post


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


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


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


Your Smartwatch Loves Tasker!

Your Smartwatch Loves Tasker!

Now available for purchase!

Featured