# Create your views here. from django.template.response import * from registro.models import * from asignacion.models import * from django.db.models import Q import math def croquis(request, lote_id): datos = CatalogoUbicacion.objects.get(lote=lote_id) datos.total = datos.filas * datos.tarima * datos.espacio return TemplateResponse(request, 'croquis.html', { 'datos': datos, 'filas':range(datos.filas), 'tarimas':range(datos.tarima), 'espacios':range(datos.espacio), 'ubicacion':'active', 'activo':'closed', 'no_activo':'closed', 'asignacion_activo':'closed', 'registro_revision':'closed' }) def pil_image(request): ''' A View that Returns a PNG Image generated using PIL''' datos = CatalogoUbicacion.objects.all().order_by('-id')[0] datos.total = datos.filas * datos.tarima try: estatusRegistro = Estatus.objects.get(nombre ='Revision') except Estatus.DoesNotExist: text = "No se encontro el registro" import Image, ImageDraw size = (1024, 800) # size of the image to create im = Image.new('RGB', size) # create the image draw = ImageDraw.Draw(im) # create a drawing object that is # used to draw on the new image yellow = (0,255,0) text_pos = (1,1) draw.text(text_pos, text, fill=yellow) red = (255,0,0) # color of our text text_pos = (10,10) # top-left position of our text text = "" # text to draw # Now, we'll do the drawing: draw.text(text_pos, text, fill=red) x = 30 #posicion horizontal superior izq y = 30 #posicion vertical superior izq # anacho total de la pagina - 10% / numero de filas base = (1024 - x * 2) / datos.filas altura = (800 - y * 2) / datos.tarima draw.polygon([(x,y), (x+base,y), (x+base,y +altura), (x,x+altura)], fill="white", outline="green") for i in range(datos.filas): for j in range(datos.tarima): draw.polygon([((base*i)+x,(altura*j)+y), ((base*i)+x+base,(altura*j)+y), ((base*i)+x+base,(altura*j)+y +altura), ((base*i)+x,(altura*j)+y+altura)], fill="white", outline="green") from decimal import Decimal text = str(base) + ' ' + str(altura) + ' ' + str( Decimal( math.sqrt(base * altura / 2 / datos.espacio) ) ) draw.text(text_pos, text, fill=red) for k in range(datos.espacio): draw.polygon( [ ((base*i)+x,(altura*j)+y), ((base*i)+x+base,(altura*j)+y), ((base*i)+x+base,(altura*j)+y +altura), ((base*i)+x,(altura*j)+y+altura) ], fill="blue", outline="black") del draw # I'm done drawing so I don't need this anymore # We need an HttpResponse object with the correct mimetype response = HttpResponse(mimetype="image/png") # now, we tell the image to save as a PNG to the # provided file-like object im.save(response, 'PNG') return response # and we're done!