Rango is a spicey API to Django with some extras.
Project description
Rango
=====
Rango is a bit of spice for Django.
Why?
----
I beleive that short and plain imports are better than long
nested ones.
In Django you should write in your ``views.py``:
from django.core.urlresolvers import reverse
from django.shortcuts import get_object_or_404, redirect
from django.contrib.auth.decorators import login_required
In Rango:
from rango.urls import reverse
from rango.views import get_object_or_404, login_required
Actually that is experimental project tending to build cleaner
API for Django.
Core features
-------------
### New ``reverse`` method
It works like that:
from rango.urls import reverse
reverse('url_name', pk=8)
Django ``reverse`` works so:
from django.core.urlresolvers import reverse
reverse('url_name', kwargs={'pk': 8})
### Base model class
It has shorcuts for ``all``, ``get``, ``filter`` and ``exclude``
methods and some extra magic:
from rango import models
class MyModel(models.RangoModel):
class MyModel(RangoModel):
title = models.CharField(max_length=100)
is_active = models.BooleanField()
@classmethod
def active(cls, _queryset=None):
return cls.filter(_queryset, is_active=True)
all_objects = MyModel.all()
start_with_a = MyModel.filter(title__startswith="a")
active_objects = start_with_a.active()
**Note!** Now you can define filter methods in model class
and chain them in queries. Magic!
### Shortcuts ``rango.views``
from rango.views import render_to, ajax_request, render_to_response, \
render, redirect, get_object_or_404, login_required
### Mailing shortcut
If you need to compose E-mail message body from template and
send it you may use a shortcut:
from rango.mail import send_template
send_template(subject='Subject', template='mail.html',
recipient_list=[to@example.com],
context={})
Full method signature:
def send_template(subject=None, template=None, recipient_list=[],
context={}, from_email=None, **kwargs)
### Other shortcuts and stuff
from rango.crypto import random_token
random_token(20) # creates rangom string
# Yes! that's replacement for
# from django.conf import settings
from rango import settings
settings.has_setting('CUSTOM_SETTINGS')
settings.get_setting('CUSTOM_SETTINGS', default='Some value')
from rango.utils import safe_upload_to
from rango import models
class MyFile(models.Model):
file = models.FileField(upload_to=safe_upload_to('files'))
# files will be uploaded to
# files/<instance id>/<random>_<filename>
Documentation
-------------
It's not ready yet, I'm working on it.
If you're brave, watch in the source :)
=====
Rango is a bit of spice for Django.
Why?
----
I beleive that short and plain imports are better than long
nested ones.
In Django you should write in your ``views.py``:
from django.core.urlresolvers import reverse
from django.shortcuts import get_object_or_404, redirect
from django.contrib.auth.decorators import login_required
In Rango:
from rango.urls import reverse
from rango.views import get_object_or_404, login_required
Actually that is experimental project tending to build cleaner
API for Django.
Core features
-------------
### New ``reverse`` method
It works like that:
from rango.urls import reverse
reverse('url_name', pk=8)
Django ``reverse`` works so:
from django.core.urlresolvers import reverse
reverse('url_name', kwargs={'pk': 8})
### Base model class
It has shorcuts for ``all``, ``get``, ``filter`` and ``exclude``
methods and some extra magic:
from rango import models
class MyModel(models.RangoModel):
class MyModel(RangoModel):
title = models.CharField(max_length=100)
is_active = models.BooleanField()
@classmethod
def active(cls, _queryset=None):
return cls.filter(_queryset, is_active=True)
all_objects = MyModel.all()
start_with_a = MyModel.filter(title__startswith="a")
active_objects = start_with_a.active()
**Note!** Now you can define filter methods in model class
and chain them in queries. Magic!
### Shortcuts ``rango.views``
from rango.views import render_to, ajax_request, render_to_response, \
render, redirect, get_object_or_404, login_required
### Mailing shortcut
If you need to compose E-mail message body from template and
send it you may use a shortcut:
from rango.mail import send_template
send_template(subject='Subject', template='mail.html',
recipient_list=[to@example.com],
context={})
Full method signature:
def send_template(subject=None, template=None, recipient_list=[],
context={}, from_email=None, **kwargs)
### Other shortcuts and stuff
from rango.crypto import random_token
random_token(20) # creates rangom string
# Yes! that's replacement for
# from django.conf import settings
from rango import settings
settings.has_setting('CUSTOM_SETTINGS')
settings.get_setting('CUSTOM_SETTINGS', default='Some value')
from rango.utils import safe_upload_to
from rango import models
class MyFile(models.Model):
file = models.FileField(upload_to=safe_upload_to('files'))
# files will be uploaded to
# files/<instance id>/<random>_<filename>
Documentation
-------------
It's not ready yet, I'm working on it.
If you're brave, watch in the source :)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
rango-0.0.2a.tar.gz
(8.8 kB
view details)
File details
Details for the file rango-0.0.2a.tar.gz
.
File metadata
- Download URL: rango-0.0.2a.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31263868e7c28ae68dfae9ac13bf3c4c013f01790a63b6ed09ba22d0fa67ea08 |
|
MD5 | 7a753e4a84fbfc9dda3f267fa1c9a5c3 |
|
BLAKE2b-256 | ce04c88e97784c199d22df3362ff6e2722f35b74830926c7c278c5f448aadcb5 |