Instalar InSync en Opensuse
Posted on Mon 20 April 2015 in Sistemas • Tagged with django, python
Posted on Mon 20 April 2015 in Sistemas • Tagged with django, python
Posted on Fri 21 November 2014 in Programación • Tagged with python, django
Para obligar que una vista django sea llamada sólo mediante llamamas AJAX.
def ajax_required(f):
"""
AJAX request required decorator
use it in your views:
@ajax_required
def my_view(request):
....
"""
def wrap(request, *args, **kwargs):
if not request.is_ajax():
return HttpResponseBadRequest()
return f(request, *args, **kwargs)
wrap.__doc__ = f.__doc__
wrap.__name__ …Posted on Sat 11 October 2014 in Programación • Tagged with django, python
Los FileField en django necesitan ana función upload_to que determine donde se subirá el fichero.
Yo suelo tener en utils.py una función genérica que los deja en una subcarpeta con el nombre del modelo.
import os
def generic_upload_to(instance, filename):
"""
Generic `upload_to` function for models.FileField and models.ImageField …Posted on Wed 21 May 2014 in Programación • Tagged with django, python
En mis proyectos suelo usar enlaces a elementos relacionados en el change_list del admin.
Tengo esto en utils.py
from django.contrib import admin
from django.contrib.contenttypes.models import ContentType
from django.core import urlresolvers
from django.utils.datastructures import SortedDict
from …Posted on Wed 08 January 2014 in Programación • Tagged with python, django
Lo suelo usar durante el principio de los proyectos.
from django.conf import settings as django_settings
from django.core.exceptions import ImproperlyConfigured
def settings(request):
"""
Adds the settings specified in settings.TEMPLATE_VISIBLE_SETTINGS to
the request context.
"""
new_settings = {}
for attr in django_settings.TEMPLATE_VISIBLE_SETTINGS:
try:
new_settings[attr] = getattr(django_settings, attr)
except AttributeError …