def create_directory(self,
                      parent_directory,
                      name=None,
                      context=None,
                      **kw):
     parent = request.env['ag_dms.directory'].sudo().browse(
         parent_directory)
     uname = file.unique_name(name or _("New Directory"),
                              parent.child_directories.mapped('name'))
     directory = request.env['ag_dms.directory'].with_context(
         context or request.env.context).create({
             'name':
             uname,
             'parent_directory':
             parent_directory
         })
     return {
         'id': "directory_%s" % directory.id,
         'text': directory.name,
         'icon': "fa fa-folder-o",
         'type': "directory",
         'data': {
             'odoo_id': directory.id,
             'odoo_model': "ag_dms.directory",
             'odoo_record': {},
             'name': directory.name,
             'perm_read': directory.permission_read,
             'perm_create': directory.permission_create,
             'perm_write': directory.permission_write,
             'perm_unlink': directory.permission_unlink,
             'parent': "directory_%s" % parent_directory,
         },
         'children': False,
     }
 def _process_message(self, msg_dict, extra_values={}):
     names = self.sudo().files.mapped('name')
     for attachment in msg_dict['attachments']:
         uname = unique_name(attachment.fname, names, escape_suffix=True)
         self.env['ag_dms.file'].sudo().create({
             'content':  base64.b64encode(attachment.content),
             'directory': self.id,
             'name': uname,
         })
         names.append(uname)
Beispiel #3
0
 def copy(self, default=None):
     self.ensure_one()
     default = dict(default or [])
     names = []
     if 'directory' in default:
         model = self.env['ag_dms.directory']
         directory = model.browse(default['directory'])
         names = directory.sudo().files.mapped('name')
     else:
         names = self.sudo().directory.files.mapped('name')
     default.update(
         {'name': file.unique_name(self.name, names, self.extension)})
     self.check_directory_access('create', default, True)
     return super(File, self).copy(default)
 def message_new(self, msg_dict, custom_values=None):
     custom_values = custom_values if custom_values is not None else {}
     parent_directory_id = custom_values.get('parent_directory', None)
     parent_directory = self.sudo().browse(parent_directory_id)
     if not parent_directory_id or not parent_directory.exists():
         raise ValueError("No directory could be found!")
     if parent_directory.alias_process == "files":
         parent_directory._process_message(msg_dict)
         return parent_directory
     names = parent_directory.child_directories.mapped('name')
     subject = slugify(msg_dict.get('subject', _('Alias-Mail-Extraction')), lower=False)
     defaults = dict({'name': unique_name(subject, names, escape_suffix=True)}, **custom_values)
     directory = super(Directory, self).message_new(msg_dict, custom_values=defaults)
     directory._process_message(msg_dict)
     return directory
 def copy(self, default=None):
     self.ensure_one()
     default = dict(default or [])
     names = []
     if 'root_storage' in default:
         storage = self.env['ag_dms.storage'].browse(
             default['root_storage'])
         names = storage.sudo().root_directories.mapped('name')
     elif 'parent_directory' in default:
         parent_directory = self.browse(default['parent_directory'])
         names = parent_directory.sudo().child_directories.mapped('name')
     elif self.is_root_directory:
         names = self.sudo().root_storage.root_directories.mapped('name')
     else:
         names = self.sudo().parent_directory.child_directories.mapped(
             'name')
     default.update({'name': file.unique_name(self.name, names)})
     new = super(Directory, self).copy(default)
     for record in self.files:
         record.copy({'directory': new.id})
     for record in self.child_directories:
         record.copy({'parent_directory': new.id})
     return new