abidibo.net

Weblog

Modal django forms with bootstrap 4

bootstrap django modals

Some time ago' I wrote an article about how to implement django forms with bootstrap 3 modals. It turned out to be a quite interesting theme since many people surfed and read that page. So now I'll refresh these concepts changing them a bit, in fact we'll see how to implement django forms with bootstrap 4-alpha modals.

Aperitif

Some preliminary stuff.

I'm almost bored with overwriting the model form class of my generic view in order to add bootstrap classes to form fields, so I'll use django-widget-tweaks. Let's install it:

(.virtualenv)$ pip install django-widget-tweaks 

Add widget_tweaks to your installed apps ...

read the full post


ng-upload-window

angularjs

Yeppa! Today I registered my first bower package, ng-upload-window, an angularjs directive wrapped around Danial Farid's ng-file-upload upload service, which organizes uploads inside a layer window which remembers the google drive upload window.

$ bower install ng-upload-window

You can find all relevant information and installation instructions in the github project page.

In a nutshell:

  • all the uploads are stacked in a fixed positioned layer window
  • for each upload information are shown: file name, file size,  progress bar, the downloading remaining time and the status of the upload.
  • uploads can be cancelled
  • the window can be iconized
  • the window can be closed when there are no more running uploads, or it's automatically closed after 8 seconds.

This directive wraps only the ...

read the full post


How to send short text messages from your U8 smartwatch

android smartwatch tasker u8

With this entry I should gain a mention from U8 boss, whoever he is.

It's a shame that the wrist dialer can transmit to the phone only ~ 40 numbers, otherwise all this stuff could be even more cool. But first things first...

Some one told you that your cheap and stupid smartwatch can't send text messages?

Well, he was wrong! At least a bit wrong. Actually you can send very short text messages from your wrist and here I'll tell ...

read the full post


U8 smartwatch - Calculator App - Proof of Concept

android smartwatch tasker u8

This is a proof of concept of how we can develop a simple calculator app (basic operations over two numbers) for the U8 smartwatch taking advantage from the tasker+notification method described in my prevoius post. Read the "How to get the best of your U8 smartwatch" entry before going on if you've not done it yet.

Your Smartwatch Loves Tasker!

Since the whole post series about U8 smartwatch and tasker had a good following, I decided to ...

read the full post


Serve private media with angular, DRF, CORS and token authentication

angularjs django drf rest

A long time has passed since my last post, I was fighting hard with a project learning django REST framework and angularjs, and now time has come to share some interesting knowledges.

This entry talks about serving private media from a django REST webservice, developed with django REST framework, to angularjs, in a scenario which uses a token authentication schema and CORS requests.

The problems to face

Let's see the problems we have to deal with.

  • Media with django are normally served directly by the web server, so they are out of the authentication/permission logic of the application
  • The token authentication schema needs every request to contain an header 'Authentication' part providing the token key (also when requesting files ...

read the full post


Decorators with Python

decorator patterns python

Decorators in python can be quite easy to use and understand, but flexible decorators using the new syntax introduced by python 2.4 can be a bit more complex.

Here I'll try to explain (especially to myself) the world of decorators in python, starting from simple cases and ending with complex ones. Ideas and notions taken from the Pro Django book by Marty Alchin.

Decorators without extra arguments

Let's create a simple cache decorator you can use to store complex operations:

>>> def cache(func):
...   cache_dict = {}
...   def wrapper(*args, **kwargs):
...     key = '%s-%s' % (repr(args), repr(kwargs))
...     if key not in cache_dict:
...       cache_dict[key] = func(*args, **kwargs)
...       print 'cached'
...     return cache_dict[key]
...   return wrapper

A simple decorator function takes ...

read the full post


Python's excess arguments

programming python

What I've always really appreciated of python is the ability to give a function an arbitrary number of positional and keyword arguments, something that in PHP is not possible and is indeed very powerful.

When declaring a function, we can define 4 different types of arguments:

  • required arguments
  • optional arguments (a default is provided)
  • excess positional arguments
  • excess keyword arguments

for example:

def myfunc(a, b=3, *c, **d)
  • a is a required argument
  • b is an optional one since it's default value it's 3
  • the single asterisk before the c argument allows the function to accept any number of positional arguments
  • the two asterisks before the d argument allow the function to support arbitrary kewyword arguments

The order of ...

read the full post


How to get the best of your U8 smartwatch

android smartwatch tasker u8

Yesterday my new U8 smartwatch arrived to me after a long trip around the world.
I'm happy with it, ok it is not as smart as the samsung gear or the sony smartwatch, but it's a super cheap product and you can't expect too much from it.

Nevertheless it has some nice functionalities:

  • receive and make calls from your watch
  • receive phone notifications
  • control your camera and take photos
  • sync your phonebook and call log
  • play music
  • anti lost feature
  • barometer, altimeter and pedometer

Wow, but it's not my intention to talk here about such things, there are trillions of youtube videos reviewing them on youtube.

Here I want to deepen how we can use two of such functions in ...

read the full post


How to exclude choices of m2m raw_id_field in django admin

django programming django-admin

This procedure took a lot of effort to be understood, but now it seems quite easy.

Scenario

Imagine we need to create a recursive m2m relationship, something like a "related posts" field assigned to a Post model. It would be nice if we could exclude the current editing post from the available choices.

This is quite straightforward if we go with the default select multiple widget. In fact we only need to create a custom form class and override the queryset property of the related_posts field in the __init__ function, excluding the id of the current instance, and then assign such form class in the ModelAdmin class, see this SO question for more info.

But things become more ...

read the full post


Lightscribe on ubuntu 14.04 64-bit, what worked for me

lightscribe linux

Lightscribe technology is cool, but almost noone uses it. Actually it can be hard also to find writable disks,  at least in Italy.

I think this is the reason why having this technology working in ubuntu 64-bit can be a mess. You may find some discussions about the installation of the necessary software, but it seems that there isn't a "widely working" solution, so let's add another "worked for me" solution.

Install the ia32-libs

This package contains runtime libraries for the ia32/i386 architecture, configured for use on an ...

read the full post


Your Smartwatch Loves Tasker!

Your Smartwatch Loves Tasker!

Now available for purchase!

Featured