|
@@ -1,12 +1,3 @@
|
1
|
|
-from sqlalchemy import create_engine
|
2
|
|
-from sqlalchemy.ext.declarative import declarative_base
|
3
|
|
-from sqlalchemy.orm import sessionmaker
|
4
|
|
-
|
5
|
|
-Base = declarative_base()
|
6
|
|
-
|
7
|
|
-some_engine = create_engine('postgresql://arnaud:wxc@localhost/template1')
|
8
|
|
-Session = sessionmaker(bind=some_engine)
|
9
|
|
-
|
10
|
1
|
from wsgidav.compat import to_bytes
|
11
|
2
|
|
12
|
3
|
from tracim.lib.content import ContentApi
|
|
@@ -15,15 +6,6 @@ from tracim.model.data import ActionDescription, ContentType, Content
|
15
|
6
|
from wsgidav import util
|
16
|
7
|
|
17
|
8
|
import transaction
|
18
|
|
-Base.metadata.create_all(some_engine)
|
19
|
|
-
|
20
|
|
-role = {
|
21
|
|
- 'NOT_APPLICABLE': 0,
|
22
|
|
- 'READER': 1,
|
23
|
|
- 'CONTRIBUTOR': 2,
|
24
|
|
- 'CONTENT_MANAGER': 4,
|
25
|
|
- 'WORKSPACE_MANAGER': 8
|
26
|
|
-}
|
27
|
9
|
|
28
|
10
|
class HistoryType(object):
|
29
|
11
|
Deleted = 'deleted'
|
|
@@ -31,52 +13,52 @@ class HistoryType(object):
|
31
|
13
|
Standard = 'standard'
|
32
|
14
|
All = 'all'
|
33
|
15
|
|
34
|
|
-# not_applicable : nothing
|
35
|
|
-# reader : can only read everything in designed workspace
|
36
|
|
-# contributor : + create / modify files
|
37
|
|
-# content_manager : + delete files / create directory / delete directory
|
38
|
|
-# workspace_manager : + create workspace / delete workspace
|
39
|
16
|
|
40
|
|
-class MyFileStream(object):
|
41
|
|
- def __init__(self, content: Content, content_api: ContentApi, file_name: str=''):
|
42
|
|
- self.buflist = []
|
|
17
|
+class FileStream(object):
|
|
18
|
+ def __init__(self, file_name: str, content: Content, content_api: ContentApi, new_file: bool):
|
|
19
|
+ self._buffer = []
|
|
20
|
+ self._file_name = file_name if file_name != '' else self._content.file_name
|
43
|
21
|
self._content = content
|
44
|
22
|
self._api = content_api
|
45
|
23
|
|
46
|
|
- self._file_name = file_name if file_name != '' else self._content.file_name
|
47
|
|
-
|
48
|
|
- def write(self, s):
|
49
|
|
- self.buflist.append(s)
|
|
24
|
+ def beginWrite(self, contentType) -> FileStream:
|
|
25
|
+ return self
|
50
|
26
|
|
51
|
|
- def close(self):
|
52
|
|
- tot = to_bytes('')
|
53
|
|
- for buf in self.buflist:
|
54
|
|
- tot += buf
|
|
27
|
+ def endWrite(self, withErrors: bool):
|
|
28
|
+ pass
|
55
|
29
|
|
56
|
|
- with new_revision(self._content):
|
57
|
|
- self._api.update_file_data(self._content, self._file_name, util.guessMimeType(self._content.file_name), tot)
|
58
|
|
- self._api.save(self._content, ActionDescription.EDITION)
|
59
|
|
-
|
60
|
|
- transaction.commit()
|
61
|
|
-
|
62
|
|
-
|
63
|
|
-class MyFileStream2(object):
|
64
|
|
- def __init__(self, file_name: str, content: Content, content_api: ContentApi):
|
65
|
|
- self.buflist = []
|
66
|
|
- self._file_name = file_name
|
67
|
|
- self._content = content
|
68
|
|
- self._api = content_api
|
69
|
|
-
|
70
|
|
- def write(self, s):
|
71
|
|
- self.buflist.append(s)
|
|
30
|
+ def write(self, s: str):
|
|
31
|
+ self._buffer.append(s)
|
72
|
32
|
|
73
|
33
|
def close(self):
|
74
|
|
- tot = to_bytes('')
|
75
|
|
- for buf in self.buflist:
|
76
|
|
- tot += buf
|
77
|
|
-
|
78
|
|
- file = self._api.create(ContentType.File, self._content.workspace, self._content)
|
79
|
|
- self._api.update_file_data(file, self._file_name, util.guessMimeType(self._file_name), tot)
|
80
|
|
- self._api.save(file, ActionDescription.CREATION)
|
|
34
|
+ item_content = b''
|
|
35
|
+
|
|
36
|
+ for part in self._buffer:
|
|
37
|
+ item_content += part
|
|
38
|
+
|
|
39
|
+ if new_file:
|
|
40
|
+ file = self._api.create(
|
|
41
|
+ content_type=ContentType.File,
|
|
42
|
+ workspace=self._content.workspace,
|
|
43
|
+ parent=self._content
|
|
44
|
+ )
|
|
45
|
+
|
|
46
|
+ self._api.update_file_data(
|
|
47
|
+ file,
|
|
48
|
+ self._file_name,
|
|
49
|
+ util.guessMimeType(self._file_name),
|
|
50
|
+ item_content
|
|
51
|
+ )
|
|
52
|
+
|
|
53
|
+ self._api.save(file, ActionDescription.CREATION)
|
|
54
|
+
|
|
55
|
+ else:
|
|
56
|
+ with new_revision(self._content):
|
|
57
|
+ self._api.update_file_data(
|
|
58
|
+ self._content,
|
|
59
|
+ self._file_name,
|
|
60
|
+ util.guessMimeType(self._content.file_name),
|
|
61
|
+ item_content)
|
|
62
|
+ self._api.save(self._content, ActionDescription.EDITION)
|
81
|
63
|
|
82
|
64
|
transaction.commit()
|