Ejemplo n.º 1
0
def storage_save(self,*args,**kwargs):
    fix_save = True
    if self.pk:
        instance_ref = self.__class__.objects.get(pk=self.pk)
        if instance_ref.file == self.file: 
            # This is a bad way of checking if the file changed...
            fix_save = False
    if fix_save:
        avail_name = get_upload_to(self, self.file.name)
        reopen = not self.file.file.closed
        if reopen:
            file_loc = self.file.file.tell()
        stored = self.file.storage.save(name=avail_name, content=self.file.file)
        self.file = self.file.storage.open(stored)
        if reopen:
            self.file.file.open()
            self.file.file.seek(file_loc)
    super(self.__class__, self).save(*args,**kwargs)
Ejemplo n.º 2
0
def image_for_name(val):
    val = os.path.basename(val)
    ImageModel = get_image_model()
    try:
        return ImageModel.objects.get(title=val)
    except ImageModel.DoesNotExist:
        logger.fatal("Could not find image %s", val)
        raise BootstrapError

    instance = ImageModel()

    file_name = get_upload_to(instance, val)
    image_query = ImageModel.objects.filter(file=file_name)
    if image_query.exists():
        return image_query.get()
    else:
        logger.fatal("Could not find image %s", val)
        raise BootstrapError
    return None
Ejemplo n.º 3
0
def storage_save(self, *args, **kwargs):
    fix_save = True
    if self.pk:
        instance_ref = self.__class__.objects.get(pk=self.pk)
        if instance_ref.file == self.file:
            # This is a bad way of checking if the file changed...
            fix_save = False
    if fix_save:
        avail_name = get_upload_to(self, self.file.name)
        reopen = not self.file.file.closed
        if reopen:
            file_loc = self.file.file.tell()
        stored = self.file.storage.save(name=avail_name,
                                        content=self.file.file)
        self.file = self.file.storage.open(stored)
        if reopen:
            self.file.file.open()
            self.file.file.seek(file_loc)
    super(self.__class__, self).save(*args, **kwargs)
Ejemplo n.º 4
0
def image_for_name(val):
    val = os.path.basename(val)
    ImageModel = get_image_model()
    try:
        return ImageModel.objects.get(title=val)
    except ImageModel.DoesNotExist:
        logger.fatal("Could not find image %s", val)
        raise BootstrapError


    instance = ImageModel()

    file_name = get_upload_to(instance, val)
    image_query = ImageModel.objects.filter(file=file_name)
    if image_query.exists():
        return image_query.get()
    else:
        logger.fatal("Could not find image %s", val)
        raise BootstrapError
    return None
def image(image_filename, format, alt_text):

    Image = get_image_model()
    instance = Image()
    path = get_upload_to(instance, image_filename)
    query = Image.objects.filter(file=path)
    if not query.exists():
        return "<span style='background: red; color: white'>MISSING IMAGE %s</span>" % image_filename
    else:
        image = query.get()
        embed_handler = get_embed_handler("image")
        image_attrs = embed_handler.get_db_attributes(
            {"data-id": image.id, "data-format": format, "data-alt": alt_text}
        )
        image_attrs["embedtype"] = "image"

        embed_attr_str = u""
        for k, v in image_attrs.items():
            embed_attr_str += u' {0}="{1}"'.format(k, v)

        return "<embed{0}/>".format(embed_attr_str)
Ejemplo n.º 6
0
def image(image_filename, format, alt_text):

    Image = get_image_model()
    instance = Image()
    path = get_upload_to(instance, image_filename)
    query = Image.objects.filter(file=path)
    if not query.exists():
        return "<span style='background: red; color: white'>MISSING IMAGE %s</span>" % image_filename
    else:
        image = query.get()
        embed_handler = get_embed_handler('image')
        image_attrs = embed_handler.get_db_attributes({'data-id': image.id,
                                                       'data-format': format,
                                                       'data-alt': alt_text})
        image_attrs['embedtype'] = 'image'

        embed_attr_str = u''
        for k, v in image_attrs.items():
            embed_attr_str += u" {0}=\"{1}\"".format(k, v)

        return "<embed{0}/>".format(embed_attr_str)
 def get_image_record(self, path):
     file_name = get_upload_to(self.image_instance, os.path.basename(path))
     image = self.ImageModel.objects.get(file=file_name)
     return image
 def is_duplicate_name(self, path):
     file_name = get_upload_to(self.image_instance, os.path.basename(path))
     image_query = self.ImageModel.objects.filter(file=file_name)
     return image_query.exists()
Ejemplo n.º 9
0
 def get_image_record(self, path):
     file_name = get_upload_to(self.image_instance, os.path.basename(path))
     image = self.ImageModel.objects.get(file=file_name)
     return image
Ejemplo n.º 10
0
 def is_duplicate_name(self, path):
     file_name = get_upload_to(self.image_instance, os.path.basename(path))
     image_query = self.ImageModel.objects.filter(file=file_name)
     return image_query.exists()