abidibo.net

Posted in "django"

Add app's contents inside ckeditor with django-resckeditor

ckeditor django django-admin

I always use django-ckeditor in my web site projects when I need an html editor. CKEditor is a nice tool, highly customizable, which produces a well formatted html. Here at Otto srl there was the need to include custom app's contents inside the editor in an easy way, since the tool has to be used by unexperienced people.

I approached these requirements developing a custom CKEditor plugin, which can communicate with django apps async through ajax requests. Every app can ...

read the full post


Django Baton, a cool, modern and responsive admin app

django django-admin programming

I was a happy developer using django-suit for all my working projects. Now django-suit v1 is becoming a bit oldie, it is based on bootstrap 2.3, and rewrites so many templates that its compatibility with some other apps begins to suffer (i.e. django-filer). It's a shame, it was in my opinion the best admin app overthere.

I know django-suit v2 is on stage, at the moment of this writing it is in development, and I'm quite sure it'will ...

read the full post


Securing django with Let's Encrypt

django https security ssl

I just finished to setup ssl encryption for abidibo.net, using Let's Encrypt Certificate Authority. This post serves as a reminder for me, and maybe a sort of guide for you.

This post assumes the website runs with the following technologies:

  • django >= 1.8
  • nginx
  • debian 8 (jessie) with ssh access

Why Let's Encrypt?

Let's Encrypt is a free, automated, and open certificate authority (CA), run for the public’s benefit. It is a service provided by the Internet Security ...

read the full post


Django debug with vim and vdebug

dbgp debug django python vim

I'm currently re-configuring all my vim stuff, operation which I perform every x months/years. I used to debug django application using pdb and its set_trace method, this time I decided to integrate a debugging tool inside vim as I always did for PHP using xdebug.

I decided (after some other attempts), to use vdebug, which (as described in the ...

read the full post


Show google analytics statistics in django admin

django django-admin

In this post we'll see how to show google analytics statistics inside your admin index. If you use django-suit as your admin application then you could simply install django-otto-admin and follow the provided instructions to get it working.

Requirements

First of all we need to create a google developer project and a service account which will allow us to authenticate to the google analytics account.

Follow the steps in the Google Identity Platform documentation to create a service account from the Google Developer Console.

Once the service account is created, you can click the Generate New JSON Key button to create and download the key and add it to your project. Place the json file in a secure place, not ...

read the full post


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


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


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


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


Your Smartwatch Loves Tasker!

Your Smartwatch Loves Tasker!

Now available for purchase!

Featured