mirror of https://github.com/interlegis/sapl.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.6 KiB
57 lines
1.6 KiB
from functools import wraps
|
|
|
|
from django.apps import apps
|
|
from django.contrib import admin
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
|
def register_all_models_in_admin(module_name):
|
|
appname = module_name.split('.')[0]
|
|
app = apps.get_app_config(appname)
|
|
for model in app.get_models():
|
|
class CustomModelAdmin(admin.ModelAdmin):
|
|
list_display = [f.name for f in model._meta.fields
|
|
if f.name != 'id']
|
|
|
|
if not admin.site.is_registered(model):
|
|
admin.site.register(model, CustomModelAdmin)
|
|
|
|
|
|
def xstr(s):
|
|
return '' if s is None else str(s)
|
|
|
|
|
|
def get_base_url(request):
|
|
# TODO substituir por Site.objects.get_current().domain
|
|
# from django.contrib.sites.models import Site
|
|
|
|
current_domain = request.get_host()
|
|
protocol = 'https' if request.is_secure() else 'http'
|
|
return "{0}://{1}".format(protocol, current_domain)
|
|
|
|
|
|
def create_barcode(value):
|
|
'''
|
|
creates a base64 encoded barcode PNG image
|
|
'''
|
|
from base64 import b64encode
|
|
from reportlab.graphics.barcode import createBarcodeDrawing
|
|
|
|
barcode = createBarcodeDrawing('Code128',
|
|
value=value,
|
|
barWidth=170,
|
|
height=50,
|
|
fontSize=2,
|
|
humanReadable=True)
|
|
data = b64encode(barcode.asString('png'))
|
|
return data.decode('utf-8')
|
|
|
|
|
|
YES_NO_CHOICES = [(True, _('Sim')), (False, _('Não'))]
|
|
|
|
|
|
def listify(function):
|
|
@wraps(function)
|
|
def f(*args, **kwargs):
|
|
return list(function(*args, **kwargs))
|
|
return f
|
|
|