Mercurial > moin > 2.0
annotate MoinMoin/items/__init__.py @ 244:a11656ba1eab
modify views: use flatland also for the file upload form field
author | Thomas Waldmann <tw AT waldmann-edv DOT de> |
---|---|
date | Sun, 29 May 2011 22:53:38 +0200 |
parents | 69c0d9f6981d |
children | 52ca5dc1ab15 |
rev | line source |
---|---|
26
4cd8edde9e94
automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
24
diff
changeset
|
1 # Copyright: 2009 MoinMoin:ThomasWaldmann |
4cd8edde9e94
automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
24
diff
changeset
|
2 # Copyright: 2009 MoinMoin:ReimarBauer |
4cd8edde9e94
automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
24
diff
changeset
|
3 # Copyright: 2009 MoinMoin:ChristopherDenter |
225
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
4 # Copyright: 2008,2009 MoinMoin:BastianBlank |
26
4cd8edde9e94
automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
24
diff
changeset
|
5 # Copyright: 2010 MoinMoin:ValentinJaniaut |
4cd8edde9e94
automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
24
diff
changeset
|
6 # Copyright: 2010 MoinMoin:DiogenesAugusto |
4cd8edde9e94
automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
24
diff
changeset
|
7 # License: GNU GPL v2 (or any later version), see LICENSE.txt for details. |
4cd8edde9e94
automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
24
diff
changeset
|
8 |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
9 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
10 MoinMoin - misc. mimetype items |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
11 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
12 While MoinMoin.storage cares for backend storage of items, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
13 this module cares for more high-level, frontend items, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
14 e.g. showing, editing, etc. of wiki items. |
26
4cd8edde9e94
automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
24
diff
changeset
|
15 """ |
168
7926fa38e797
update TODO, move some TODOs to the code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
157
diff
changeset
|
16 # TODO: split this huge module into multiple ones after code has stabilized |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
17 |
71
efe399a0375b
cleanup some imports, fix pep8 issue
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
67
diff
changeset
|
18 import os, re, time, datetime, base64 |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
19 import tarfile |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
20 import zipfile |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
21 import tempfile |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
22 from StringIO import StringIO |
204
af274db0ed53
items: move duplicated code to function conv_serialize
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
203
diff
changeset
|
23 from array import array |
173
89f50aed143f
move mimetype related code from wikiutil to util.mimetype
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
170
diff
changeset
|
24 |
242
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
25 from flatland import Form, String, Integer, Boolean, Enum |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
26 from flatland.validation import Validator, Present, IsEmail, ValueBetween, URLValidator, Converted |
244
a11656ba1eab
modify views: use flatland also for the file upload form field
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
243
diff
changeset
|
27 from MoinMoin.util.forms import FileStorage |
242
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
28 |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
29 from MoinMoin.security.textcha import TextCha, TextChaizedForm, TextChaValid |
242
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
30 from MoinMoin.signalling import item_modified |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
31 from MoinMoin.util.forms import make_generator |
173
89f50aed143f
move mimetype related code from wikiutil to util.mimetype
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
170
diff
changeset
|
32 from MoinMoin.util.mimetype import MimeType |
203
1d416427b7be
items: do some imports globally
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
202
diff
changeset
|
33 from MoinMoin.util.mime import Type, type_moin_document |
1d416427b7be
items: do some imports globally
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
202
diff
changeset
|
34 from MoinMoin.util.tree import moin_page, html, xlink, docbook |
1d416427b7be
items: do some imports globally
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
202
diff
changeset
|
35 from MoinMoin.util.iri import Iri |
174
e8f61cbd661b
modularize crypto/random stuff, move it to MoinMoin.util.crypto, pw change bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
173
diff
changeset
|
36 from MoinMoin.util.crypto import cache_key |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
37 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
38 try: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
39 import PIL |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
40 from PIL import Image as PILImage |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
41 from PIL.ImageChops import difference as PILdiff |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
42 except ImportError: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
43 PIL = None |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
44 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
45 from MoinMoin import log |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
46 logging = log.getLogger(__name__) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
47 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
48 try: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
49 import json |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
50 except ImportError: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
51 import simplejson as json |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
52 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
53 from flask import current_app as app |
109
e4c332436733
remove flask monkeypatch, use 'from flask import g as flaskg'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
103
diff
changeset
|
54 from flask import g as flaskg |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
55 |
242
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
56 from flask import request, url_for, flash, Response, redirect, abort, escape |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
57 |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
58 from werkzeug import is_resource_modified |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
59 from jinja2 import Markup |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
60 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
61 from MoinMoin.i18n import _, L_, N_ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
62 from MoinMoin.themes import render_template |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
63 from MoinMoin import wikiutil, config, user |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
64 from MoinMoin.util.send_file import send_file |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
65 from MoinMoin.storage.error import NoSuchItemError, NoSuchRevisionError, AccessDeniedError, \ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
66 StorageError |
111
d7eb7bf188ed
simplify revision timestamp handling - just store it into metadata
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
109
diff
changeset
|
67 from MoinMoin.config import UUID, NAME, NAME_OLD, MTIME, REVERTED_TO, ACL, \ |
102
c084c1369078
move metadata name constant defs to MoinMoin.config
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
101
diff
changeset
|
68 IS_SYSITEM, SYSITEM_VERSION, USERGROUP, SOMEDICT, \ |
216
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
69 CONTENTTYPE, SIZE, LANGUAGE, ITEMLINKS, ITEMTRANSCLUSIONS, \ |
102
c084c1369078
move metadata name constant defs to MoinMoin.config
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
101
diff
changeset
|
70 TAGS, ACTION, ADDRESS, HOSTNAME, USERID, EXTRA, COMMENT, \ |
c084c1369078
move metadata name constant defs to MoinMoin.config
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
101
diff
changeset
|
71 HASH_ALGORITHM |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
72 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
73 COLS = 80 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
74 ROWS_DATA = 20 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
75 ROWS_META = 10 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
76 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
77 |
225
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
78 from ..util.registry import RegistryBase |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
79 |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
80 |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
81 class RegistryItem(RegistryBase): |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
82 class Entry(object): |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
83 def __init__(self, factory, content_type, priority): |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
84 self.factory = factory |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
85 self.content_type = content_type |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
86 self.priority = priority |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
87 |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
88 def __call__(self, name, content_type, kw): |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
89 if self.content_type.issupertype(content_type): |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
90 return self.factory(name, content_type, **kw) |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
91 |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
92 def __eq__(self, other): |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
93 if isinstance(other, self.__class__): |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
94 return (self.factory == other.factory and |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
95 self.content_type == other.content_type and |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
96 self.priority == other.priority) |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
97 return NotImplemented |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
98 |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
99 def __lt__(self, other): |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
100 if isinstance(other, self.__class__): |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
101 if self.priority < other.priority: |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
102 return True |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
103 if self.content_type != other.content_type: |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
104 return other.content_type.issupertype(self.content_type) |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
105 return False |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
106 return NotImplemented |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
107 |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
108 def __repr__(self): |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
109 return '<%s: %s, prio %d [%r]>' % (self.__class__.__name__, |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
110 self.content_type, |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
111 self.priority, |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
112 self.factory) |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
113 |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
114 def get(self, name, content_type, **kw): |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
115 for entry in self._entries: |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
116 item = entry(name, content_type, kw) |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
117 if item is not None: |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
118 return item |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
119 |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
120 def register(self, factory, content_type, priority=RegistryBase.PRIORITY_MIDDLE): |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
121 """ |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
122 Register a factory |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
123 |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
124 :param factory: Factory to register. Callable, must return an object. |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
125 """ |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
126 return self._register(self.Entry(factory, content_type, priority)) |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
127 |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
128 |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
129 item_registry = RegistryItem() |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
130 |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
131 |
204
af274db0ed53
items: move duplicated code to function conv_serialize
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
203
diff
changeset
|
132 def conv_serialize(doc, namespaces): |
af274db0ed53
items: move duplicated code to function conv_serialize
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
203
diff
changeset
|
133 out = array('u') |
af274db0ed53
items: move duplicated code to function conv_serialize
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
203
diff
changeset
|
134 flaskg.clock.start('conv_serialize') |
af274db0ed53
items: move duplicated code to function conv_serialize
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
203
diff
changeset
|
135 doc.write(out.fromunicode, namespaces=namespaces, method='xml') |
af274db0ed53
items: move duplicated code to function conv_serialize
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
203
diff
changeset
|
136 out = out.tounicode() |
af274db0ed53
items: move duplicated code to function conv_serialize
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
203
diff
changeset
|
137 flaskg.clock.stop('conv_serialize') |
af274db0ed53
items: move duplicated code to function conv_serialize
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
203
diff
changeset
|
138 return out |
af274db0ed53
items: move duplicated code to function conv_serialize
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
203
diff
changeset
|
139 |
af274db0ed53
items: move duplicated code to function conv_serialize
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
203
diff
changeset
|
140 |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
141 class DummyRev(dict): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
142 """ if we have no stored Revision, we use this dummy """ |
216
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
143 def __init__(self, item, contenttype): |
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
144 self[CONTENTTYPE] = contenttype |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
145 self.item = item |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
146 self.timestamp = 0 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
147 self.revno = None |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
148 def read(self, size=-1): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
149 return '' |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
150 def seek(self, offset, whence=0): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
151 pass |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
152 def tell(self): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
153 return 0 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
154 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
155 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
156 class DummyItem(object): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
157 """ if we have no stored Item, we use this dummy """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
158 def __init__(self, name): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
159 self.name = name |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
160 def list_revisions(self): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
161 return [] # same as an empty Item |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
162 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
163 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
164 class Item(object): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
165 """ Highlevel (not storage) Item """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
166 @classmethod |
225
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
167 def _factory(cls, name=u'', contenttype=None, **kw): |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
168 return cls(name, contenttype=unicode(contenttype), **kw) |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
169 |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
170 @classmethod |
216
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
171 def create(cls, name=u'', contenttype=None, rev_no=None, item=None): |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
172 if rev_no is None: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
173 rev_no = -1 |
216
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
174 if contenttype is None: |
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
175 contenttype = 'application/x-nonexistent' |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
176 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
177 try: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
178 if item is None: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
179 item = flaskg.storage.get_item(name) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
180 else: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
181 name = item.name |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
182 except NoSuchItemError: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
183 logging.debug("No such item: %r" % name) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
184 item = DummyItem(name) |
216
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
185 rev = DummyRev(item, contenttype) |
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
186 logging.debug("Item %r, created dummy revision with contenttype %r" % (name, contenttype)) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
187 else: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
188 logging.debug("Got item: %r" % name) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
189 try: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
190 rev = item.get_revision(rev_no) |
221
faa06b4873dd
more contenttype related changes/fixes, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
216
diff
changeset
|
191 contenttype = 'application/octet-stream' # it exists |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
192 except NoSuchRevisionError: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
193 try: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
194 rev = item.get_revision(-1) # fall back to current revision |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
195 # XXX add some message about invalid revision |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
196 except NoSuchRevisionError: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
197 logging.debug("Item %r has no revisions." % name) |
216
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
198 rev = DummyRev(item, contenttype) |
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
199 logging.debug("Item %r, created dummy revision with contenttype %r" % (name, contenttype)) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
200 logging.debug("Got item %r, revision: %r" % (name, rev_no)) |
221
faa06b4873dd
more contenttype related changes/fixes, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
216
diff
changeset
|
201 contenttype = rev.get(CONTENTTYPE) or contenttype # use contenttype in case our metadata does not provide CONTENTTYPE |
216
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
202 logging.debug("Item %r, got contenttype %r from revision meta" % (name, contenttype)) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
203 logging.debug("Item %r, rev meta dict: %r" % (name, dict(rev))) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
204 |
225
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
205 item = item_registry.get(name, Type(contenttype), rev=rev) |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
206 logging.debug("ItemClass %r handles %r" % (item.__class__, contenttype)) |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
207 return item |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
208 |
216
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
209 def __init__(self, name, rev=None, contenttype=None): |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
210 self.name = name |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
211 self.rev = rev |
216
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
212 self.contenttype = contenttype |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
213 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
214 def get_meta(self): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
215 return self.rev or {} |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
216 meta = property(fget=get_meta) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
217 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
218 def _render_meta(self): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
219 # override this in child classes |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
220 return '' |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
221 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
222 def feed_input_conv(self): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
223 return self.name |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
224 |
197
19e92e1ff286
fix the +dom view, details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
193
diff
changeset
|
225 def internal_representation(self, converters=['smiley']): |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
226 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
227 Return the internal representation of a document using a DOM Tree |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
228 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
229 flaskg.clock.start('conv_in_dom') |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
230 hash_name = HASH_ALGORITHM |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
231 hash_hexdigest = self.rev.get(hash_name) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
232 if hash_hexdigest: |
174
e8f61cbd661b
modularize crypto/random stuff, move it to MoinMoin.util.crypto, pw change bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
173
diff
changeset
|
233 cid = cache_key(usage="internal_representation", |
e8f61cbd661b
modularize crypto/random stuff, move it to MoinMoin.util.crypto, pw change bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
173
diff
changeset
|
234 hash_name=hash_name, |
e8f61cbd661b
modularize crypto/random stuff, move it to MoinMoin.util.crypto, pw change bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
173
diff
changeset
|
235 hash_hexdigest=hash_hexdigest) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
236 doc = app.cache.get(cid) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
237 else: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
238 # likely a non-existing item |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
239 doc = cid = None |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
240 if doc is None: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
241 # We will see if we can perform the conversion: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
242 # FROM_mimetype --> DOM |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
243 # if so we perform the transformation, otherwise we don't |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
244 from MoinMoin.converter import default_registry as reg |
216
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
245 input_conv = reg.get(Type(self.contenttype), type_moin_document) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
246 if not input_conv: |
216
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
247 raise TypeError("We cannot handle the conversion from %s to the DOM tree" % self.contenttype) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
248 smiley_conv = reg.get(type_moin_document, type_moin_document, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
249 icon='smiley') |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
250 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
251 # We can process the conversion |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
252 links = Iri(scheme='wiki', authority='', path='/' + self.name) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
253 input = self.feed_input_conv() |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
254 doc = input_conv(input) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
255 # XXX is the following assuming that the top element of the doc tree |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
256 # is a moin_page.page element? if yes, this is the wrong place to do that |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
257 # as not every doc will have that element (e.g. for images, we just get |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
258 # moin_page.object, for a tar item, we get a moin_page.table): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
259 doc.set(moin_page.page_href, unicode(links)) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
260 for conv in converters: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
261 if conv == 'smiley': |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
262 doc = smiley_conv(doc) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
263 if cid: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
264 app.cache.set(cid, doc) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
265 flaskg.clock.stop('conv_in_dom') |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
266 return doc |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
267 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
268 def _expand_document(self, doc): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
269 from MoinMoin.converter import default_registry as reg |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
270 include_conv = reg.get(type_moin_document, type_moin_document, includes='expandall') |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
271 macro_conv = reg.get(type_moin_document, type_moin_document, macros='expandall') |
67
d43c7fb728e0
Items - Move link converter into output
Bastian Blank <bblank@thinkmo.de>
parents:
38
diff
changeset
|
272 link_conv = reg.get(type_moin_document, type_moin_document, links='extern', |
d43c7fb728e0
Items - Move link converter into output
Bastian Blank <bblank@thinkmo.de>
parents:
38
diff
changeset
|
273 url_root=Iri(request.url_root)) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
274 flaskg.clock.start('conv_include') |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
275 doc = include_conv(doc) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
276 flaskg.clock.stop('conv_include') |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
277 flaskg.clock.start('conv_macro') |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
278 doc = macro_conv(doc) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
279 flaskg.clock.stop('conv_macro') |
67
d43c7fb728e0
Items - Move link converter into output
Bastian Blank <bblank@thinkmo.de>
parents:
38
diff
changeset
|
280 flaskg.clock.start('conv_link') |
d43c7fb728e0
Items - Move link converter into output
Bastian Blank <bblank@thinkmo.de>
parents:
38
diff
changeset
|
281 doc = link_conv(doc) |
d43c7fb728e0
Items - Move link converter into output
Bastian Blank <bblank@thinkmo.de>
parents:
38
diff
changeset
|
282 flaskg.clock.stop('conv_link') |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
283 return doc |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
284 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
285 def _render_data(self): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
286 from MoinMoin.converter import default_registry as reg |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
287 include_conv = reg.get(type_moin_document, type_moin_document, includes='expandall') |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
288 macro_conv = reg.get(type_moin_document, type_moin_document, macros='expandall') |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
289 # TODO: Real output format |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
290 html_conv = reg.get(type_moin_document, Type('application/x-xhtml-moin-page')) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
291 doc = self.internal_representation() |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
292 doc = self._expand_document(doc) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
293 flaskg.clock.start('conv_dom_html') |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
294 doc = html_conv(doc) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
295 flaskg.clock.stop('conv_dom_html') |
204
af274db0ed53
items: move duplicated code to function conv_serialize
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
203
diff
changeset
|
296 return conv_serialize(doc, {html.namespace: ''}) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
297 |
197
19e92e1ff286
fix the +dom view, details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
193
diff
changeset
|
298 def _render_data_xml(self): |
19e92e1ff286
fix the +dom view, details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
193
diff
changeset
|
299 doc = self.internal_representation() |
204
af274db0ed53
items: move duplicated code to function conv_serialize
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
203
diff
changeset
|
300 return conv_serialize(doc, |
af274db0ed53
items: move duplicated code to function conv_serialize
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
203
diff
changeset
|
301 {moin_page.namespace: '', |
af274db0ed53
items: move duplicated code to function conv_serialize
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
203
diff
changeset
|
302 xlink.namespace: 'xlink', |
af274db0ed53
items: move duplicated code to function conv_serialize
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
203
diff
changeset
|
303 html.namespace: 'html', |
af274db0ed53
items: move duplicated code to function conv_serialize
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
203
diff
changeset
|
304 }) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
305 |
202
9ffa82e550ba
highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
197
diff
changeset
|
306 def _render_data_highlight(self): |
9ffa82e550ba
highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
197
diff
changeset
|
307 # override this in child classes |
9ffa82e550ba
highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
197
diff
changeset
|
308 return '' |
9ffa82e550ba
highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
197
diff
changeset
|
309 |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
310 def _do_modify_show_templates(self): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
311 # call this if the item is still empty |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
312 rev_nos = [] |
216
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
313 item_templates = self.get_templates(self.contenttype) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
314 return render_template('modify_show_template_selection.html', |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
315 item_name=self.name, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
316 rev=self.rev, |
216
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
317 contenttype=self.contenttype, |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
318 templates=item_templates, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
319 first_rev_no=rev_nos and rev_nos[0], |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
320 last_rev_no=rev_nos and rev_nos[-1], |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
321 meta_rendered='', |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
322 data_rendered='', |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
323 ) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
324 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
325 def meta_filter(self, meta): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
326 """ kill metadata entries that we set automatically when saving """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
327 kill_keys = [# shall not get copied from old rev to new rev |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
328 SYSITEM_VERSION, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
329 NAME_OLD, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
330 # are automatically implanted when saving |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
331 NAME, |
122
e90768ec963c
cleanup some NAME/UUID stuff
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
111
diff
changeset
|
332 UUID, |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
333 HASH_ALGORITHM, |
103
1d900f3cf7bb
do not put size metadata into metadata editor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
102
diff
changeset
|
334 SIZE, |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
335 COMMENT, |
111
d7eb7bf188ed
simplify revision timestamp handling - just store it into metadata
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
109
diff
changeset
|
336 MTIME, |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
337 ACTION, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
338 ADDRESS, HOSTNAME, USERID, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
339 ] |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
340 for key in kill_keys: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
341 meta.pop(key, None) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
342 return meta |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
343 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
344 def meta_text_to_dict(self, text): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
345 """ convert meta data from a text fragment to a dict """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
346 meta = json.loads(text) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
347 return self.meta_filter(meta) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
348 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
349 def meta_dict_to_text(self, meta, use_filter=True): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
350 """ convert meta data from a dict to a text fragment """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
351 meta = dict(meta) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
352 if use_filter: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
353 meta = self.meta_filter(meta) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
354 return json.dumps(meta, sort_keys=True, indent=2, ensure_ascii=False) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
355 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
356 def get_data(self): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
357 return '' # TODO create a better method for binary stuff |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
358 data = property(fget=get_data) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
359 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
360 def _write_stream(self, content, new_rev, bufsize=8192): |
193
17693a043442
some preparations for jquery.file-upload code, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
174
diff
changeset
|
361 written = 0 |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
362 if hasattr(content, "read"): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
363 while True: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
364 buf = content.read(bufsize) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
365 if not buf: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
366 break |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
367 new_rev.write(buf) |
193
17693a043442
some preparations for jquery.file-upload code, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
174
diff
changeset
|
368 written += len(buf) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
369 elif isinstance(content, str): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
370 new_rev.write(content) |
193
17693a043442
some preparations for jquery.file-upload code, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
174
diff
changeset
|
371 written += len(content) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
372 else: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
373 raise StorageError("unsupported content object: %r" % content) |
193
17693a043442
some preparations for jquery.file-upload code, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
174
diff
changeset
|
374 return written |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
375 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
376 def copy(self, name, comment=u''): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
377 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
378 copy this item to item <name> |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
379 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
380 old_item = self.rev.item |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
381 flaskg.storage.copy_item(old_item, name=name) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
382 current_rev = old_item.get_revision(-1) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
383 # we just create a new revision with almost same meta/data to show up on RC |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
384 self._save(current_rev, current_rev, name=name, action=u'COPY', comment=comment) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
385 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
386 def _rename(self, name, comment, action): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
387 self.rev.item.rename(name) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
388 self._save(self.meta, self.data, name=name, action=action, comment=comment) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
389 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
390 def rename(self, name, comment=u''): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
391 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
392 rename this item to item <name> |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
393 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
394 return self._rename(name, comment, action=u'RENAME') |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
395 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
396 def delete(self, comment=u''): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
397 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
398 delete this item by moving it to the trashbin |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
399 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
400 trash_prefix = u'Trash/' # XXX move to config |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
401 now = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime()) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
402 # make trash name unique by including timestamp: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
403 trashname = u'%s%s (%s UTC)' % (trash_prefix, self.name, now) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
404 return self._rename(trashname, comment, action=u'TRASH') |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
405 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
406 def revert(self): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
407 # called from revert UI/POST |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
408 comment = request.form.get('comment') |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
409 self._save(self.meta, self.data, action=u'REVERT', comment=comment) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
410 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
411 def destroy(self, comment=u'', destroy_item=False): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
412 # called from destroy UI/POST |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
413 if destroy_item: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
414 # destroy complete item with all revisions, metadata, etc. |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
415 self.rev.item.destroy() |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
416 else: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
417 # just destroy this revision |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
418 self.rev.destroy() |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
419 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
420 def modify(self): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
421 # called from modify UI/POST |
236
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
422 meta = data = contenttype_guessed = None |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
423 contenttype_qs = request.values.get('contenttype') |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
424 data_file = request.files.get('data_file') |
236
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
425 if data_file and data_file.filename: # XXX is this the right way to check if there was a file uploaded? |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
426 data = data_file.stream |
236
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
427 # this is likely a guess by the browser, based on the filename |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
428 contenttype_guessed = data_file.content_type # comes from form multipart data |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
429 if data is None: |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
430 # no file upload, try taking stuff from textarea |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
431 data = request.form.get('data_text') |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
432 if data is not None: |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
433 # there was a data_text field with (possibly empty) content |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
434 assert isinstance(data, unicode) # we get unicode from the form |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
435 data = self.data_form_to_internal(data) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
436 data = self.data_internal_to_storage(data) |
236
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
437 # we know it is text and utf-8 - XXX is there a way to get the charset of the form? |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
438 contenttype_guessed = 'text/plain;charset=utf-8' |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
439 # data might be None here, if we have a form with just the data_file field, no file was uploaded |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
440 # and no data_text field. this can happen if just metadata of a non-text item is edited. |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
441 |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
442 meta_text = request.form.get('meta_text') |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
443 if meta_text is not None: |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
444 # there was a meta_text field with (possibly empty) content |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
445 try: |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
446 meta = self.meta_text_to_dict(meta_text) |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
447 except ValueError: |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
448 # XXX maybe rather validate and reject invalid json |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
449 pass |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
450 if meta is None: |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
451 # no form metadata - reuse some stuff from previous metadata? |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
452 meta = {} |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
453 |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
454 if contenttype_qs: |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
455 # we use querystring param to FORCE content type |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
456 meta[CONTENTTYPE] = contenttype_qs |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
457 |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
458 comment = request.form.get('comment') |
236
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
459 return self._save(meta, data, contenttype_guessed=contenttype_guessed, comment=comment) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
460 |
236
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
461 def _save(self, meta, data=None, name=None, action=u'SAVE', contenttype_guessed=None, comment=u''): |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
462 if name is None: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
463 name = self.name |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
464 backend = flaskg.storage |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
465 try: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
466 storage_item = backend.get_item(name) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
467 except NoSuchItemError: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
468 storage_item = backend.create_item(name) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
469 try: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
470 currentrev = storage_item.get_revision(-1) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
471 rev_no = currentrev.revno |
236
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
472 contenttype_current = currentrev.get(CONTENTTYPE) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
473 except NoSuchRevisionError: |
241
f464adcc3a51
fix saving no data if no previous revision exists
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
236
diff
changeset
|
474 currentrev = None |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
475 rev_no = -1 |
236
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
476 contenttype_current = None |
193
17693a043442
some preparations for jquery.file-upload code, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
174
diff
changeset
|
477 new_rev_no = rev_no + 1 |
17693a043442
some preparations for jquery.file-upload code, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
174
diff
changeset
|
478 newrev = storage_item.create_revision(new_rev_no) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
479 for k, v in meta.iteritems(): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
480 # TODO Put metadata into newrev here for now. There should be a safer way |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
481 # of input for this. |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
482 newrev[k] = v |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
483 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
484 # we store the previous (if different) and current item name into revision metadata |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
485 # this is useful for rename history and backends that use item uids internally |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
486 oldname = meta.get(NAME) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
487 if oldname and oldname != name: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
488 newrev[NAME_OLD] = oldname |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
489 newrev[NAME] = name |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
490 |
236
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
491 if data is None: |
241
f464adcc3a51
fix saving no data if no previous revision exists
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
236
diff
changeset
|
492 if currentrev is not None: |
f464adcc3a51
fix saving no data if no previous revision exists
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
236
diff
changeset
|
493 # we don't have (new) data, just copy the old one. |
f464adcc3a51
fix saving no data if no previous revision exists
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
236
diff
changeset
|
494 # a valid usecase of this is to just edit metadata. |
f464adcc3a51
fix saving no data if no previous revision exists
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
236
diff
changeset
|
495 data = currentrev |
f464adcc3a51
fix saving no data if no previous revision exists
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
236
diff
changeset
|
496 else: |
f464adcc3a51
fix saving no data if no previous revision exists
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
236
diff
changeset
|
497 data = '' |
193
17693a043442
some preparations for jquery.file-upload code, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
174
diff
changeset
|
498 size = self._write_stream(data, newrev) |
236
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
499 |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
500 # XXX if meta is from old revision, and user did not give a non-empty |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
501 # XXX comment, re-using the old rev's comment is wrong behaviour: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
502 comment = unicode(comment or meta.get(COMMENT, '')) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
503 if comment: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
504 newrev[COMMENT] = comment |
236
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
505 |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
506 if CONTENTTYPE not in newrev: |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
507 # make sure we have CONTENTTYPE |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
508 newrev[CONTENTTYPE] = unicode(contenttype_current or contenttype_guessed or 'application/octet-stream') |
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
509 |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
510 newrev[ACTION] = unicode(action) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
511 self.before_revision_commit(newrev, data) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
512 storage_item.commit() |
242
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
513 item_modified.send(app._get_current_object(), item_name=name) |
193
17693a043442
some preparations for jquery.file-upload code, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
174
diff
changeset
|
514 return new_rev_no, size |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
515 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
516 def before_revision_commit(self, newrev, data): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
517 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
518 hook that can be used to add more meta data to a revision before |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
519 it is committed. |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
520 |
38
1d8e9b1153d6
docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
26
diff
changeset
|
521 :param newrev: new (still uncommitted) revision - modify as wanted |
1d8e9b1153d6
docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
26
diff
changeset
|
522 :param data: either str or open file (we can avoid having to read/seek |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
523 rev's data with this) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
524 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
525 remote_addr = request.remote_addr |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
526 if remote_addr: |
98
29f2e129dd36
use log_remote_addr / log_reverse_dns_lookups settings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
76
diff
changeset
|
527 if app.cfg.log_remote_addr: |
29f2e129dd36
use log_remote_addr / log_reverse_dns_lookups settings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
76
diff
changeset
|
528 newrev[ADDRESS] = unicode(remote_addr) |
170
1481cbc12553
metadata: only store hostname if we did a successful lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
168
diff
changeset
|
529 hostname = wikiutil.get_hostname(remote_addr) |
1481cbc12553
metadata: only store hostname if we did a successful lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
168
diff
changeset
|
530 if hostname: |
1481cbc12553
metadata: only store hostname if we did a successful lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
168
diff
changeset
|
531 newrev[HOSTNAME] = hostname |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
532 if flaskg.user.valid: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
533 newrev[USERID] = unicode(flaskg.user.id) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
534 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
535 def search_items(self, term=None): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
536 """ search items matching the term or, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
537 if term is None, return all items |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
538 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
539 if term: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
540 backend_items = flaskg.storage.search_items(term) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
541 else: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
542 # special case: we just want all items |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
543 backend_items = flaskg.storage.iteritems() |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
544 for item in backend_items: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
545 yield Item.create(item=item) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
546 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
547 list_items = search_items # just for cosmetics |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
548 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
549 def count_items(self, term=None): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
550 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
551 Return item count for matching items. See search_items() for details. |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
552 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
553 count = 0 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
554 # we intentionally use a loop to avoid creating a list with all item objects: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
555 for item in self.list_items(term): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
556 count += 1 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
557 return count |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
558 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
559 def get_index(self): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
560 """ create an index of sub items of this item """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
561 import re |
76
dab51965d605
import terms module from new location
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
71
diff
changeset
|
562 from MoinMoin.storage.terms import NameRE |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
563 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
564 if self.name: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
565 prefix = self.name + u'/' |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
566 else: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
567 # trick: an item of empty name can be considered as "virtual root item", |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
568 # that has all wiki items as sub items |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
569 prefix = u'' |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
570 sub_item_re = u"^%s.*" % re.escape(prefix) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
571 regex = re.compile(sub_item_re, re.UNICODE) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
572 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
573 item_iterator = self.search_items(NameRE(regex)) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
574 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
575 # We only want the sub-item part of the item names, not the whole item objects. |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
576 prefix_len = len(prefix) |
216
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
577 items = [(item.name, item.name[prefix_len:], item.meta.get(CONTENTTYPE)) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
578 for item in item_iterator] |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
579 return sorted(items) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
580 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
581 def flat_index(self): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
582 index = self.get_index() |
216
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
583 index = [(fullname, relname, contenttype) |
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
584 for fullname, relname, contenttype in index |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
585 if u'/' not in relname] |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
586 return index |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
587 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
588 index_template = 'index.html' |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
589 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
590 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
591 class NonExistent(Item): |
216
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
592 contenttype_groups = [ |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
593 ('markup text items', [ |
221
faa06b4873dd
more contenttype related changes/fixes, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
216
diff
changeset
|
594 ('text/x.moin.wiki;charset=utf-8', 'Wiki (MoinMoin)'), |
faa06b4873dd
more contenttype related changes/fixes, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
216
diff
changeset
|
595 ('text/x.moin.creole;charset=utf-8', 'Wiki (Creole)'), |
faa06b4873dd
more contenttype related changes/fixes, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
216
diff
changeset
|
596 ('text/x-mediawiki;charset=utf-8', 'Wiki (MediaWiki)'), |
faa06b4873dd
more contenttype related changes/fixes, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
216
diff
changeset
|
597 ('text/x-rst;charset=utf-8', 'ReST'), |
faa06b4873dd
more contenttype related changes/fixes, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
216
diff
changeset
|
598 ('application/docbook+xml;charset=utf-8', 'DocBook'), |
faa06b4873dd
more contenttype related changes/fixes, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
216
diff
changeset
|
599 ('text/html;charset=utf-8', 'HTML'), |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
600 ]), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
601 ('other text items', [ |
221
faa06b4873dd
more contenttype related changes/fixes, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
216
diff
changeset
|
602 ('text/plain;charset=utf-8', 'plain text'), |
faa06b4873dd
more contenttype related changes/fixes, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
216
diff
changeset
|
603 ('text/x-diff;charset=utf-8', 'diff/patch'), |
faa06b4873dd
more contenttype related changes/fixes, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
216
diff
changeset
|
604 ('text/x-python;charset=utf-8', 'python code'), |
faa06b4873dd
more contenttype related changes/fixes, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
216
diff
changeset
|
605 ('text/csv;charset=utf-8', 'csv'), |
faa06b4873dd
more contenttype related changes/fixes, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
216
diff
changeset
|
606 ('text/x-irclog;charset=utf-8', 'IRC log'), |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
607 ]), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
608 ('image items', [ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
609 ('image/jpeg', 'JPEG'), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
610 ('image/png', 'PNG'), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
611 ('image/svg+xml', 'SVG'), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
612 ]), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
613 ('audio items', [ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
614 ('audio/wave', 'WAV'), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
615 ('audio/ogg', 'OGG'), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
616 ('audio/mpeg', 'MP3'), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
617 ('audio/webm', 'WebM'), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
618 ]), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
619 ('video items', [ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
620 ('video/ogg', 'OGG'), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
621 ('video/webm', 'WebM'), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
622 ('video/mp4', 'MP4'), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
623 ]), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
624 ('drawing items', [ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
625 ('application/x-twikidraw', 'TDRAW'), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
626 ('application/x-anywikidraw', 'ADRAW'), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
627 ('application/x-svgdraw', 'SVGDRAW'), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
628 ]), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
629 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
630 ('other items', [ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
631 ('application/pdf', 'PDF'), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
632 ('application/zip', 'ZIP'), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
633 ('application/x-tar', 'TAR'), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
634 ('application/x-gtar', 'TGZ'), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
635 ('application/octet-stream', 'binary file'), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
636 ]), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
637 ] |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
638 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
639 def do_get(self): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
640 abort(404) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
641 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
642 def _convert(self): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
643 abort(404) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
644 |
242
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
645 def do_modify(self, contenttype, template_name): |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
646 # XXX think about and add item template support |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
647 return render_template('modify_show_type_selection.html', |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
648 item_name=self.name, |
216
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
649 contenttype_groups=self.contenttype_groups, |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
650 ) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
651 |
225
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
652 item_registry.register(NonExistent._factory, Type('application/x-nonexistent')) |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
653 |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
654 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
655 class Binary(Item): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
656 """ An arbitrary binary item, fallback class for every item mimetype. """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
657 modify_help = """\ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
658 There is no help, you're doomed! |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
659 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
660 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
661 template = "modify_binary.html" |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
662 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
663 # XXX reads item rev data into memory! |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
664 def get_data(self): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
665 if self.rev is not None: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
666 return self.rev.read() |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
667 else: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
668 return '' |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
669 data = property(fget=get_data) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
670 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
671 def _render_meta(self): |
17
41e2918dcafd
escape metadata to avoid XSS / html / js injection via item_name, comment or other user-settable metadata (should fix #3 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
0
diff
changeset
|
672 return "<pre>%s</pre>" % escape(self.meta_dict_to_text(self.meta, use_filter=False)) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
673 |
216
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
674 def get_templates(self, contenttype=None): |
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
675 """ create a list of templates (for some specific contenttype) """ |
76
dab51965d605
import terms module from new location
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
71
diff
changeset
|
676 from MoinMoin.storage.terms import AND, LastRevisionMetaDataMatch |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
677 term = LastRevisionMetaDataMatch(TAGS, ['template']) # XXX there might be other tags |
216
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
678 if contenttype: |
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
679 term = AND(term, LastRevisionMetaDataMatch(CONTENTTYPE, contenttype)) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
680 item_iterator = self.search_items(term) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
681 items = [item.name for item in item_iterator] |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
682 return sorted(items) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
683 |
242
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
684 def do_modify(self, contenttype, template_name): |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
685 # XXX think about and add item template support |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
686 #if template_name is None and isinstance(self.rev, DummyRev): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
687 # return self._do_modify_show_templates() |
242
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
688 from MoinMoin.apps.frontend.views import CommentForm |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
689 class ModifyForm(CommentForm): |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
690 rev = Integer.using(optional=False) |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
691 meta_text = String.using(optional=False).with_properties(placeholder=L_("MetaData (JSON)")) |
244
a11656ba1eab
modify views: use flatland also for the file upload form field
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
243
diff
changeset
|
692 data_file = FileStorage.using(optional=True, label=L_('Upload file:')) |
242
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
693 |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
694 if request.method == 'GET': |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
695 form = ModifyForm.from_defaults() |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
696 TextCha(form).amend_form() |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
697 form['meta_text'] = self.meta_dict_to_text(self.meta) |
243
69c0d9f6981d
modify: put real base rev no into the hidden form field
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
242
diff
changeset
|
698 form['rev'] = self.rev.revno if self.rev.revno is not None else -1 |
242
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
699 elif request.method == 'POST': |
244
a11656ba1eab
modify views: use flatland also for the file upload form field
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
243
diff
changeset
|
700 form = ModifyForm.from_flat(request.form.items() + request.files.items()) |
242
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
701 TextCha(form).amend_form() |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
702 valid = form.validate() |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
703 if valid: |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
704 try: |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
705 self.modify() # XXX |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
706 except AccessDeniedError: |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
707 abort(403) |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
708 else: |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
709 return redirect(url_for('frontend.show_item', item_name=self.name)) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
710 return render_template(self.template, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
711 item_name=self.name, |
242
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
712 rows_meta=str(ROWS_META), cols=str(COLS), |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
713 help=self.modify_help, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
714 form=form, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
715 gen=make_generator(), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
716 ) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
717 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
718 copy_template = 'copy.html' |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
719 delete_template = 'delete.html' |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
720 destroy_template = 'destroy.html' |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
721 diff_template = 'diff.html' |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
722 rename_template = 'rename.html' |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
723 revert_template = 'revert.html' |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
724 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
725 def _render_data_diff(self, oldrev, newrev): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
726 hash_name = HASH_ALGORITHM |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
727 if oldrev[hash_name] == newrev[hash_name]: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
728 return _("The items have the same data hash code (that means they very likely have the same data).") |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
729 else: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
730 return _("The items have different data.") |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
731 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
732 _render_data_diff_text = _render_data_diff |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
733 _render_data_diff_raw = _render_data_diff |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
734 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
735 def _convert(self): |
216
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
736 return _("Impossible to convert the data to the contenttype: %(contenttype)s", |
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
737 contenttype=request.values.get('contenttype')) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
738 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
739 def do_get(self): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
740 hash = self.rev.get(HASH_ALGORITHM) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
741 if is_resource_modified(request.environ, hash): # use hash as etag |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
742 return self._do_get_modified(hash) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
743 else: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
744 return Response(status=304) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
745 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
746 def _do_get_modified(self, hash): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
747 member = request.values.get('member') |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
748 return self._do_get(hash, member) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
749 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
750 def _do_get(self, hash, member=None): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
751 filename = None |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
752 if member: # content = file contained within a archive item revision |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
753 path, filename = os.path.split(member) |
173
89f50aed143f
move mimetype related code from wikiutil to util.mimetype
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
170
diff
changeset
|
754 mt = MimeType(filename=filename) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
755 content_disposition = mt.content_disposition(app.cfg) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
756 content_type = mt.content_type() |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
757 content_length = None |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
758 file_to_send = self.get_member(member) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
759 else: # content = item revision |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
760 rev = self.rev |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
761 try: |
216
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
762 mimestr = rev[CONTENTTYPE] |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
763 except KeyError: |
221
faa06b4873dd
more contenttype related changes/fixes, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
216
diff
changeset
|
764 mt = MimeType(filename=rev.item.name) |
faa06b4873dd
more contenttype related changes/fixes, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
216
diff
changeset
|
765 else: |
faa06b4873dd
more contenttype related changes/fixes, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
216
diff
changeset
|
766 mt = MimeType(mimestr=mimestr) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
767 content_disposition = mt.content_disposition(app.cfg) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
768 content_type = mt.content_type() |
101
856945a6d936
simplify revision data size handling - just store it into metadata
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
98
diff
changeset
|
769 content_length = rev[SIZE] |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
770 file_to_send = rev |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
771 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
772 # TODO: handle content_disposition is not None |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
773 # Important: empty filename keeps flask from trying to autodetect filename, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
774 # as this would not work for us, because our file's are not necessarily fs files. |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
775 return send_file(file=file_to_send, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
776 mimetype=content_type, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
777 as_attachment=False, attachment_filename=filename, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
778 cache_timeout=10, # wiki data can change rapidly |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
779 add_etags=True, etag=hash, conditional=True) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
780 |
225
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
781 item_registry.register(Binary._factory, Type('*/*')) |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
782 |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
783 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
784 class RenderableBinary(Binary): |
225
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
785 """ Base class for some binary stuff that renders with a object tag. """ |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
786 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
787 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
788 class Application(Binary): |
225
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
789 """ Base class for application/* """ |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
790 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
791 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
792 class TarMixin(object): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
793 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
794 TarMixin offers additional functionality for tar-like items to list and |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
795 access member files and to create new revisions by multiple posts. |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
796 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
797 def list_members(self): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
798 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
799 list tar file contents (member file names) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
800 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
801 self.rev.seek(0) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
802 tf = tarfile.open(fileobj=self.rev, mode='r') |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
803 return tf.getnames() |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
804 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
805 def get_member(self, name): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
806 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
807 return a file-like object with the member file data |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
808 |
38
1d8e9b1153d6
docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
26
diff
changeset
|
809 :param name: name of the data in the container file |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
810 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
811 self.rev.seek(0) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
812 tf = tarfile.open(fileobj=self.rev, mode='r') |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
813 return tf.extractfile(name) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
814 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
815 def put_member(self, name, content, content_length, expected_members): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
816 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
817 puts a new member file into a temporary tar container. |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
818 If all expected members have been put, it saves the tar container |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
819 to a new item revision. |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
820 |
38
1d8e9b1153d6
docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
26
diff
changeset
|
821 :param name: name of the data in the container file |
1d8e9b1153d6
docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
26
diff
changeset
|
822 :param content: the data to store into the tar file (str or file-like) |
1d8e9b1153d6
docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
26
diff
changeset
|
823 :param content_length: byte-length of content (for str, None can be given) |
1d8e9b1153d6
docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
26
diff
changeset
|
824 :param expected_members: set of expected member file names |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
825 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
826 if not name in expected_members: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
827 raise StorageError("tried to add unexpected member %r to container item %r" % (name, self.name)) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
828 if isinstance(name, unicode): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
829 name = name.encode('utf-8') |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
830 temp_fname = os.path.join(tempfile.gettempdir(), 'TarContainer_' + |
174
e8f61cbd661b
modularize crypto/random stuff, move it to MoinMoin.util.crypto, pw change bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
173
diff
changeset
|
831 cache_key(usage='TarContainer', name=self.name)) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
832 tf = tarfile.TarFile(temp_fname, mode='a') |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
833 ti = tarfile.TarInfo(name) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
834 if isinstance(content, str): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
835 if content_length is None: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
836 content_length = len(content) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
837 content = StringIO(content) # we need a file obj |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
838 elif not hasattr(content, 'read'): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
839 logging.error("unsupported content object: %r" % content) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
840 raise StorageError("unsupported content object: %r" % content) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
841 assert content_length >= 0 # we don't want -1 interpreted as 4G-1 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
842 ti.size = content_length |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
843 tf.addfile(ti, content) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
844 tf_members = set(tf.getnames()) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
845 tf.close() |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
846 if tf_members - expected_members: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
847 msg = "found unexpected members in container item %r" % self.name |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
848 logging.error(msg) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
849 os.remove(temp_fname) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
850 raise StorageError(msg) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
851 if tf_members == expected_members: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
852 # everything we expected has been added to the tar file, save the container as revision |
216
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
853 meta = {CONTENTTYPE: self.contenttype} |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
854 data = open(temp_fname, 'rb') |
236
7a77ae08161e
items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
225
diff
changeset
|
855 self._save(meta, data, name=self.name, action=u'SAVE', comment='') |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
856 data.close() |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
857 os.remove(temp_fname) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
858 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
859 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
860 class ApplicationXTar(TarMixin, Application): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
861 def feed_input_conv(self): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
862 return self.rev |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
863 |
225
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
864 item_registry.register(ApplicationXTar._factory, Type('application/x-tar')) |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
865 item_registry.register(ApplicationXTar._factory, Type('application/x-gtar')) |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
866 |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
867 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
868 class ZipMixin(object): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
869 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
870 ZipMixin offers additional functionality for zip-like items to list and |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
871 access member files. |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
872 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
873 def list_members(self): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
874 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
875 list zip file contents (member file names) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
876 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
877 self.rev.seek(0) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
878 zf = zipfile.ZipFile(self.rev, mode='r') |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
879 return zf.namelist() |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
880 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
881 def get_member(self, name): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
882 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
883 return a file-like object with the member file data |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
884 |
38
1d8e9b1153d6
docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
26
diff
changeset
|
885 :param name: name of the data in the zip file |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
886 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
887 self.rev.seek(0) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
888 zf = zipfile.ZipFile(self.rev, mode='r') |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
889 return zf.open(name, mode='r') |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
890 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
891 def put_member(self, name, content, content_length, expected_members): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
892 raise NotImplementedError |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
893 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
894 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
895 class ApplicationZip(ZipMixin, Application): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
896 def feed_input_conv(self): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
897 return self.rev |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
898 |
225
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
899 item_registry.register(ApplicationZip._factory, Type('application/zip')) |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
900 |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
901 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
902 class PDF(Application): |
225
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
903 """ PDF """ |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
904 |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
905 item_registry.register(PDF._factory, Type('application/pdf')) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
906 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
907 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
908 class Video(Binary): |
225
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
909 """ Base class for video/* """ |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
910 |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
911 item_registry.register(Video._factory, Type('video/*')) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
912 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
913 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
914 class Audio(Binary): |
225
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
915 """ Base class for audio/* """ |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
916 |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
917 item_registry.register(Audio._factory, Type('audio/*')) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
918 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
919 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
920 class Image(Binary): |
225
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
921 """ Base class for image/* """ |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
922 |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
923 item_registry.register(Image._factory, Type('image/*')) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
924 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
925 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
926 class RenderableImage(RenderableBinary): |
225
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
927 """ Base class for renderable Image mimetypes """ |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
928 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
929 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
930 class SvgImage(RenderableImage): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
931 """ SVG images use <object> tag mechanism from RenderableBinary base class """ |
225
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
932 |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
933 item_registry.register(SvgImage._factory, Type('image/svg+xml')) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
934 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
935 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
936 class RenderableBitmapImage(RenderableImage): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
937 """ PNG/JPEG/GIF images use <img> tag (better browser support than <object>) """ |
225
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
938 # if mimetype is also transformable, please register in TransformableImage ONLY! |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
939 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
940 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
941 class TransformableBitmapImage(RenderableBitmapImage): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
942 """ We can transform (resize, rotate, mirror) some image types """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
943 def _transform(self, content_type, size=None, transpose_op=None): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
944 """ resize to new size (optional), transpose according to exif infos, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
945 result data should be content_type. |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
946 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
947 try: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
948 from PIL import Image as PILImage |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
949 except ImportError: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
950 # no PIL, we can't do anything, we just output the revision data as is |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
951 return content_type, self.rev.read() |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
952 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
953 if content_type == 'image/jpeg': |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
954 output_type = 'JPEG' |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
955 elif content_type == 'image/png': |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
956 output_type = 'PNG' |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
957 elif content_type == 'image/gif': |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
958 output_type = 'GIF' |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
959 else: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
960 raise ValueError("content_type %r not supported" % content_type) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
961 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
962 # revision obj has read() seek() tell(), thus this works: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
963 image = PILImage.open(self.rev) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
964 image.load() |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
965 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
966 try: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
967 # if we have EXIF data, we can transpose (e.g. rotate left), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
968 # so the rendered image is correctly oriented: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
969 transpose_op = transpose_op or 1 # or self.exif['Orientation'] |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
970 except KeyError: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
971 transpose_op = 1 # no change |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
972 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
973 if size is not None: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
974 image = image.copy() # create copy first as thumbnail works in-place |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
975 image.thumbnail(size, PILImage.ANTIALIAS) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
976 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
977 transpose_func = { |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
978 1: lambda image: image, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
979 2: lambda image: image.transpose(PILImage.FLIP_LEFT_RIGHT), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
980 3: lambda image: image.transpose(PILImage.ROTATE_180), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
981 4: lambda image: image.transpose(PILImage.FLIP_TOP_BOTTOM), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
982 5: lambda image: image.transpose(PILImage.ROTATE_90).transpose(PILImage.FLIP_TOP_BOTTOM), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
983 6: lambda image: image.transpose(PILImage.ROTATE_270), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
984 7: lambda image: image.transpose(PILImage.ROTATE_90).transpose(PILImage.FLIP_LEFT_RIGHT), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
985 8: lambda image: image.transpose(PILImage.ROTATE_90), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
986 } |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
987 image = transpose_func[transpose_op](image) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
988 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
989 outfile = StringIO() |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
990 image.save(outfile, output_type) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
991 data = outfile.getvalue() |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
992 outfile.close() |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
993 return content_type, data |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
994 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
995 def _do_get_modified(self, hash): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
996 try: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
997 width = int(request.values.get('w')) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
998 except (TypeError, ValueError): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
999 width = None |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1000 try: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1001 height = int(request.values.get('h')) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1002 except (TypeError, ValueError): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1003 height = None |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1004 try: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1005 transpose = int(request.values.get('t')) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1006 assert 1 <= transpose <= 8 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1007 except (TypeError, ValueError, AssertionError): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1008 transpose = 1 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1009 if width or height or transpose != 1: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1010 # resize requested, XXX check ACL behaviour! XXX |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1011 hash_name = HASH_ALGORITHM |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1012 hash_hexdigest = self.rev[hash_name] |
174
e8f61cbd661b
modularize crypto/random stuff, move it to MoinMoin.util.crypto, pw change bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
173
diff
changeset
|
1013 cid = cache_key(usage="ImageTransform", |
e8f61cbd661b
modularize crypto/random stuff, move it to MoinMoin.util.crypto, pw change bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
173
diff
changeset
|
1014 hash_name=hash_name, |
e8f61cbd661b
modularize crypto/random stuff, move it to MoinMoin.util.crypto, pw change bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
173
diff
changeset
|
1015 hash_hexdigest=hash_hexdigest, |
e8f61cbd661b
modularize crypto/random stuff, move it to MoinMoin.util.crypto, pw change bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
173
diff
changeset
|
1016 width=width, height=height, transpose=transpose) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1017 c = app.cache.get(cid) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1018 if c is None: |
216
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
1019 content_type = self.rev[CONTENTTYPE] |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1020 size = (width or 99999, height or 99999) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1021 content_type, data = self._transform(content_type, size=size, transpose_op=transpose) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1022 headers = wikiutil.file_headers(content_type=content_type, content_length=len(data)) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1023 app.cache.set(cid, (headers, data)) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1024 else: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1025 # XXX TODO check ACL behaviour |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1026 headers, data = c |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1027 return Response(data, headers=headers) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1028 else: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1029 return self._do_get(hash) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1030 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1031 def _render_data_diff(self, oldrev, newrev): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1032 if PIL is None: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1033 # no PIL, we can't do anything, we just call the base class method |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1034 return super(TransformableBitmapImage, self)._render_data_diff(oldrev, newrev) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1035 url = url_for('frontend.diffraw', item_name=self.name, rev1=oldrev.revno, rev2=newrev.revno) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1036 return Markup('<img src="%s" />' % escape(url)) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1037 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1038 def _render_data_diff_raw(self, oldrev, newrev): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1039 hash_name = HASH_ALGORITHM |
174
e8f61cbd661b
modularize crypto/random stuff, move it to MoinMoin.util.crypto, pw change bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
173
diff
changeset
|
1040 cid = cache_key(usage="ImageDiff", |
e8f61cbd661b
modularize crypto/random stuff, move it to MoinMoin.util.crypto, pw change bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
173
diff
changeset
|
1041 hash_name=hash_name, |
e8f61cbd661b
modularize crypto/random stuff, move it to MoinMoin.util.crypto, pw change bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
173
diff
changeset
|
1042 hash_old=oldrev[hash_name], |
e8f61cbd661b
modularize crypto/random stuff, move it to MoinMoin.util.crypto, pw change bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
173
diff
changeset
|
1043 hash_new=newrev[hash_name]) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1044 c = app.cache.get(cid) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1045 if c is None: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1046 if PIL is None: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1047 abort(404) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1048 |
216
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
1049 content_type = newrev[CONTENTTYPE] |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1050 if content_type == 'image/jpeg': |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1051 output_type = 'JPEG' |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1052 elif content_type == 'image/png': |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1053 output_type = 'PNG' |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1054 elif content_type == 'image/gif': |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1055 output_type = 'GIF' |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1056 else: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1057 raise ValueError("content_type %r not supported" % content_type) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1058 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1059 oldimage = PILImage.open(oldrev) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1060 newimage = PILImage.open(newrev) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1061 oldimage.load() |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1062 newimage.load() |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1063 diffimage = PILdiff(newimage, oldimage) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1064 outfile = StringIO() |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1065 diffimage.save(outfile, output_type) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1066 data = outfile.getvalue() |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1067 outfile.close() |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1068 headers = wikiutil.file_headers(content_type=content_type, content_length=len(data)) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1069 app.cache.set(cid, (headers, data)) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1070 else: |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1071 # XXX TODO check ACL behaviour |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1072 headers, data = c |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1073 return Response(data, headers=headers) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1074 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1075 def _render_data_diff_text(self, oldrev, newrev): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1076 return super(TransformableBitmapImage, self)._render_data_diff_text(oldrev, newrev) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1077 |
225
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
1078 item_registry.register(TransformableBitmapImage._factory, Type('image/png')) |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
1079 item_registry.register(TransformableBitmapImage._factory, Type('image/jpeg')) |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
1080 item_registry.register(TransformableBitmapImage._factory, Type('image/gif')) |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
1081 |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1082 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1083 class Text(Binary): |
225
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
1084 """ Base class for text/* """ |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1085 template = "modify_text.html" |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1086 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1087 # text/plain mandates crlf - but in memory, we want lf only |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1088 def data_internal_to_form(self, text): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1089 """ convert data from memory format to form format """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1090 return text.replace(u'\n', u'\r\n') |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1091 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1092 def data_form_to_internal(self, data): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1093 """ convert data from form format to memory format """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1094 return data.replace(u'\r\n', u'\n') |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1095 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1096 def data_internal_to_storage(self, text): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1097 """ convert data from memory format to storage format """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1098 return text.replace(u'\n', u'\r\n').encode(config.charset) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1099 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1100 def data_storage_to_internal(self, data): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1101 """ convert data from storage format to memory format """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1102 return data.decode(config.charset).replace(u'\r\n', u'\n') |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1103 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1104 def feed_input_conv(self): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1105 return self.data_storage_to_internal(self.data).split(u'\n') |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1106 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1107 def _render_data_diff(self, oldrev, newrev): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1108 from MoinMoin.util.diff_html import diff |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1109 old_text = self.data_storage_to_internal(oldrev.read()) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1110 new_text = self.data_storage_to_internal(newrev.read()) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1111 storage_item = flaskg.storage.get_item(self.name) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1112 revs = storage_item.list_revisions() |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1113 diffs = [(d[0], Markup(d[1]), d[2], Markup(d[3])) for d in diff(old_text, new_text)] |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1114 return Markup(render_template('diff_text.html', |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1115 item_name=self.name, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1116 oldrev=oldrev, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1117 newrev=newrev, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1118 min_revno=revs[0], |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1119 max_revno=revs[-1], |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1120 diffs=diffs, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1121 )) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1122 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1123 def _render_data_diff_text(self, oldrev, newrev): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1124 from MoinMoin.util import diff_text |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1125 oldlines = self.data_storage_to_internal(oldrev.read()).split('\n') |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1126 newlines = self.data_storage_to_internal(newrev.read()).split('\n') |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1127 difflines = diff_text.diff(oldlines, newlines) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1128 return '\n'.join(difflines) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1129 |
202
9ffa82e550ba
highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
197
diff
changeset
|
1130 def _render_data_highlight(self): |
9ffa82e550ba
highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
197
diff
changeset
|
1131 from MoinMoin.converter import default_registry as reg |
9ffa82e550ba
highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
197
diff
changeset
|
1132 data_text = self.data_storage_to_internal(self.data) |
9ffa82e550ba
highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
197
diff
changeset
|
1133 # TODO: use registry as soon as it is in there |
9ffa82e550ba
highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
197
diff
changeset
|
1134 from MoinMoin.converter.pygments_in import Converter as PygmentsConverter |
221
faa06b4873dd
more contenttype related changes/fixes, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
216
diff
changeset
|
1135 pygments_conv = PygmentsConverter(contenttype=self.contenttype) |
202
9ffa82e550ba
highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
197
diff
changeset
|
1136 doc = pygments_conv(data_text.split(u'\n')) |
9ffa82e550ba
highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
197
diff
changeset
|
1137 # TODO: Real output format |
9ffa82e550ba
highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
197
diff
changeset
|
1138 html_conv = reg.get(type_moin_document, Type('application/x-xhtml-moin-page')) |
9ffa82e550ba
highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
197
diff
changeset
|
1139 doc = html_conv(doc) |
204
af274db0ed53
items: move duplicated code to function conv_serialize
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
203
diff
changeset
|
1140 return conv_serialize(doc, {html.namespace: ''}) |
202
9ffa82e550ba
highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
197
diff
changeset
|
1141 |
242
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1142 def do_modify(self, contenttype, template_name): |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1143 # XXX think about and add item template support |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1144 #if template_name is None and isinstance(self.rev, DummyRev): |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1145 # return self._do_modify_show_templates() |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1146 from MoinMoin.apps.frontend.views import CommentForm |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1147 class ModifyForm(CommentForm): |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1148 rev = Integer.using(optional=False) |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1149 meta_text = String.using(optional=False).with_properties(placeholder=L_("MetaData (JSON)")) |
244
a11656ba1eab
modify views: use flatland also for the file upload form field
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
243
diff
changeset
|
1150 data_text = String.using(optional=True).with_properties(placeholder=L_("Type your text here")) |
a11656ba1eab
modify views: use flatland also for the file upload form field
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
243
diff
changeset
|
1151 data_file = FileStorage.using(optional=True, label=L_('Upload file:')) |
242
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1152 |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1153 if request.method == 'GET': |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1154 if template_name is None and isinstance(self.rev, DummyRev): |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1155 return self._do_modify_show_templates() |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1156 form = ModifyForm.from_defaults() |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1157 TextCha(form).amend_form() |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1158 if template_name: |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1159 item = Item.create(template_name) |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1160 form['data_text'] = self.data_storage_to_internal(item.data) |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1161 else: |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1162 form['data_text'] = self.data_storage_to_internal(self.data) |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1163 form['meta_text'] = self.meta_dict_to_text(self.meta) |
243
69c0d9f6981d
modify: put real base rev no into the hidden form field
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
242
diff
changeset
|
1164 form['rev'] = self.rev.revno if self.rev.revno is not None else -1 |
242
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1165 elif request.method == 'POST': |
244
a11656ba1eab
modify views: use flatland also for the file upload form field
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
243
diff
changeset
|
1166 form = ModifyForm.from_flat(request.form.items() + request.files.items()) |
242
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1167 TextCha(form).amend_form() |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1168 valid = form.validate() |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1169 if valid: |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1170 try: |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1171 self.modify() # XXX |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1172 except AccessDeniedError: |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1173 abort(403) |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1174 else: |
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1175 return redirect(url_for('frontend.show_item', item_name=self.name)) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1176 return render_template(self.template, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1177 item_name=self.name, |
242
e93157b8b0bd
refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
241
diff
changeset
|
1178 rows_data=str(ROWS_DATA), rows_meta=str(ROWS_META), cols=str(COLS), |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1179 help=self.modify_help, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1180 form=form, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1181 gen=make_generator(), |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1182 ) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1183 |
225
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
1184 item_registry.register(Text._factory, Type('text/*')) |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
1185 |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1186 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1187 class MarkupItem(Text): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1188 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1189 some kind of item with markup |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1190 (internal links and transcluded items) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1191 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1192 def before_revision_commit(self, newrev, data): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1193 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1194 add ITEMLINKS and ITEMTRANSCLUSIONS metadata |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1195 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1196 super(MarkupItem, self).before_revision_commit(newrev, data) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1197 |
157
4d706850ec7c
before_revision_commit: deal with file-like data also
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
122
diff
changeset
|
1198 if hasattr(data, "read"): |
4d706850ec7c
before_revision_commit: deal with file-like data also
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
122
diff
changeset
|
1199 data.seek(0) |
4d706850ec7c
before_revision_commit: deal with file-like data also
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
122
diff
changeset
|
1200 data = data.read() |
4d706850ec7c
before_revision_commit: deal with file-like data also
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
122
diff
changeset
|
1201 elif isinstance(data, str): |
4d706850ec7c
before_revision_commit: deal with file-like data also
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
122
diff
changeset
|
1202 pass |
4d706850ec7c
before_revision_commit: deal with file-like data also
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
122
diff
changeset
|
1203 else: |
4d706850ec7c
before_revision_commit: deal with file-like data also
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
122
diff
changeset
|
1204 raise StorageError("unsupported content object: %r" % data) |
4d706850ec7c
before_revision_commit: deal with file-like data also
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
122
diff
changeset
|
1205 |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1206 from MoinMoin.converter import default_registry as reg |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1207 |
216
661a57c747bd
replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
204
diff
changeset
|
1208 input_conv = reg.get(Type(self.contenttype), type_moin_document) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1209 item_conv = reg.get(type_moin_document, type_moin_document, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1210 items='refs', url_root=Iri(request.url_root)) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1211 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1212 i = Iri(scheme='wiki', authority='', path='/' + self.name) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1213 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1214 doc = input_conv(self.data_storage_to_internal(data).split(u'\n')) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1215 doc.set(moin_page.page_href, unicode(i)) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1216 doc = item_conv(doc) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1217 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1218 newrev[ITEMLINKS] = item_conv.get_links() |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1219 newrev[ITEMTRANSCLUSIONS] = item_conv.get_transclusions() |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1220 |
225
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
1221 |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1222 class MoinWiki(MarkupItem): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1223 """ MoinMoin wiki markup """ |
225
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
1224 |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
1225 item_registry.register(MoinWiki._factory, Type('text/x.moin.wiki')) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1226 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1227 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1228 class CreoleWiki(MarkupItem): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1229 """ Creole wiki markup """ |
225
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
1230 |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
1231 item_registry.register(CreoleWiki._factory, Type('text/x.moin.creole')) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1232 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1233 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1234 class MediaWiki(MarkupItem): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1235 """ MediaWiki markup """ |
225
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
1236 |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
1237 item_registry.register(MediaWiki._factory, Type('text/x-mediawiki')) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1238 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1239 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1240 class ReST(MarkupItem): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1241 """ ReStructured Text markup """ |
225
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
1242 |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
1243 item_registry.register(ReST._factory, Type('text/x-rst')) |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1244 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1245 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1246 class HTML(Text): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1247 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1248 HTML markup |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1249 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1250 Note: As we use html_in converter to convert this to DOM and later some |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1251 output converterter to produce output format (e.g. html_out for html |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1252 output), all(?) unsafe stuff will get lost. |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1253 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1254 Note: If raw revision data is accessed, unsafe stuff might be present! |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1255 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1256 template = "modify_text_html.html" |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1257 |
225
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
1258 item_registry.register(HTML._factory, Type('text/html')) |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
1259 |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1260 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1261 class DocBook(MarkupItem): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1262 """ DocBook Document """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1263 def _convert(self, doc): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1264 from emeraldtree import ElementTree as ET |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1265 from MoinMoin.converter import default_registry as reg |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1266 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1267 doc = self._expand_document(doc) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1268 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1269 # We convert the internal representation of the document |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1270 # into a DocBook document |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1271 conv = reg.get(type_moin_document, Type('application/docbook+xml')) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1272 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1273 doc = conv(doc) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1274 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1275 # We determine the different namespaces of the output form |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1276 output_namespaces = { |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1277 docbook.namespace: '', |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1278 xlink.namespace: 'xlink', |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1279 } |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1280 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1281 # We convert the result into a StringIO object |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1282 # With the appropriate namespace |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1283 # TODO: Some other operation should probably be done here too |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1284 # like adding a doctype |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1285 file_to_send = StringIO() |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1286 tree = ET.ElementTree(doc) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1287 tree.write(file_to_send, namespaces=output_namespaces) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1288 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1289 # We determine the different parameters for the reply |
221
faa06b4873dd
more contenttype related changes/fixes, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
216
diff
changeset
|
1290 mt = MimeType(mimestr='application/docbook+xml;charset=utf-8') |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1291 content_disposition = mt.content_disposition(app.cfg) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1292 content_type = mt.content_type() |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1293 # After creation of the StringIO, we are at the end of the file |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1294 # so position is the size the file. |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1295 # and then we should move it back at the beginning of the file |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1296 content_length = file_to_send.tell() |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1297 file_to_send.seek(0) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1298 # Important: empty filename keeps flask from trying to autodetect filename, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1299 # as this would not work for us, because our file's are not necessarily fs files. |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1300 return send_file(file=file_to_send, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1301 mimetype=content_type, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1302 as_attachment=False, attachment_filename=None, |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1303 cache_timeout=10, # wiki data can change rapidly |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1304 add_etags=False, etag=None, conditional=True) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1305 |
225
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
1306 item_registry.register(DocBook._factory, Type('application/docbook+xml')) |
bac248bcf98c
use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
221
diff
changeset
|
1307 |
0
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1308 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1309 class TWikiDraw(TarMixin, Image): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1310 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1311 drawings by TWikiDraw applet. It creates three files which are stored as tar file. |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1312 """ |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1313 modify_help = "" |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1314 template = "modify_twikidraw.html" |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1315 |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1316 def modify(self): |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1317 # called from modify UI/POST |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1318 file_upload = request.files.get('filepath') |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1319 filename = request.form['filename'] |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1320 basepath, basename = os.path.split(filename) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1321 basename, ext = os.path.splitext(basename) |
5568cf133caf
create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff
changeset
|
1322 |