|
@@ -15,16 +15,11 @@ from wsgidav.compat import PY3
|
15
|
15
|
from wsgidav.dav_error import DAVError, HTTP_FORBIDDEN
|
16
|
16
|
from wsgidav.dav_provider import DAVCollection, DAVNonCollection
|
17
|
17
|
from tracim.model import data, new_revision
|
18
|
|
-from tracim.model.data import Content, ActionDescription, VirtualEvent
|
|
18
|
+from tracim.model.data import Content, ActionDescription
|
19
|
19
|
from tracim.model.data import ContentType
|
20
|
|
-from wsgidav.dav_provider import DAVResource
|
|
20
|
+from wsgidav.dav_provider import _DAVResource
|
21
|
21
|
|
22
|
|
-_CONTENTS = {
|
23
|
|
- ContentType.Folder: Folder,
|
24
|
|
- ContentType.File: File,
|
25
|
|
- ContentType.Page: OtherFile,
|
26
|
|
- ContentType.Thread: OtherFile
|
27
|
|
-}
|
|
22
|
+from tracim.lib.webdav.design import designThread, designPage
|
28
|
23
|
|
29
|
24
|
class Encapsuler(object):
|
30
|
25
|
def __init__(self, type: str, api: ContentApi, content: Content):
|
|
@@ -40,13 +35,32 @@ class Encapsuler(object):
|
40
|
35
|
|
41
|
36
|
self._type = type
|
42
|
37
|
|
|
38
|
+ self._new_name = self.make_name()
|
|
39
|
+
|
43
|
40
|
def action(self):
|
44
|
41
|
with new_revision(self._content):
|
45
|
42
|
self._actions[self._type](self._content)
|
|
43
|
+
|
|
44
|
+ if self._content.label == '':
|
|
45
|
+ self._content.file_name = self._new_name
|
|
46
|
+ else:
|
|
47
|
+ self._content.label = self._new_name
|
|
48
|
+
|
46
|
49
|
self._api.save(self._content, self._type)
|
47
|
50
|
|
48
|
51
|
transaction.commit()
|
49
|
52
|
|
|
53
|
+ def make_name(self):
|
|
54
|
+ new_name = self._content.get_label()
|
|
55
|
+ is_file_name = self._content.label == ''
|
|
56
|
+ add = ''
|
|
57
|
+
|
|
58
|
+ if self._type in [ActionDescription.ARCHIVING, ActionDescription.DELETION]:
|
|
59
|
+ new_name += ' - %s the %s' % (self._type, datetime.now())
|
|
60
|
+ else:
|
|
61
|
+ pass
|
|
62
|
+
|
|
63
|
+ return new_name
|
50
|
64
|
|
51
|
65
|
class Root(DAVCollection):
|
52
|
66
|
def __init__(self, path: str, environ: dict):
|
|
@@ -69,7 +83,7 @@ class Root(DAVCollection):
|
69
|
83
|
def getMemberNames(self) -> [str]:
|
70
|
84
|
return [workspace.label for workspace in self._workspace_api.get_all()]
|
71
|
85
|
|
72
|
|
- def getMember(self, label: str) -> Workspace:
|
|
86
|
+ def getMember(self, label: str) -> _DAVResource:
|
73
|
87
|
|
74
|
88
|
workspace = self._workspace_api.get_one_by_label(label)
|
75
|
89
|
|
|
@@ -122,7 +136,7 @@ class Workspace(DAVCollection):
|
122
|
136
|
|
123
|
137
|
return retlist
|
124
|
138
|
|
125
|
|
- def getMember(self, content_label: str) -> DAVResource:
|
|
139
|
+ def getMember(self, content_label: str) -> _DAVResource:
|
126
|
140
|
|
127
|
141
|
content = self._content_api.get_one_by_label_and_parent(
|
128
|
142
|
content_label=content_label,
|
|
@@ -130,7 +144,7 @@ class Workspace(DAVCollection):
|
130
|
144
|
)
|
131
|
145
|
|
132
|
146
|
return _CONTENTS[content.type](
|
133
|
|
- path=self.path + content.get_label(),
|
|
147
|
+ path=self.path + '/' + content.get_label(),
|
134
|
148
|
environ=self.environ,
|
135
|
149
|
content=content
|
136
|
150
|
)
|
|
@@ -138,7 +152,7 @@ class Workspace(DAVCollection):
|
138
|
152
|
def createEmptyResource(self, name: str):
|
139
|
153
|
raise DAVError(HTTP_FORBIDDEN)
|
140
|
154
|
|
141
|
|
- def createCollection(self, label: str) -> Folder:
|
|
155
|
+ def createCollection(self, label: str) -> 'Folder':
|
142
|
156
|
|
143
|
157
|
folder = self._content_api.create(
|
144
|
158
|
content_type=ContentType.Folder,
|
|
@@ -158,7 +172,7 @@ class Workspace(DAVCollection):
|
158
|
172
|
|
159
|
173
|
transaction.commit()
|
160
|
174
|
|
161
|
|
- return Folder(self.path + label, self.environ, folder)
|
|
175
|
+ return Folder(self.path + '/' + label, self.environ, folder)
|
162
|
176
|
|
163
|
177
|
def delete(self):
|
164
|
178
|
raise DAVError(HTTP_FORBIDDEN)
|
|
@@ -175,7 +189,7 @@ class Workspace(DAVCollection):
|
175
|
189
|
def setLastModified(self, destpath, timestamp, dryrun):
|
176
|
190
|
return False
|
177
|
191
|
|
178
|
|
- def getMemberList(self) -> [DAVResource]:
|
|
192
|
+ def getMemberList(self) -> [_DAVResource]:
|
179
|
193
|
memberlist = []
|
180
|
194
|
|
181
|
195
|
if self.environ['REQUEST_METHOD'] not in ['MOVE', 'COPY', 'DELETE']:
|
|
@@ -187,26 +201,26 @@ class Workspace(DAVCollection):
|
187
|
201
|
if memberlist != [] and self._file_count > 0:
|
188
|
202
|
memberlist.append(
|
189
|
203
|
HistoryFolder(
|
190
|
|
- path=self.path + ".history",
|
|
204
|
+ path=self.path + '/' + ".history",
|
191
|
205
|
environ=self.environ,
|
192
|
|
- content=self._content,
|
|
206
|
+ content=None,
|
193
|
207
|
type=HistoryType.Standard
|
194
|
208
|
)
|
195
|
209
|
)
|
196
|
210
|
|
197
|
211
|
memberlist.append(
|
198
|
212
|
DeletedFolder(
|
199
|
|
- path=self.path + ".deleted",
|
|
213
|
+ path=self.path + '/' + ".deleted",
|
200
|
214
|
environ=self.environ,
|
201
|
|
- content=self._content
|
|
215
|
+ content=None
|
202
|
216
|
)
|
203
|
217
|
)
|
204
|
218
|
|
205
|
219
|
memberlist.append(
|
206
|
220
|
ArchivedFolder(
|
207
|
|
- path=self.path + ".archived",
|
|
221
|
+ path=self.path + '/' + ".archived",
|
208
|
222
|
environ=self.environ,
|
209
|
|
- content=self._content
|
|
223
|
+ content=None
|
210
|
224
|
)
|
211
|
225
|
)
|
212
|
226
|
|
|
@@ -245,7 +259,7 @@ class Folder(DAVCollection):
|
245
|
259
|
|
246
|
260
|
return retlist
|
247
|
261
|
|
248
|
|
- def getMember(self, content_label: str) -> DAVResource:
|
|
262
|
+ def getMember(self, content_label: str) -> _DAVResource:
|
249
|
263
|
|
250
|
264
|
content = self._api.get_one_by_label_and_parent(
|
251
|
265
|
content_label=content_label,
|
|
@@ -253,7 +267,7 @@ class Folder(DAVCollection):
|
253
|
267
|
)
|
254
|
268
|
|
255
|
269
|
return self.provider.getResourceInst(
|
256
|
|
- path=self.path + content.get_label(),
|
|
270
|
+ path=self.path + '/' + content.get_label(),
|
257
|
271
|
environ=self.environ
|
258
|
272
|
)
|
259
|
273
|
|
|
@@ -265,7 +279,7 @@ class Folder(DAVCollection):
|
265
|
279
|
new_file=True
|
266
|
280
|
)
|
267
|
281
|
|
268
|
|
- def createCollection(self, label: str) -> Folder:
|
|
282
|
+ def createCollection(self, label: str) -> _DAVResource:
|
269
|
283
|
|
270
|
284
|
folder = self._api.create(ContentType.Folder, self._content.workspace, self._content, label)
|
271
|
285
|
|
|
@@ -281,7 +295,7 @@ class Folder(DAVCollection):
|
281
|
295
|
|
282
|
296
|
transaction.commit()
|
283
|
297
|
|
284
|
|
- return Folder(self.path + label, self.environ, folder)
|
|
298
|
+ return Folder(self.path + '/' + label, self.environ, folder)
|
285
|
299
|
|
286
|
300
|
def delete(self):
|
287
|
301
|
Encapsuler(ActionDescription.DELETION, self._api, self._content).action()
|
|
@@ -337,7 +351,7 @@ class Folder(DAVCollection):
|
337
|
351
|
#self.item.updated = datetime.fromtimestamp(timestamp)
|
338
|
352
|
#return True
|
339
|
353
|
|
340
|
|
- def getMemberList(self) -> [DAVResource]:
|
|
354
|
+ def getMemberList(self) -> [_DAVResource]:
|
341
|
355
|
memberlist = []
|
342
|
356
|
|
343
|
357
|
for name in self.getMemberNames():
|
|
@@ -349,7 +363,7 @@ class Folder(DAVCollection):
|
349
|
363
|
if memberlist != [] and self._file_count > 0:
|
350
|
364
|
memberlist.append(
|
351
|
365
|
HistoryFolder(
|
352
|
|
- path=self.path + ".history",
|
|
366
|
+ path=self.path + '/' + ".history",
|
353
|
367
|
environ=self.environ,
|
354
|
368
|
content=self._content,
|
355
|
369
|
type=HistoryType.Standard
|
|
@@ -358,7 +372,7 @@ class Folder(DAVCollection):
|
358
|
372
|
|
359
|
373
|
memberlist.append(
|
360
|
374
|
DeletedFolder(
|
361
|
|
- path=self.path + ".deleted",
|
|
375
|
+ path=self.path + '/' + ".deleted",
|
362
|
376
|
environ=self.environ,
|
363
|
377
|
content=self._content
|
364
|
378
|
)
|
|
@@ -366,7 +380,7 @@ class Folder(DAVCollection):
|
366
|
380
|
|
367
|
381
|
memberlist.append(
|
368
|
382
|
ArchivedFolder(
|
369
|
|
- path=self.path + ".archived",
|
|
383
|
+ path=self.path + '/' + ".archived",
|
370
|
384
|
environ=self.environ,
|
371
|
385
|
content=self._content
|
372
|
386
|
)
|
|
@@ -374,7 +388,6 @@ class Folder(DAVCollection):
|
374
|
388
|
|
375
|
389
|
return memberlist
|
376
|
390
|
|
377
|
|
-
|
378
|
391
|
class HistoryFolder(Folder):
|
379
|
392
|
def __init__(self, path, environ, content: data.Content, type):
|
380
|
393
|
super(HistoryFolder, self).__init__(path, environ, content)
|
|
@@ -399,14 +412,14 @@ class HistoryFolder(Folder):
|
399
|
412
|
def getLastModified(self) -> float:
|
400
|
413
|
return mktime(datetime.now().timetuple())
|
401
|
414
|
|
402
|
|
- def getMember(self, content_label: str) -> HistoryFileFolder:
|
|
415
|
+ def getMember(self, content_label: str) -> _DAVResource:
|
403
|
416
|
content = self._api.get_one_by_label_and_parent(
|
404
|
417
|
content_label=content_label,
|
405
|
418
|
content_parent=self._content
|
406
|
419
|
)
|
407
|
420
|
|
408
|
421
|
return HistoryFileFolder(
|
409
|
|
- path=self.path + content.get_label(),
|
|
422
|
+ path=self.path + '/' + content.get_label(),
|
410
|
423
|
environ=self.environ,
|
411
|
424
|
content=content)
|
412
|
425
|
|
|
@@ -442,7 +455,7 @@ class HistoryFolder(Folder):
|
442
|
455
|
def setLastModified(self, destpath: str, timestamp: float, dryrun: bool):
|
443
|
456
|
return False
|
444
|
457
|
|
445
|
|
- def getMemberList(self) -> [HistoryFileFolder]:
|
|
458
|
+ def getMemberList(self) -> [_DAVResource]:
|
446
|
459
|
memberlist = []
|
447
|
460
|
for name in self.getMemberNames():
|
448
|
461
|
member = self.getMember(name)
|
|
@@ -456,7 +469,7 @@ class DeletedFolder(HistoryFolder):
|
456
|
469
|
super(DeletedFolder, self).__init__(path, environ, content, HistoryType.Deleted)
|
457
|
470
|
|
458
|
471
|
self._api = ContentApi(
|
459
|
|
- current_user=self._user,
|
|
472
|
+ current_user=environ['user'],
|
460
|
473
|
show_deleted=True
|
461
|
474
|
)
|
462
|
475
|
|
|
@@ -474,7 +487,7 @@ class DeletedFolder(HistoryFolder):
|
474
|
487
|
def getLastModified(self) -> float:
|
475
|
488
|
return mktime(datetime.now().timetuple())
|
476
|
489
|
|
477
|
|
- def getMember(self, content_label) -> DAVResource:
|
|
490
|
+ def getMember(self, content_label) -> _DAVResource:
|
478
|
491
|
|
479
|
492
|
content = self._api.get_one_by_label_and_parent(
|
480
|
493
|
content_label=content_label,
|
|
@@ -482,7 +495,7 @@ class DeletedFolder(HistoryFolder):
|
482
|
495
|
)
|
483
|
496
|
|
484
|
497
|
return self.provider.getResourceInst(
|
485
|
|
- path=self.path + content.get_label(),
|
|
498
|
+ path=self.path + '/' + content.get_label(),
|
486
|
499
|
environ=self.environ
|
487
|
500
|
)
|
488
|
501
|
|
|
@@ -519,7 +532,7 @@ class DeletedFolder(HistoryFolder):
|
519
|
532
|
def setLastModified(self, destpath: str, timestamp: float, dryrun: bool):
|
520
|
533
|
return False
|
521
|
534
|
|
522
|
|
- def getMemberList(self) -> [DAVResource]:
|
|
535
|
+ def getMemberList(self) -> [_DAVResource]:
|
523
|
536
|
memberlist = []
|
524
|
537
|
|
525
|
538
|
if self.environ['REQUEST_METHOD'] not in ['MOVE', 'COPY', 'DELETE']:
|
|
@@ -532,7 +545,7 @@ class DeletedFolder(HistoryFolder):
|
532
|
545
|
if self._file_count > 0:
|
533
|
546
|
memberlist.append(
|
534
|
547
|
HistoryFolder(
|
535
|
|
- path=self.path + ".history",
|
|
548
|
+ path=self.path + '/' + ".history",
|
536
|
549
|
environ=self.environ,
|
537
|
550
|
content=self._content,
|
538
|
551
|
type=HistoryType.Deleted
|
|
@@ -565,7 +578,7 @@ class ArchivedFolder(HistoryFolder):
|
565
|
578
|
def getLastModified(self) -> float:
|
566
|
579
|
return mktime(datetime.now().timetuple())
|
567
|
580
|
|
568
|
|
- def getMember(self, content_label) -> DAVResource:
|
|
581
|
+ def getMember(self, content_label) -> _DAVResource:
|
569
|
582
|
|
570
|
583
|
content = self._api.get_one_by_label_and_parent(
|
571
|
584
|
content_label=content_label,
|
|
@@ -573,7 +586,7 @@ class ArchivedFolder(HistoryFolder):
|
573
|
586
|
)
|
574
|
587
|
|
575
|
588
|
return self.provider.getResourceInst(
|
576
|
|
- path=self.path + content.get_label(),
|
|
589
|
+ path=self.path + '/' + content.get_label(),
|
577
|
590
|
environ=self.environ
|
578
|
591
|
)
|
579
|
592
|
|
|
@@ -610,7 +623,7 @@ class ArchivedFolder(HistoryFolder):
|
610
|
623
|
def setLastModified(self, destpath: str, timestamp: float, dryrun: bool):
|
611
|
624
|
return False
|
612
|
625
|
|
613
|
|
- def getMemberList(self) -> [DAVResource]:
|
|
626
|
+ def getMemberList(self) -> [_DAVResource]:
|
614
|
627
|
memberlist = []
|
615
|
628
|
|
616
|
629
|
if self.environ['REQUEST_METHOD'] not in ['MOVE', 'COPY', 'DELETE']:
|
|
@@ -622,7 +635,7 @@ class ArchivedFolder(HistoryFolder):
|
622
|
635
|
if self._file_count > 0:
|
623
|
636
|
memberlist.append(
|
624
|
637
|
HistoryFolder(
|
625
|
|
- path=self.path + ".history",
|
|
638
|
+ path=self.path + '/' + ".history",
|
626
|
639
|
environ=self.environ,
|
627
|
640
|
content=self._content,
|
628
|
641
|
type=HistoryType.Archived
|
|
@@ -663,13 +676,13 @@ class HistoryFileFolder(HistoryFolder):
|
663
|
676
|
|
664
|
677
|
if self._content.type == ContentType.File:
|
665
|
678
|
return HistoryFile(
|
666
|
|
- path=self.path + str(rev.revision_id) + '-' + rev.file_name,
|
|
679
|
+ path=self.path + '/' + str(revision.revision_id) + '-' + revision.file_name,
|
667
|
680
|
environ=self.environ,
|
668
|
681
|
content=self._content,
|
669
|
682
|
content_revision=revision)
|
670
|
683
|
else:
|
671
|
684
|
return HistoryOtherFile(
|
672
|
|
- path=self.path + str(rev.revision_id) + '-' + rev.get_label(),
|
|
685
|
+ path=self.path + '/' + str(revision.revision_id) + '-' + revision.get_label(),
|
673
|
686
|
environ=self.environ,
|
674
|
687
|
content=self._content,
|
675
|
688
|
content_revision=revision)
|
|
@@ -677,9 +690,21 @@ class HistoryFileFolder(HistoryFolder):
|
677
|
690
|
def delete(self):
|
678
|
691
|
raise DAVError(HTTP_FORBIDDEN)
|
679
|
692
|
|
|
693
|
+ def getMemberList(self) -> [_DAVResource]:
|
|
694
|
+ memberlist = []
|
|
695
|
+
|
|
696
|
+ if self.environ['REQUEST_METHOD'] not in ['MOVE', 'COPY', 'DELETE']:
|
|
697
|
+
|
|
698
|
+ for name in self.getMemberNames():
|
|
699
|
+ member = self.getMember(name)
|
|
700
|
+ if member is not None:
|
|
701
|
+ memberlist.append(member)
|
|
702
|
+
|
|
703
|
+ return memberlist
|
|
704
|
+
|
680
|
705
|
|
681
|
706
|
class File(DAVNonCollection):
|
682
|
|
- def __init__(self, path: str, environ: environ, content: Content, is_new_file: bool):
|
|
707
|
+ def __init__(self, path: str, environ: dict, content: Content, is_new_file: bool):
|
683
|
708
|
super(File, self).__init__(path, environ)
|
684
|
709
|
|
685
|
710
|
self._content = content
|
|
@@ -690,10 +715,15 @@ class File(DAVNonCollection):
|
690
|
715
|
show_deleted=True
|
691
|
716
|
)
|
692
|
717
|
|
693
|
|
- self.filestream = MyFileStream(content=self._content, content_api=self._api)
|
|
718
|
+ self.filestream = FileStream(
|
|
719
|
+ content=self._content,
|
|
720
|
+ content_api=self._api,
|
|
721
|
+ file_name=self._content.get_label(),
|
|
722
|
+ new_file=False
|
|
723
|
+ )
|
694
|
724
|
|
695
|
725
|
def __repr__(self) -> str:
|
696
|
|
- return "<DAVNonCollectio: File (%s)>" % self._content.get_label()
|
|
726
|
+ return "<DAVNonCollection: File (%s)>" % self._content.get_label()
|
697
|
727
|
|
698
|
728
|
def getContentLength(self) -> int:
|
699
|
729
|
return len(self._content.file_content)
|
|
@@ -720,14 +750,18 @@ class File(DAVNonCollection):
|
720
|
750
|
|
721
|
751
|
return filestream
|
722
|
752
|
|
723
|
|
- def beginWrite(self, contentType: str=None) -> MyFileStream:
|
|
753
|
+ def beginWrite(self, contentType: str=None) -> FileStream:
|
724
|
754
|
return self.filestream
|
725
|
755
|
|
726
|
756
|
def copyMoveSingle(self, destpath: str, ismove: bool):
|
727
|
757
|
destpath = normpath(destpath)
|
728
|
758
|
|
729
|
759
|
if ismove:
|
730
|
|
- parent = self.provider.get_parent_from_path(normpath(destpath), self._api, WorkspaceApi(self._user))
|
|
760
|
+ parent = self.provider.get_parent_from_path(
|
|
761
|
+ normpath(destpath),
|
|
762
|
+ self._api,
|
|
763
|
+ WorkspaceApi(self.environ['user'])
|
|
764
|
+ )
|
731
|
765
|
|
732
|
766
|
with new_revision(self._content):
|
733
|
767
|
if basename(destpath) != self._content.label:
|
|
@@ -801,7 +835,7 @@ class HistoryFile(File):
|
801
|
835
|
raise DAVError(HTTP_FORBIDDEN)
|
802
|
836
|
|
803
|
837
|
def handleDelete(self):
|
804
|
|
- return True
|
|
838
|
+ return False
|
805
|
839
|
|
806
|
840
|
def handleCopy(self, destPath, depthInfinity):
|
807
|
841
|
return True
|
|
@@ -825,9 +859,9 @@ class OtherFile(File):
|
825
|
859
|
|
826
|
860
|
def getContentLength(self) -> int:
|
827
|
861
|
if self._content.type == ContentType.Page:
|
828
|
|
- return len(self.designPage(self._content))
|
|
862
|
+ return len(designPage(self._content, self._content.revision))
|
829
|
863
|
else:
|
830
|
|
- return len(self.designThread(self._content))
|
|
864
|
+ return len(designThread(self._content, self._content.revision, self._api.get_all(self._content.content_id, ContentType.Comment)))
|
831
|
865
|
|
832
|
866
|
def getContentType(self) -> str:
|
833
|
867
|
return 'text/html'
|
|
@@ -839,232 +873,14 @@ class OtherFile(File):
|
839
|
873
|
filestream = compat.StringIO()
|
840
|
874
|
|
841
|
875
|
if self._content.type == ContentType.Page:
|
842
|
|
- self._content_page = self.designPage(self._content)
|
|
876
|
+ self._content_page = designPage(self._content, self._content.revision)
|
843
|
877
|
else:
|
844
|
|
- self._content_page = self.designThread(self._content)
|
|
878
|
+ self._content_page = designThread(self._content, self._content.revision, self._api.get_all(self._content.content_id, ContentType.Comment))
|
845
|
879
|
|
846
|
880
|
filestream.write(bytes(self._content_page, 'utf-8'))
|
847
|
881
|
filestream.seek(0)
|
848
|
882
|
return filestream
|
849
|
883
|
|
850
|
|
- def designPage(self, content: data.Content) -> str:
|
851
|
|
- #f = open('wsgidav/addons/webdav/style.css', 'r')
|
852
|
|
- style = ''#f.read()
|
853
|
|
- #f.close()
|
854
|
|
-
|
855
|
|
- hist = self._content.get_history()
|
856
|
|
- histHTML = '<table class="table table-striped table-hover">'
|
857
|
|
- for event in hist:
|
858
|
|
- if isinstance(event, VirtualEvent):
|
859
|
|
- date = event.create_readable_date()
|
860
|
|
- _LABELS = {
|
861
|
|
- 'archiving': 'Item archived',
|
862
|
|
- 'content-comment': 'Item commented',
|
863
|
|
- 'creation': 'Item created',
|
864
|
|
- 'deletion': 'Item deleted',
|
865
|
|
- 'edition': 'item modified',
|
866
|
|
- 'revision': 'New revision',
|
867
|
|
- 'status-update': 'New status',
|
868
|
|
- 'unarchiving': 'Item unarchived',
|
869
|
|
- 'undeletion': 'Item undeleted',
|
870
|
|
- 'move': 'Item moved'
|
871
|
|
- }
|
872
|
|
-
|
873
|
|
- label = _LABELS[event.type.id]
|
874
|
|
-
|
875
|
|
- histHTML += '''
|
876
|
|
- <tr class="%s">
|
877
|
|
- <td class="my-align"><span class="label label-default"><i class="fa %s"></i> %s</span></td>
|
878
|
|
- <td>%s</td>
|
879
|
|
- <td>%s</td>
|
880
|
|
- <td>%s</td>
|
881
|
|
- </tr>
|
882
|
|
- ''' % ('warning' if event.id == content.revision_id else '',
|
883
|
|
- event.type.icon,
|
884
|
|
- label,
|
885
|
|
- date,
|
886
|
|
- event.owner.display_name,
|
887
|
|
- '<i class="fa fa-caret-left"></i> shown' if event.id == content.revision_id else '''<span><a class="revision-link" href="/.history/%s/%s-%s">(View revision)</a></span>''' % (self._content.label, event.id, event.ref_object.label) if event.type.id == 'revision' else '')
|
888
|
|
-
|
889
|
|
- histHTML+='</table>'
|
890
|
|
-
|
891
|
|
- file = '''
|
892
|
|
-<html>
|
893
|
|
-<head>
|
894
|
|
- <title>%s</title>
|
895
|
|
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
|
896
|
|
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">
|
897
|
|
- <link rel="stylesheet" href="/home/arnaud/Documents/css/style.css">
|
898
|
|
- <script type="text/javascript" src="/home/arnaud/Documents/css/script.js"></script>
|
899
|
|
-</head>
|
900
|
|
-<body>
|
901
|
|
- <div id="left" class="col-lg-8 col-md-12 col-sm-12 col-xs-12">
|
902
|
|
- <div class="title page">
|
903
|
|
- <div class="title-text">
|
904
|
|
- <i class="fa fa-file-text-o title-icon page"></i>
|
905
|
|
- <h1>%s</h1>
|
906
|
|
- <h6>page created on <b>%s</b> by <b>%s</b></h6>
|
907
|
|
- </div>
|
908
|
|
- <div class="pull-right">
|
909
|
|
- <div class="btn-group btn-group-vertical">
|
910
|
|
- <a class="btn btn-default">
|
911
|
|
- <i class="fa fa-external-link"></i> View in tracim</a>
|
912
|
|
- </a>
|
913
|
|
- </div>
|
914
|
|
- </div>
|
915
|
|
- </div>
|
916
|
|
- <div class="content col-xs-12 col-sm-12 col-md-12 col-lg-12">
|
917
|
|
- %s
|
918
|
|
- </div>
|
919
|
|
- </div>
|
920
|
|
- <div id="right" class="col-lg-4 col-md-12 col-sm-12 col-xs-12">
|
921
|
|
- <h4>History</h4>
|
922
|
|
- %s
|
923
|
|
- </div>
|
924
|
|
- <script type="text/javascript">
|
925
|
|
- window.onload = function() {
|
926
|
|
- elems = document.getElementsByClassName('revision-link');
|
927
|
|
- for(var i = 0; i<elems.length; i++) {
|
928
|
|
- test = window.location.href
|
929
|
|
- test += "/.." + elems[i].href.replace(/file:\/\//, "")
|
930
|
|
- elems[i].href = test
|
931
|
|
- }
|
932
|
|
- }
|
933
|
|
- </script>
|
934
|
|
-</body>
|
935
|
|
-</html>
|
936
|
|
- ''' % (content.label,
|
937
|
|
- content.label,
|
938
|
|
- self._content.created.strftime("%B %d, %Y at %H:%m"),
|
939
|
|
- self._content.owner.display_name,
|
940
|
|
- content.description,
|
941
|
|
- histHTML)
|
942
|
|
-
|
943
|
|
- return file
|
944
|
|
-
|
945
|
|
- def designThread(self, content: data.Content) -> str:
|
946
|
|
-
|
947
|
|
- comments = self._api.get_all(self._content.content_id, ContentType.Comment)
|
948
|
|
- hist = self._content.get_history()
|
949
|
|
-
|
950
|
|
- allT = []
|
951
|
|
- allT += comments
|
952
|
|
- allT += hist
|
953
|
|
- allT.sort(key=lambda x: x.created, reverse=True)
|
954
|
|
-
|
955
|
|
- disc = ''
|
956
|
|
- participants = {}
|
957
|
|
- for t in allT:
|
958
|
|
- if t.type == ContentType.Comment:
|
959
|
|
- disc += '''
|
960
|
|
- <div class="row comment comment-row">
|
961
|
|
- <i class="fa fa-comment-o comment-icon"></i>
|
962
|
|
- <div class="comment-content">
|
963
|
|
- <h5>
|
964
|
|
- <span class="comment-author"><b>%s</b> wrote :</span>
|
965
|
|
- <div class="pull-right text-right">%s</div>
|
966
|
|
- </h5>
|
967
|
|
- %s
|
968
|
|
- </div>
|
969
|
|
- </div>
|
970
|
|
- ''' % (t.owner.display_name, t.create_readable_date(), t.description)
|
971
|
|
-
|
972
|
|
- if t.owner.display_name not in participants:
|
973
|
|
- participants[t.owner.display_name] = [1, t.created]
|
974
|
|
- else:
|
975
|
|
- participants[t.owner.display_name][0] += 1
|
976
|
|
- else:
|
977
|
|
- if isinstance(t, VirtualEvent) and t.type.id != 'comment':
|
978
|
|
- _LABELS = {
|
979
|
|
- 'archiving': 'Item archived',
|
980
|
|
- 'content-comment': 'Item commented',
|
981
|
|
- 'creation': 'Item created',
|
982
|
|
- 'deletion': 'Item deleted',
|
983
|
|
- 'edition': 'item modified',
|
984
|
|
- 'revision': 'New revision',
|
985
|
|
- 'status-update': 'New status',
|
986
|
|
- 'unarchiving': 'Item unarchived',
|
987
|
|
- 'undeletion': 'Item undeleted',
|
988
|
|
- 'move': 'Item moved',
|
989
|
|
- 'comment' : 'hmmm'
|
990
|
|
- }
|
991
|
|
-
|
992
|
|
- label = _LABELS[t.type.id]
|
993
|
|
-
|
994
|
|
- disc += '''
|
995
|
|
- <div class="row comment comment-row">
|
996
|
|
- <i class="fa %s comment-icon"></i>
|
997
|
|
- <div class="comment-content">
|
998
|
|
- <h5>
|
999
|
|
- <span class="comment-author"><b>%s</b></span>
|
1000
|
|
- <div class="pull-right text-right">%s</div>
|
1001
|
|
- </h5>
|
1002
|
|
- %s %s
|
1003
|
|
- </div>
|
1004
|
|
- </div>
|
1005
|
|
- ''' % (t.type.icon,
|
1006
|
|
- t.owner.display_name,
|
1007
|
|
- t.create_readable_date(),
|
1008
|
|
- label,
|
1009
|
|
- '''<span><a class="revision-link" href="/.history/%s/%s-%s">(View revision)</a></span>''' % (
|
1010
|
|
- self._content.label,
|
1011
|
|
- t.id,
|
1012
|
|
- t.ref_object.label) if t.type.id == 'revision' else '')
|
1013
|
|
-
|
1014
|
|
- page = '''
|
1015
|
|
-<html>
|
1016
|
|
-<head>
|
1017
|
|
- <title>%s</title>
|
1018
|
|
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
|
1019
|
|
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">
|
1020
|
|
- <link rel="stylesheet" href="/home/arnaud/Documents/css/style.css">
|
1021
|
|
- <script type="text/javascript" src="/home/arnaud/Documents/css/script.js"></script>
|
1022
|
|
-</head>
|
1023
|
|
-<body>
|
1024
|
|
- <div id="left" class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
|
1025
|
|
- <div class="title thread">
|
1026
|
|
- <div class="title-text">
|
1027
|
|
- <i class="fa fa-comments-o title-icon thread"></i>
|
1028
|
|
- <h1>%s</h1>
|
1029
|
|
- <h6>thread created on <b>%s</b> by <b>%s</b></h6>
|
1030
|
|
- </div>
|
1031
|
|
- <div class="pull-right">
|
1032
|
|
- <div class="btn-group btn-group-vertical">
|
1033
|
|
- <a class="btn btn-default">
|
1034
|
|
- <i class="fa fa-external-link"></i> View in tracim</a>
|
1035
|
|
- </a>
|
1036
|
|
- </div>
|
1037
|
|
- </div>
|
1038
|
|
- </div>
|
1039
|
|
- <div class="content col-xs-12 col-sm-12 col-md-12 col-lg-12">
|
1040
|
|
- <div class="description">
|
1041
|
|
- <span class="description-text">%s</span>
|
1042
|
|
- </div>
|
1043
|
|
- %s
|
1044
|
|
- </div>
|
1045
|
|
- </div>
|
1046
|
|
- <script type="text/javascript">
|
1047
|
|
- window.onload = function() {
|
1048
|
|
- elems = document.getElementsByClassName('revision-link');
|
1049
|
|
- for(var i = 0; i<elems.length; i++) {
|
1050
|
|
- test = window.location.href
|
1051
|
|
- test += "/.." + elems[i].href.replace(/file:\/\//, "")
|
1052
|
|
- elems[i].href = test
|
1053
|
|
- }
|
1054
|
|
- }
|
1055
|
|
- </script>
|
1056
|
|
-</body>
|
1057
|
|
-</html>
|
1058
|
|
- ''' % (content.label,
|
1059
|
|
- content.label,
|
1060
|
|
- self._content.created.strftime("%B %d, %Y at %H:%m"),
|
1061
|
|
- self._content.owner.display_name,
|
1062
|
|
- content.description,
|
1063
|
|
- disc)
|
1064
|
|
-
|
1065
|
|
- return page
|
1066
|
|
-
|
1067
|
|
-
|
1068
|
884
|
class HistoryOtherFile(OtherFile):
|
1069
|
885
|
def __init__(self, path: str, environ: dict, content: data.Content, content_revision: data.ContentRevisionRO):
|
1070
|
886
|
super(HistoryOtherFile, self).__init__(path, environ, content)
|
|
@@ -1083,9 +899,9 @@ class HistoryOtherFile(OtherFile):
|
1083
|
899
|
filestream = compat.StringIO()
|
1084
|
900
|
|
1085
|
901
|
if self._content.type == ContentType.Page:
|
1086
|
|
- self._content_page = self.designPage(self._content_revision)
|
|
902
|
+ self._content_page = designPage(self._content, self._content_revision)
|
1087
|
903
|
else:
|
1088
|
|
- self._content_page = self.designThread(self._content_revision)
|
|
904
|
+ self._content_page = designThread(self._content, self._content_revision, self._api.get_all(self._content.content_id, ContentType.Comment))
|
1089
|
905
|
|
1090
|
906
|
filestream.write(bytes(self._content_page, 'utf-8'))
|
1091
|
907
|
filestream.seek(0)
|
|
@@ -1111,3 +927,11 @@ class HistoryOtherFile(OtherFile):
|
1111
|
927
|
|
1112
|
928
|
def copyMoveSingle(self, destpath, ismove):
|
1113
|
929
|
raise DAVError(HTTP_FORBIDDEN)
|
|
930
|
+
|
|
931
|
+
|
|
932
|
+_CONTENTS = {
|
|
933
|
+ ContentType.Folder: Folder,
|
|
934
|
+ ContentType.File: File,
|
|
935
|
+ ContentType.Page: OtherFile,
|
|
936
|
+ ContentType.Thread: OtherFile
|
|
937
|
+}
|