Using Django @alwaysdata



Nicolas Ferrari

Nov. 5, 2012 (Paris, France)
Nov. 17, 2012 (Rennes, France)
Nov. 24, 2012 (Toulouse, France)

About alwaysdata.com

Hosting platform. Support Django.

Transitioning to Django

Why?

Awesomeness

File structure

Initial file structure

.
├── administration_
│   ├── settings.py
│   ├── urls.py
│   ├── administration
│   │   ├── models.py
│   │   ├── templates
│   │   └── views.py
├── website_
│   ├── settings.py
│   ├── urls.py
│   └── website
│       ├── models.py
│       ├── templates
│       └── views.py
├── etc.
.
        

Current file structure

.
├── administration
│   ├── templates
│   │   ├── alerts
│   │   └── invoice
│   ├── templatetags
│   └── views
├── fixtures
├── overlord
│   └── templates
│       └── admin
├── phpmyadmin
│   └── templates
├── phppgadmin
│   └── templates
├── reseller
│   ├── templates
│   ├── templatetags
│   └── views
├── status
│   └── templates
├── webmail
│   ├── templates
│   └── views
└── website
    └── templates
        
├── common
│   ├── billing
│   │   ├── payment
│   │   └── wallets
│   ├── cruds
│   ├── domains
│   ├── mails
│   ├── models
│   ├── scripts
│   ├── services
│   ├── sites
│   │   ├── httpd
│   │   └── type
│   ├── templates
│   │   └── common
│   ├── templatetags
│   ├── utils
│   └── vendors
│       ├── domains
│       ├── sms
│       └── telephone
        

Signals

Signals (example)

def database_user_delete(sender, instance, **kwargs):
    if settings.ENABLE_ARCHITECTURE_OPERATIONS:
        alwaysdata.common.scripts.database.delete_user(instance)

pre_delete.connect(database_user_delete, sender=DatabaseUser)
        

Custom CRUD library (simple example)

class FtpUserCrud(django_crud.ModelCrud):

    model = FtpUser
    form_class = FtpUserForm
    operations = 'CRUDL'
    url_prefix = 'ftp'
    decorators = [permission_required('account_ftp')]

    def get_success_url(self):
        return reverse('domain_read', args=(self.domain.id,))

    def get_created_message(self):
        return mark_safe(_(u"L'utilisateur FTP %s a été créé.") % self.object.name)

django_crud.handler.TemplateHandler.register(FtpUserCrud)
        

get_object(), get_queryset(), get_context_data(), get_form(), get_form_kwargs() and more...

Custom CRUD library (api example)

class ApiModelCrud(django_crud.handler.api.ApiModelCrud):

    excludes = set(('password',))
    url_prefix = 'v1/'

class DatabaseCrud(ApiModelCrud):

    model = Database
    form_class = DatabaseForm
    operations = 'RUL'
    decorators = [permission_required('account_database')]
    url_prefix = ApiModelCrud.url_prefix + 'database'
    excludes = ApiModelCrud.excludes | set(('account', ))
    container_fields = ['options',]

django_crud.handler.ApiHandler.register(DatabaseCrud)
        
$ curl https://api.alwaysdata.com/v1/database/12345/ -u /batman:apikeyapikeyapikeyapikeyapikey
HTTP/1.1 200 OK
{
    "id": 12345,
    "href": "/v1/database/12345/",
    "name": "batman_joker",
    "type": "postgresql"
    "is_postgis": false,
    "encoding": "LATIN1",
}
        

Thank you!

@alwaysdata
@ferrouzzz