def _convert_cache(self, kwargs, cache):
        datos_json = json_loads(cache.datos_json)[0]
        cached_fields = datos_json['fields']

        foreign_key_fields = (field for field in self.model._meta.fields
                              if isinstance(field, models.ForeignKey)
                              and cached_fields[field.name])
        cached_fields.update({
            field.name: field.rel.to.objects.get(pk=cached_fields[field.name])
            for field in foreign_key_fields
        })

        date_fields = (field for field in self.model._meta.fields
                       if isinstance(field, models.DateField)
                       and cached_fields[field.name])
        cached_fields.update({
            field.name: self._convert_date(cached_fields[field.name])
            for field in date_fields
        })

        dirpath = custom_models.gen_path_str_from_key_str(
            self._get_pst(cached_fields, 'rif'))

        file_fields = (field for field in self.model._meta.fields if (
            isinstance(field, models.FileField) and cached_fields[field.name]))
        cached_fields.update({
            field.name: path.join(dirpath, cached_fields[field.name])
            for field in file_fields
        })

        return self.model(pk=datos_json['pk'], **cached_fields)
    def _save_files(self):
        dirpath = custom_models.gen_path_str_from_key_str(self._get_pst('rif'))

        for fld in self._meta.fields:
            if isinstance(fld, models.FileField) and getattr(self, fld.name):
                file_field = getattr(self, fld.name)

                if not file_field:
                    continue

                if FILE_REGEX.match(file_field.name):
                    setattr(self, fld.name, path.basename(file_field.name))
                    continue

                newpath = file_field.storage.save(
                    path.join(dirpath, file_field.name),
                    file_field.file,
                )
                setattr(self, fld.name, path.basename(newpath))
Beispiel #3
0
def get_file_path(rif, filename, foldername):
    return path.join(
        custom_models.gen_path_str_from_key_str(rif), foldername,
        normalize_filename(filename.lower(), pass_blank_name=True))
Beispiel #4
0
def get_folio_file_path(instance, filename):
    return path.join(
        custom_models.gen_path_str_from_key_str(
            instance.lsr_fisico.identificador), 'folio',
        normalize_filename(filename.lower()))
Beispiel #5
0
def get_funcionario_signature_file_path(instance, filename):
    return path.join(
        custom_models.gen_path_str_from_key_str(str(instance.fecha_emision)),
        'firmado', normalize_filename(filename.lower()))
Beispiel #6
0
def get_funcionario_file_path(instance, filename):
    return path.join(
        custom_models.gen_path_str_from_key_str(str(instance.fecha_emision)),
        'adjunto_notificacion', normalize_filename(filename.lower()))
Beispiel #7
0
def get_pst_file_path(instance, filename):
    return path.join(
        custom_models.gen_path_str_from_key_str(instance.solicitud.pst.rif),
        'categorizacion', normalize_filename(filename.lower()))
Beispiel #8
0
def get_archivo_file_path(instance, filename):
    return path.join(
        custom_models.gen_path_str_from_key_str(str(instance.emisor.id)),
        'adjunto_notificacion', normalize_filename(filename.lower()))
Beispiel #9
0
def get_comprobante_file_path(instance, filename):
    return path.join(
        custom_models.gen_path_str_from_key_str(
            str(instance.numero_comprobante)), 'comprobante',
        normalize_filename(filename.lower()))