Ejemplo n.º 1
0
 def put(cls, uri, data, content_type, cache=None):
     from pywebdav.lib.errors import DAV_Forbidden
     from pywebdav.lib.utils import get_uriparentpath, get_urifilename
     object_name, object_id = cls._uri2object(get_uriparentpath(uri),
                                              cache=cache)
     if not object_name \
             or object_name == 'ir.attachment' \
             or not object_id:
         raise DAV_Forbidden
     pool = Pool()
     Attachment = pool.get('ir.attachment')
     object_name2, object_id2 = cls._uri2object(uri, cache=cache)
     if not object_id2:
         name = get_urifilename(uri)
         try:
             Attachment.create([{
                 'name':
                 name,
                 'data':
                 data,
                 'resource':
                 '%s,%s' % (object_name, object_id),
             }])
         except Exception:
             raise DAV_Forbidden
     else:
         try:
             Attachment.write(object_id2, {
                 'data': data,
             })
         except Exception:
             raise DAV_Forbidden
     return
Ejemplo n.º 2
0
 def put(cls, uri, data, content_type, cache=None):
     from pywebdav.lib.errors import DAV_Forbidden
     from pywebdav.lib.utils import get_uriparentpath, get_urifilename
     object_name, object_id = cls._uri2object(get_uriparentpath(uri),
             cache=cache)
     if not object_name \
             or object_name == 'ir.attachment' \
             or not object_id:
         raise DAV_Forbidden
     pool = Pool()
     Attachment = pool.get('ir.attachment')
     object_name2, object_id2 = cls._uri2object(uri, cache=cache)
     if not object_id2:
         name = get_urifilename(uri)
         try:
             Attachment.create([{
                         'name': name,
                         'data': data,
                         'resource': '%s,%s' % (object_name, object_id),
                         }])
         except Exception:
             raise DAV_Forbidden
     else:
         try:
             Attachment.write(object_id2, {
                 'data': data,
                 })
         except Exception:
             raise DAV_Forbidden
     return
Ejemplo n.º 3
0
 def get_data(self, uri, range=None):
     dbname, dburi = self._get_dburi(uri)
     if not dbname or (self.exists(uri) and self.is_collection(uri)):
         res = ('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 '
             'Transitional//EN">')
         res += '<html>'
         res += '<head>'
         res += ('<meta http-equiv="Content-Type" content="text/html; '
             'charset=utf-8">')
         res += ('<title>%s - WebDAV - %s</title>'
             % (PACKAGE, dbname or 'root'))
         res += '</head>'
         res += '<body>'
         res += '<h2>Collection: %s</h2>' % (get_urifilename(uri) or '/')
         res += '<ul>'
         if dbname:
             scheme, netloc, path, params, query, fragment = \
                 urlparse.urlparse(uri)
             if path[-1:] != '/':
                 path += '/'
             res += ('<li><a href="%s">..</a></li>'
                 % urlparse.urlunparse((scheme, netloc, path + '..',
                         params, query, fragment)))
         childs = self.get_childs(uri)
         childs.sort()
         for child in childs:
             res += ('<li><a href="%s">%s</a></li>'
                 % (quote_uri(child), get_urifilename(child)))
         res += '</ul>'
         res += '<hr noshade>'
         res += ('<em>Powered by <a href="%s">%s</a> version %s</em>'
             % (quote_uri(WEBSITE), PACKAGE, VERSION))
         res += '</body>'
         res += '</html>'
         return res
     pool = Pool(Transaction().cursor.database_name)
     Collection = pool.get('webdav.collection')
     try:
         res = Collection.get_data(dburi, cache=CACHE)
     except (DAV_Error, DAV_NotFound, DAV_Secret, DAV_Forbidden), exception:
         self._log_exception(exception)
         raise
Ejemplo n.º 4
0
 def get_data(self, uri, range=None):
     dbname, dburi = self._get_dburi(uri)
     if not dbname or (self.exists(uri) and self.is_collection(uri)):
         res = ('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 '
                'Transitional//EN">')
         res += '<html>'
         res += '<head>'
         res += ('<meta http-equiv="Content-Type" content="text/html; '
                 'charset=utf-8">')
         res += '<title>Tryton - WebDAV - %s</title>' % dbname or 'root'
         res += '</head>'
         res += '<body>'
         res += '<h2>Collection: %s</h2>' % (get_urifilename(uri) or '/')
         res += '<ul>'
         if dbname:
             scheme, netloc, path, params, query, fragment = \
                 urlparse.urlparse(uri)
             if path[-1:] != '/':
                 path += '/'
             res += ('<li><a href="%s">..</a></li>' % urlparse.urlunparse(
                 (scheme, netloc, path + '..', params, query, fragment)))
         childs = self.get_childs(uri)
         childs.sort()
         for child in childs:
             res += ('<li><a href="%s">%s</a></li>' %
                     (quote_uri(child), get_urifilename(child)))
         res += '</ul>'
         res += '<hr noshade>'
         res += ('<em>Powered by <a href="http://www.tryton.org/">'
                 'Tryton</a> version %s</em>' % __version__)
         res += '</body>'
         res += '</html>'
         return res
     pool = Pool(Transaction().cursor.database_name)
     Collection = pool.get('webdav.collection')
     try:
         res = Collection.get_data(dburi, cache=CACHE)
     except (DAV_Error, DAV_NotFound, DAV_Secret, DAV_Forbidden), exception:
         self._log_exception(exception)
         raise
Ejemplo n.º 5
0
 def mkcol(cls, uri, cache=None):
     from pywebdav.lib.errors import DAV_Forbidden
     from pywebdav.lib.utils import get_uriparentpath, get_urifilename
     if uri[-1:] == '/':
         uri = uri[:-1]
     object_name, object_id = cls._uri2object(get_uriparentpath(uri),
                                              cache=cache)
     if object_name != 'webdav.collection':
         raise DAV_Forbidden
     name = get_urifilename(uri)
     try:
         cls.create([{
             'name': name,
             'parent': object_id,
         }])
     except Exception:
         raise DAV_Forbidden
     return 201
Ejemplo n.º 6
0
 def mkcol(cls, uri, cache=None):
     from pywebdav.lib.errors import DAV_Forbidden
     from pywebdav.lib.utils import get_uriparentpath, get_urifilename
     if uri[-1:] == '/':
         uri = uri[:-1]
     object_name, object_id = cls._uri2object(get_uriparentpath(uri),
             cache=cache)
     if object_name != 'webdav.collection':
         raise DAV_Forbidden
     name = get_urifilename(uri)
     try:
         cls.create([{
                     'name': name,
                     'parent': object_id,
                     }])
     except Exception:
         raise DAV_Forbidden
     return 201