annotate MoinMoin/items/__init__.py @ 1389:522d2cea9ec8

Fix string formatting in RegistryItem.__repr__
author DasIch <dasdasich@gmail.com>
date Sun, 03 Jun 2012 18:36:13 +0200
parents 359d51f0fa90
children 7a2ee6335ea9
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
254
91330de48b9c items: implemented 2.6 r:2031 alpha of svg-edit using a save extension for doing a single post for svg and png data.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 248
diff changeset
2 # Copyright: 2009-2011 MoinMoin:ReimarBauer
26
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
486
b6149c732926 contenttype filtering added to global index page
Akash Sinha <akash2607@gmail.com>
parents: 484
diff changeset
22 import itertools
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
23 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
24 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
25
242
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 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
27 from flatland.validation import Validator, Present, IsEmail, ValueBetween, URLValidator, Converted
779
815c46100e2c whooshify get_templates, adapt MimeType analyzer so it yields also a full and normalized contenttype
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 525
diff changeset
28
780
f5e0f85e66ce whooshify get_index()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 779
diff changeset
29 from whoosh.query import Term, And, Prefix
779
815c46100e2c whooshify get_templates, adapt MimeType analyzer so it yields also a full and normalized contenttype
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 525
diff changeset
30
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
31 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
32
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
33 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
34 from MoinMoin.signalling import item_modified
173
89f50aed143f move mimetype related code from wikiutil to util.mimetype
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 170
diff changeset
35 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
36 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
37 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
38 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
39 from MoinMoin.util.crypto import cache_key
1005
c36f61f85e97 AccessDeniedError replaced by AccessDenied, from the new storage api.
Bruno Martin <bruno@hacklab.com.br>
parents: 1004
diff changeset
40 from MoinMoin.storage.middleware.protecting import AccessDenied
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
41
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
42 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
43 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
44 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
45 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
46 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
47 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
48
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
49 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
50 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
51
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
52 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
53 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
54 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
55 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
56
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
57 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
58 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
59
242
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
60 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
61
0
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 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
63 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
64
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.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
66 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
67 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
68 from MoinMoin.util.send_file import send_file
316
4ee796d759bf use url_for_item where appropriate (in py code, no template changes yet)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 315
diff changeset
69 from MoinMoin.util.interwiki import url_for_item
1005
c36f61f85e97 AccessDeniedError replaced by AccessDenied, from the new storage api.
Bruno Martin <bruno@hacklab.com.br>
parents: 1004
diff changeset
70 from MoinMoin.storage.error import NoSuchItemError, NoSuchRevisionError, StorageError
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
71 from MoinMoin.config import NAME, NAME_OLD, NAME_EXACT, WIKINAME, 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
72 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
73 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
74 TAGS, ACTION, ADDRESS, HOSTNAME, USERID, EXTRA, COMMENT, \
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
75 HASH_ALGORITHM, CONTENTTYPE_GROUPS, ITEMID, REVID, DATAID, \
892
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
76 CURRENT, PARENTID
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
77
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
78 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
79 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
80 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
81
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
82
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
83 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
84
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
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 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
87 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
88 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
89 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
90 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
91 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
92
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 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
94 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
95 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
96
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 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
98 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
99 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
100 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
101 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 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
103
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 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
105 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
106 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
107 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
108 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
109 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
110 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
111 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
112
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 def __repr__(self):
1389
522d2cea9ec8 Fix string formatting in RegistryItem.__repr__
DasIch <dasdasich@gmail.com>
parents: 1361
diff changeset
114 return '<{0}: {1}, prio {2} [{3!r}]>'.format(self.__class__.__name__,
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
115 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
116 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
117 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
118
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 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
120 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
121 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
122 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
123 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
124
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 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
126 """
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 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
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 :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
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 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
132
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
133
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
134 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
135
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
136
1356
25a7e9e2b9b7 use polyglot writer, require emeraldtree >= 0.9.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1272
diff changeset
137 def conv_serialize(doc, namespaces, method='polyglot'):
204
af274db0ed53 items: move duplicated code to function conv_serialize
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 203
diff changeset
138 out = array('u')
af274db0ed53 items: move duplicated code to function conv_serialize
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 203
diff changeset
139 flaskg.clock.start('conv_serialize')
1356
25a7e9e2b9b7 use polyglot writer, require emeraldtree >= 0.9.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1272
diff changeset
140 doc.write(out.fromunicode, namespaces=namespaces, method=method)
204
af274db0ed53 items: move duplicated code to function conv_serialize
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 203
diff changeset
141 out = out.tounicode()
af274db0ed53 items: move duplicated code to function conv_serialize
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 203
diff changeset
142 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
143 return out
af274db0ed53 items: move duplicated code to function conv_serialize
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 203
diff changeset
144
af274db0ed53 items: move duplicated code to function conv_serialize
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 203
diff changeset
145
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
146 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
147 """ 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
148 def __init__(self, item, 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
149 self.item = item
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
150 self.meta = {CONTENTTYPE: contenttype}
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
151 self.data = StringIO('')
891
d90782ad8b24 instead of parent revno (int), we give parent revid (str) now
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 890
diff changeset
152 self.revid = 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
153
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 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
156 """ 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
157 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
158 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
159 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
160 return [] # same as an empty Item
1180
1c5a013b9ebd Fix the three failing tests.
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1152
diff changeset
161 def destroy_all_revisions(self):
1c5a013b9ebd Fix the three failing tests.
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1152
diff changeset
162 return True
0
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
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
165 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
166 """ 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
167 @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
168 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
169 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
170
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
171 @classmethod
905
51475954290f rename all revno usages to revid (no numbers any more), remove update_item param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 904
diff changeset
172 def create(cls, name=u'', contenttype=None, rev_id=CURRENT, item=None):
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 204
diff changeset
173 if contenttype is None:
415
d755f798fe66 fix some tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 402
diff changeset
174 contenttype = u'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
175
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
176 if 1: # try:
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
177 if item is None:
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
178 item = flaskg.storage[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
179 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
180 name = item.name
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
181 if not item: # except NoSuchItemError:
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
182 logging.debug("No such item: {0!r}".format(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
183 item = DummyItem(name)
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 204
diff changeset
184 rev = DummyRev(item, contenttype)
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
185 logging.debug("Item {0!r}, created dummy revision with contenttype {1!r}".format(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
186 else:
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
187 logging.debug("Got item: {0!r}".format(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
188 try:
905
51475954290f rename all revno usages to revid (no numbers any more), remove update_item param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 904
diff changeset
189 rev = item.get_revision(rev_id)
415
d755f798fe66 fix some tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 402
diff changeset
190 contenttype = u'application/octet-stream' # it exists
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
191 except KeyError: # NoSuchRevisionError:
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 try:
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
193 rev = item.get_revision(CURRENT) # fall back to current revision
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
194 # XXX add some message about invalid revision
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
195 except KeyError: # NoSuchRevisionError:
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
196 logging.debug("Item {0!r} has no revisions.".format(name))
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 204
diff changeset
197 rev = DummyRev(item, contenttype)
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
198 logging.debug("Item {0!r}, created dummy revision with contenttype {1!r}".format(name, contenttype))
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
199 logging.debug("Got item {0!r}, revision: {1!r}".format(name, rev_id))
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
200 contenttype = rev.meta.get(CONTENTTYPE) or contenttype # use contenttype in case our metadata does not provide CONTENTTYPE
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
201 logging.debug("Item {0!r}, got contenttype {1!r} from revision meta".format(name, contenttype))
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
202 #logging.debug("Item %r, rev meta dict: %r" % (name, dict(rev.meta)))
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
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
204 item = item_registry.get(name, Type(contenttype), rev=rev)
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
205 logging.debug("ItemClass {0!r} handles {1!r}".format(item.__class__, contenttype))
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
206 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
207
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 204
diff changeset
208 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
209 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
210 self.rev = rev
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 204
diff changeset
211 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
212
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
213 def get_meta(self):
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
214 return self.rev.meta
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
215 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
216
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
217 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
218 # 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
219 return ''
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
220
197
19e92e1ff286 fix the +dom view, details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 193
diff changeset
221 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
222 """
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 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
224 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
225 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
226 hash_name = HASH_ALGORITHM
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
227 hash_hexdigest = self.rev.meta.get(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
228 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
229 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
230 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
231 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
232 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
233 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
234 # 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
235 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
236 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
237 # 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
238 # 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
239 # 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
240 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
241 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
242 if not input_conv:
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
243 raise TypeError("We cannot handle the conversion from {0} to the DOM tree".format(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
244 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
245 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
246
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
247 # 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
248 links = Iri(scheme='wiki', authority='', path='/' + self.name)
292
ebdfe9448e01 make converter api more homogeneous, adapt tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 257
diff changeset
249 doc = input_conv(self.rev, 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
250 # 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
251 # 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
252 # 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
253 # 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
254 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
255 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
256 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
257 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
258 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
259 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
260 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
261 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
262
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
263 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
264 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
265 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
266 macro_conv = reg.get(type_moin_document, type_moin_document, macros='expandall')
315
fed6024028b4 link converter: remove url_root param, not needed any more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 298
diff changeset
267 link_conv = reg.get(type_moin_document, type_moin_document, links='extern')
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
268 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
269 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
270 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
271 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
272 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
273 flaskg.clock.stop('conv_macro')
67
d43c7fb728e0 Items - Move link converter into output
Bastian Blank <bblank@thinkmo.de>
parents: 38
diff changeset
274 flaskg.clock.start('conv_link')
d43c7fb728e0 Items - Move link converter into output
Bastian Blank <bblank@thinkmo.de>
parents: 38
diff changeset
275 doc = link_conv(doc)
d43c7fb728e0 Items - Move link converter into output
Bastian Blank <bblank@thinkmo.de>
parents: 38
diff changeset
276 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
277 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
278
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
279 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
280 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
281 # 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
282 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
283 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
284 flaskg.clock.start('conv_dom_html')
1361
359d51f0fa90 items: remove some unneeded code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1356
diff changeset
285 html_conv = reg.get(type_moin_document, Type('application/x-xhtml-moin-page'))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
286 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
287 flaskg.clock.stop('conv_dom_html')
1224
0e5107719adf Return a break if rendered_data has no content in it to avoid CSS theming issues.
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1214
diff changeset
288 rendered_data = conv_serialize(doc, {html.namespace: ''})
1356
25a7e9e2b9b7 use polyglot writer, require emeraldtree >= 0.9.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1272
diff changeset
289 return rendered_data
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
290
197
19e92e1ff286 fix the +dom view, details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 193
diff changeset
291 def _render_data_xml(self):
19e92e1ff286 fix the +dom view, details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 193
diff changeset
292 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
293 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
294 {moin_page.namespace: '',
af274db0ed53 items: move duplicated code to function conv_serialize
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 203
diff changeset
295 xlink.namespace: 'xlink',
af274db0ed53 items: move duplicated code to function conv_serialize
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 203
diff changeset
296 html.namespace: 'html',
1356
25a7e9e2b9b7 use polyglot writer, require emeraldtree >= 0.9.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1272
diff changeset
297 },
25a7e9e2b9b7 use polyglot writer, require emeraldtree >= 0.9.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1272
diff changeset
298 '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
299
202
9ffa82e550ba highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 197
diff changeset
300 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
301 # 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
302 return ''
9ffa82e550ba highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 197
diff changeset
303
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
304 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
305 # call this if the item is still empty
905
51475954290f rename all revno usages to revid (no numbers any more), remove update_item param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 904
diff changeset
306 rev_ids = []
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 204
diff changeset
307 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
308 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
309 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
310 rev=self.rev,
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 204
diff changeset
311 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
312 templates=item_templates,
905
51475954290f rename all revno usages to revid (no numbers any more), remove update_item param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 904
diff changeset
313 first_rev_id=rev_ids and rev_ids[0],
51475954290f rename all revno usages to revid (no numbers any more), remove update_item param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 904
diff changeset
314 last_rev_id=rev_ids and rev_ids[-1],
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
315 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
316 data_rendered='',
1019
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
317 )
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
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
319 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
320 """ 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
321 kill_keys = [# shall not get copied from old rev to new rev
1019
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
322 SYSITEM_VERSION,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
323 NAME_OLD,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
324 # are automatically implanted when saving
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
325 NAME,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
326 ITEMID, REVID, DATAID,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
327 HASH_ALGORITHM,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
328 SIZE,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
329 COMMENT,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
330 MTIME,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
331 ACTION,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
332 ADDRESS, HOSTNAME, USERID,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
333 ]
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
334 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
335 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
336 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
337
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
338 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
339 """ 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
340 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
341 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
342
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
343 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
344 """ 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
345 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
346 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
347 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
348 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
349
892
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
350 def prepare_meta_for_modify(self, meta):
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
351 """
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
352 transform the meta dict of the current revision into a meta dict
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
353 that can be used for savind next revision (after "modify").
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
354 """
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
355 meta = dict(meta)
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
356 revid = meta.pop(REVID, None)
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
357 if revid is not None:
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
358 meta[PARENTID] = revid
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
359 return meta
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
360
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
361 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
362 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
363 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
364
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
365 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
366 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
367 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
368 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
369 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
370 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
371 break
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
372 new_rev.data.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
373 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
374 elif isinstance(content, str):
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
375 new_rev.data.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
376 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
377 else:
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
378 raise StorageError("unsupported content object: {0!r}".format(content))
193
17693a043442 some preparations for jquery.file-upload code, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
379 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
380
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
381 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
382 self._save(self.meta, self.data, name=name, action=action, comment=comment)
1019
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
383 for child in self.get_index():
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
384 item = Item.create(child[0])
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
385 item._save(item.meta, item.data, name='/'.join((name, child[1])), action=action, 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
386
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
387 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
388 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
389 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
390 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
391 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
392
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
393 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
394 """
904
46263060782e remove references to "trash" (is an implementation detail and might change)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 903
diff changeset
395 delete this 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
396 """
903
50aa61c9b952 fixed rename issue: do not use the new name to load the item, but the old one
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 902
diff changeset
397 trash_prefix = u'Trash/' # XXX move to config
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
398 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
399 # make trash name unique by including timestamp:
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
400 trashname = u'{0}{1} ({2} UTC)'.format(trash_prefix, self.name, now)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
401 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
402
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
403 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
404 # 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
405 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
406 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
407
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
408 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
409 # 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
410 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
411 # destroy complete item with all revisions, metadata, etc.
910
5b7e522d97af fix destroy
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 908
diff changeset
412 self.rev.item.destroy_all_revisions()
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
413 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
414 # just destroy this revision
910
5b7e522d97af fix destroy
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 908
diff changeset
415 self.rev.item.destroy_revision(self.rev.revid)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
416
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
417 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
418 # 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
419 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
420 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
421 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
422 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
423 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
424 # 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
425 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
426 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
427 # 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
428 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
429 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
430 # 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
431 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
432 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
433 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
434 # we know it is text and utf-8 - XXX is there a way to get the charset of the form?
415
d755f798fe66 fix some tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 402
diff changeset
435 contenttype_guessed = u'text/plain;charset=utf-8'
236
7a77ae08161e items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 225
diff changeset
436 # 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
437 # 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
438
7a77ae08161e items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 225
diff changeset
439 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
440 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
441 # there was a meta_text field with (possibly empty) content
245
52ca5dc1ab15 add a JSON validator, use it to validate meta_text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 244
diff changeset
442 # Note: if you get crashes here, please see the ValidJSON validator
52ca5dc1ab15 add a JSON validator, use it to validate meta_text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 244
diff changeset
443 # to catch invalid json issues early.
52ca5dc1ab15 add a JSON validator, use it to validate meta_text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 244
diff changeset
444 meta = self.meta_text_to_dict(meta_text)
236
7a77ae08161e items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 225
diff changeset
445 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
446 # 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
447 meta = {}
7a77ae08161e items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 225
diff changeset
448
7a77ae08161e items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 225
diff changeset
449 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
450 # 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
451 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
452
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
453 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
454 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
455
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
456 def _save(self, meta, data=None, name=None, action=u'SAVE', contenttype_guessed=None, comment=u'', overwrite=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
457 backend = flaskg.storage
903
50aa61c9b952 fixed rename issue: do not use the new name to load the item, but the old one
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 902
diff changeset
458 storage_item = backend[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
459 try:
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
460 currentrev = storage_item.get_revision(CURRENT)
905
51475954290f rename all revno usages to revid (no numbers any more), remove update_item param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 904
diff changeset
461 rev_id = currentrev.revid
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
462 contenttype_current = currentrev.meta.get(CONTENTTYPE)
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
463 except KeyError: # XXX was: NoSuchRevisionError:
241
f464adcc3a51 fix saving no data if no previous revision exists
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 236
diff changeset
464 currentrev = None
905
51475954290f rename all revno usages to revid (no numbers any more), remove update_item param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 904
diff changeset
465 rev_id = None
236
7a77ae08161e items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 225
diff changeset
466 contenttype_current = None
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
467
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
468 meta = dict(meta) # we may get a read-only dict-like, copy it
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
469
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
470 # 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
471 # this is useful for rename history and backends that use item uids internally
903
50aa61c9b952 fixed rename issue: do not use the new name to load the item, but the old one
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 902
diff changeset
472 if name is None:
50aa61c9b952 fixed rename issue: do not use the new name to load the item, but the old one
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 902
diff changeset
473 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
474 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
475 if oldname and oldname != name:
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
476 meta[NAME_OLD] = oldname
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
477 meta[NAME] = name
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
478
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
479 if comment:
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
480 meta[COMMENT] = unicode(comment)
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
481
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
482 if not overwrite and REVID in meta:
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
483 # we usually want to create a new revision, thus we must remove the existing REVID
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
484 del meta[REVID]
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
485
236
7a77ae08161e items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 225
diff changeset
486 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
487 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
488 # 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
489 # a valid usecase of this is to just edit metadata.
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
490 data = currentrev.data
241
f464adcc3a51 fix saving no data if no previous revision exists
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 236
diff changeset
491 else:
f464adcc3a51 fix saving no data if no previous revision exists
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 236
diff changeset
492 data = ''
236
7a77ae08161e items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 225
diff changeset
493
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
494 if isinstance(data, unicode):
1266
1c66f39aa44f implement validation for revision metadata storage using flatland
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1236
diff changeset
495 data = data.encode(config.charset) # XXX wrong! if contenttype gives a coding, we MUST use THAT.
236
7a77ae08161e items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 225
diff changeset
496
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
497 if isinstance(data, str):
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
498 data = StringIO(data)
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
499
1266
1c66f39aa44f implement validation for revision metadata storage using flatland
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1236
diff changeset
500 newrev = storage_item.store_revision(meta, data, overwrite=overwrite,
1c66f39aa44f implement validation for revision metadata storage using flatland
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1236
diff changeset
501 action=unicode(action),
1c66f39aa44f implement validation for revision metadata storage using flatland
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1236
diff changeset
502 contenttype_current=contenttype_current,
1c66f39aa44f implement validation for revision metadata storage using flatland
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1236
diff changeset
503 contenttype_guessed=contenttype_guessed,
1c66f39aa44f implement validation for revision metadata storage using flatland
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1236
diff changeset
504 )
242
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
505 item_modified.send(app._get_current_object(), item_name=name)
905
51475954290f rename all revno usages to revid (no numbers any more), remove update_item param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 904
diff changeset
506 return newrev.revid, newrev.meta[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
507
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
508 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
509 """ 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
510 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
511 prefix = self.name + u'/'
827
94e388cd4e28 use 'constants' for metadata keys / whoosh field names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 794
diff changeset
512 query = And([Term(WIKINAME, app.cfg.interwikiname), Prefix(NAME_EXACT, prefix)])
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
513 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
514 # 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
515 # 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
516 prefix = u''
827
94e388cd4e28 use 'constants' for metadata keys / whoosh field names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 794
diff changeset
517 query = Term(WIKINAME, app.cfg.interwikiname)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
518 # 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
519 prefix_len = len(prefix)
953
326f7a365007 search/indexing: remove all_revs=False params (it is the default)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 910
diff changeset
520 revs = flaskg.storage.search(query, sortedby=NAME_EXACT, limit=None)
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
521 items = [(rev.meta[NAME], rev.meta[NAME][prefix_len:], rev.meta[CONTENTTYPE])
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
522 for rev in revs]
780
f5e0f85e66ce whooshify get_index()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 779
diff changeset
523 return items
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
524
993
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
525 def _connect_levels(self, index):
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
526 new_index = []
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
527 last = self.name
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
528 for item in index:
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
529 name = item[0]
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
530
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
531 while not name.startswith(last):
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
532 last = last.rpartition('/')[0]
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
533
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
534 missing_layers = name.split('/')[last.count('/')+1:-1]
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
535
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
536 for layer in missing_layers:
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
537 last = '/'.join([last, layer])
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
538 new_index.append((last, last[len(self.name)+1:], u'application/x-nonexistent'))
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
539
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
540 last = item[0]
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
541 new_index.append(item)
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
542
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
543 return new_index
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
544
486
b6149c732926 contenttype filtering added to global index page
Akash Sinha <akash2607@gmail.com>
parents: 484
diff changeset
545 def flat_index(self, startswith=None, selected_groups=None):
b6149c732926 contenttype filtering added to global index page
Akash Sinha <akash2607@gmail.com>
parents: 484
diff changeset
546 """
993
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
547 creates a top level index of sub items of this item
486
b6149c732926 contenttype filtering added to global index page
Akash Sinha <akash2607@gmail.com>
parents: 484
diff changeset
548 if startswith is set, filtering is done on the basis of starting letter of item name
b6149c732926 contenttype filtering added to global index page
Akash Sinha <akash2607@gmail.com>
parents: 484
diff changeset
549 if selected_groups is set, items whose contentype belonging to the selected contenttype_groups, are filtered.
b6149c732926 contenttype filtering added to global index page
Akash Sinha <akash2607@gmail.com>
parents: 484
diff changeset
550 """
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
551 index = self.get_index()
993
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
552 index = self._connect_levels(index)
486
b6149c732926 contenttype filtering added to global index page
Akash Sinha <akash2607@gmail.com>
parents: 484
diff changeset
553
496
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
554 all_ctypes = [[ctype for ctype, clabel in contenttypes]
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
555 for gname, contenttypes in CONTENTTYPE_GROUPS]
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
556 all_ctypes_chain = itertools.chain(*all_ctypes)
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
557 all_contenttypes = list(all_ctypes_chain)
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
558 contenttypes_without_encoding = [contenttype[:contenttype.index(u';')]
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
559 for contenttype in all_contenttypes
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
560 if u';' in contenttype]
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
561 all_contenttypes.extend(contenttypes_without_encoding) # adding more mime-types without the encoding term
486
b6149c732926 contenttype filtering added to global index page
Akash Sinha <akash2607@gmail.com>
parents: 484
diff changeset
562
496
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
563 if selected_groups:
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
564 ctypes = [[ctype for ctype, clabel in contenttypes]
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
565 for gname, contenttypes in CONTENTTYPE_GROUPS
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
566 if gname in selected_groups]
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
567 ctypes_chain = itertools.chain(*ctypes)
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
568 selected_contenttypes = list(ctypes_chain)
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
569 contenttypes_without_encoding = [contenttype[:contenttype.index(u';')]
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
570 for contenttype in selected_contenttypes
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
571 if u';' in contenttype]
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
572 selected_contenttypes.extend(contenttypes_without_encoding)
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
573 else:
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
574 selected_contenttypes = all_contenttypes
486
b6149c732926 contenttype filtering added to global index page
Akash Sinha <akash2607@gmail.com>
parents: 484
diff changeset
575
518
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
576 unknown_item_group = "unknown items"
477
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 257
diff changeset
577 if startswith:
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
578 startswith = (u'{0}'.format(startswith), u'{0}'.format(startswith.swapcase()))
520
6332dda59cb6 some pep8 fixes
Akash Sinha <akash2607@gmail.com>
parents: 518
diff changeset
579 if not selected_groups or unknown_item_group in selected_groups:
518
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
580 index = [(fullname, relname, contenttype)
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
581 for fullname, relname, contenttype in index
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
582 if u'/' not in relname
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
583 and relname.startswith(startswith)
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
584 and (contenttype not in all_contenttypes or contenttype in selected_contenttypes)]
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
585 # If an item's contenttype not present in the default contenttype list,
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
586 # then it will be shown without going through any filter.
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
587 else:
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
588 index = [(fullname, relname, contenttype)
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
589 for fullname, relname, contenttype in index
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
590 if u'/' not in relname
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
591 and relname.startswith(startswith)
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
592 and (contenttype in selected_contenttypes)]
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
593
477
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 257
diff changeset
594 else:
518
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
595 if not selected_groups or unknown_item_group in selected_groups:
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
596 index = [(fullname, relname, contenttype)
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
597 for fullname, relname, contenttype in index
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
598 if u'/' not in relname
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
599 and (contenttype not in all_contenttypes or contenttype in selected_contenttypes)]
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
600 else:
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
601 index = [(fullname, relname, contenttype)
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
602 for fullname, relname, contenttype in index
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
603 if u'/' not in relname
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
604 and contenttype in selected_contenttypes]
477
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 257
diff changeset
605
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
606 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
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 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
609
484
19b257c0e102 code to get the subitem index flag has been refactored and moved under items/__init__.py and also unitest is added for the same.
Akash Sinha <akash2607@gmail.com>
parents: 477
diff changeset
610 def get_detailed_index(self, index):
19b257c0e102 code to get the subitem index flag has been refactored and moved under items/__init__.py and also unitest is added for the same.
Akash Sinha <akash2607@gmail.com>
parents: 477
diff changeset
611 """ appends a flag in the index of items indicating that the parent has sub items """
19b257c0e102 code to get the subitem index flag has been refactored and moved under items/__init__.py and also unitest is added for the same.
Akash Sinha <akash2607@gmail.com>
parents: 477
diff changeset
612 detailed_index = []
19b257c0e102 code to get the subitem index flag has been refactored and moved under items/__init__.py and also unitest is added for the same.
Akash Sinha <akash2607@gmail.com>
parents: 477
diff changeset
613 all_item_index = self.get_index()
19b257c0e102 code to get the subitem index flag has been refactored and moved under items/__init__.py and also unitest is added for the same.
Akash Sinha <akash2607@gmail.com>
parents: 477
diff changeset
614 all_item_text = "\n".join(item_info[1] for item_info in all_item_index)
19b257c0e102 code to get the subitem index flag has been refactored and moved under items/__init__.py and also unitest is added for the same.
Akash Sinha <akash2607@gmail.com>
parents: 477
diff changeset
615 for fullname, relname, contenttype in index:
19b257c0e102 code to get the subitem index flag has been refactored and moved under items/__init__.py and also unitest is added for the same.
Akash Sinha <akash2607@gmail.com>
parents: 477
diff changeset
616 hassubitem = False
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
617 subitem_name_re = u"^{0}/[^/]+$".format(re.escape(relname))
524
77a9bd2d3dc8 regex search function updated, to get the subitem flag correctly
Akash Sinha <akash2607@gmail.com>
parents: 520
diff changeset
618 regex = re.compile(subitem_name_re, re.UNICODE|re.M)
484
19b257c0e102 code to get the subitem index flag has been refactored and moved under items/__init__.py and also unitest is added for the same.
Akash Sinha <akash2607@gmail.com>
parents: 477
diff changeset
619 if regex.search(all_item_text):
19b257c0e102 code to get the subitem index flag has been refactored and moved under items/__init__.py and also unitest is added for the same.
Akash Sinha <akash2607@gmail.com>
parents: 477
diff changeset
620 hassubitem = True
19b257c0e102 code to get the subitem index flag has been refactored and moved under items/__init__.py and also unitest is added for the same.
Akash Sinha <akash2607@gmail.com>
parents: 477
diff changeset
621 detailed_index.append((fullname, relname, contenttype, hassubitem))
19b257c0e102 code to get the subitem index flag has been refactored and moved under items/__init__.py and also unitest is added for the same.
Akash Sinha <akash2607@gmail.com>
parents: 477
diff changeset
622 return detailed_index
19b257c0e102 code to get the subitem index flag has been refactored and moved under items/__init__.py and also unitest is added for the same.
Akash Sinha <akash2607@gmail.com>
parents: 477
diff changeset
623
477
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 257
diff changeset
624 def name_initial(self, names=None):
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 257
diff changeset
625 initials = [(name[1][0])
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 257
diff changeset
626 for name in names]
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 257
diff changeset
627 return initials
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
628
1003
8621c3e273a1 fixes #72. Implements the page to handle 404 error, and calls abort(404) in some view, when apropriate.
Bruno Martin <bruno@hacklab.com.br>
parents: 969
diff changeset
629 delete_template = 'delete.html'
8621c3e273a1 fixes #72. Implements the page to handle 404 error, and calls abort(404) in some view, when apropriate.
Bruno Martin <bruno@hacklab.com.br>
parents: 969
diff changeset
630 destroy_template = 'destroy.html'
8621c3e273a1 fixes #72. Implements the page to handle 404 error, and calls abort(404) in some view, when apropriate.
Bruno Martin <bruno@hacklab.com.br>
parents: 969
diff changeset
631 diff_template = 'diff.html'
8621c3e273a1 fixes #72. Implements the page to handle 404 error, and calls abort(404) in some view, when apropriate.
Bruno Martin <bruno@hacklab.com.br>
parents: 969
diff changeset
632 rename_template = 'rename.html'
8621c3e273a1 fixes #72. Implements the page to handle 404 error, and calls abort(404) in some view, when apropriate.
Bruno Martin <bruno@hacklab.com.br>
parents: 969
diff changeset
633 revert_template = 'revert.html'
8621c3e273a1 fixes #72. Implements the page to handle 404 error, and calls abort(404) in some view, when apropriate.
Bruno Martin <bruno@hacklab.com.br>
parents: 969
diff changeset
634
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
635 class NonExistent(Item):
509
92cc4c7ea1c0 mimetype parameter added in the download item link, such that we could set the contenttype of item being downloaded as desired.
Akash Sinha <akash2607@gmail.com>
parents: 496
diff changeset
636 def do_get(self, force_attachment=False, mimetype=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
637 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
638
1099
2068f99501c5 fix a few bugs exposed by the new view tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1023
diff changeset
639 def _convert(self, doc):
0
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
242
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
642 def do_modify(self, contenttype, template_name):
1236
3b723046d80e First, check if the user has the needed ACLs before allowing the user to enter page content or choose content type for creating a new page
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1230
diff changeset
643 # First, check if the current user has the required privileges
3b723046d80e First, check if the user has the needed ACLs before allowing the user to enter page content or choose content type for creating a new page
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1230
diff changeset
644 if not flaskg.user.may.create(self.name):
3b723046d80e First, check if the user has the needed ACLs before allowing the user to enter page content or choose content type for creating a new page
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1230
diff changeset
645 abort(403)
3b723046d80e First, check if the user has the needed ACLs before allowing the user to enter page content or choose content type for creating a new page
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1230
diff changeset
646
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
647 # 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
648 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
649 item_name=self.name,
488
8462764f59d2 contenttype_groups structure moved under config
Akash Sinha <akash2607@gmail.com>
parents: 486
diff changeset
650 contenttype_groups=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
651 )
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
652
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
653 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
654
245
52ca5dc1ab15 add a JSON validator, use it to validate meta_text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 244
diff changeset
655 class ValidJSON(Validator):
52ca5dc1ab15 add a JSON validator, use it to validate meta_text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 244
diff changeset
656 """Validator for JSON
52ca5dc1ab15 add a JSON validator, use it to validate meta_text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 244
diff changeset
657 """
52ca5dc1ab15 add a JSON validator, use it to validate meta_text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 244
diff changeset
658 invalid_json_msg = L_('Invalid JSON.')
52ca5dc1ab15 add a JSON validator, use it to validate meta_text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 244
diff changeset
659
52ca5dc1ab15 add a JSON validator, use it to validate meta_text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 244
diff changeset
660 def validate(self, element, state):
52ca5dc1ab15 add a JSON validator, use it to validate meta_text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 244
diff changeset
661 try:
52ca5dc1ab15 add a JSON validator, use it to validate meta_text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 244
diff changeset
662 json.loads(element.value)
52ca5dc1ab15 add a JSON validator, use it to validate meta_text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 244
diff changeset
663 except:
52ca5dc1ab15 add a JSON validator, use it to validate meta_text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 244
diff changeset
664 return self.note_error(element, state, 'invalid_json_msg')
52ca5dc1ab15 add a JSON validator, use it to validate meta_text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 244
diff changeset
665 return True
52ca5dc1ab15 add a JSON validator, use it to validate meta_text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 244
diff changeset
666
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
667
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
668 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
669 """ 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
670 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
671 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
672 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
673
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
674 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
675
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
676 # 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
677 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
678 if self.rev is not None:
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
679 return self.rev.data.read()
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 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
681 return ''
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
682 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
683
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
684 def _render_meta(self):
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
685 return "<pre>{0}</pre>".format(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
686
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 204
diff changeset
687 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
688 """ create a list of templates (for some specific contenttype) """
827
94e388cd4e28 use 'constants' for metadata keys / whoosh field names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 794
diff changeset
689 terms = [Term(WIKINAME, app.cfg.interwikiname), Term(TAGS, u'template')]
779
815c46100e2c whooshify get_templates, adapt MimeType analyzer so it yields also a full and normalized contenttype
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 525
diff changeset
690 if contenttype is not None:
815c46100e2c whooshify get_templates, adapt MimeType analyzer so it yields also a full and normalized contenttype
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 525
diff changeset
691 terms.append(Term(CONTENTTYPE, contenttype))
815c46100e2c whooshify get_templates, adapt MimeType analyzer so it yields also a full and normalized contenttype
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 525
diff changeset
692 query = And(terms)
953
326f7a365007 search/indexing: remove all_revs=False params (it is the default)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 910
diff changeset
693 revs = flaskg.storage.search(query, sortedby=NAME_EXACT, limit=None)
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
694 return [rev.meta[NAME] for rev in 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
695
242
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
696 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
697 # 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
698 #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
699 # 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
700 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
701 class ModifyForm(CommentForm):
245
52ca5dc1ab15 add a JSON validator, use it to validate meta_text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 244
diff changeset
702 meta_text = String.using(optional=False).with_properties(placeholder=L_("MetaData (JSON)")).validated_by(ValidJSON())
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
703 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
704
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
705 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
706 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
707 TextCha(form).amend_form()
892
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
708 form['meta_text'] = self.meta_dict_to_text(self.prepare_meta_for_modify(self.meta))
242
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
709 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
710 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
711 TextCha(form).amend_form()
246
727e03c59dbf simplify form validation check, fix indentation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 245
diff changeset
712 if form.validate():
242
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
713 try:
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
714 self.modify() # XXX
1005
c36f61f85e97 AccessDeniedError replaced by AccessDenied, from the new storage api.
Bruno Martin <bruno@hacklab.com.br>
parents: 1004
diff changeset
715 except AccessDenied:
242
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
716 abort(403)
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
717 else:
316
4ee796d759bf use url_for_item where appropriate (in py code, no template changes yet)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 315
diff changeset
718 return redirect(url_for_item(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
719 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
720 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
721 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
722 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
723 form=form,
1229
29301b8a2718 Hide search box in modify views.
Sam Toyer <samATqxcvDOTnet>
parents: 1214
diff changeset
724 search_form=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
725 )
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
726
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
727 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
728 hash_name = HASH_ALGORITHM
860
de6ece090b7d fix download view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
729 if oldrev.meta[hash_name] == newrev.meta[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
730 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
731 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
732 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
733
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
734 _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
735 _render_data_diff_raw = _render_data_diff
1211
e63c9c8d0ad9 Move revision info to the end
Shitiz Garg <mail@dragooon.net>
parents: 1210
diff changeset
736
1208
92d8f0777a9a Improve handling of other data types in atom feed, also remove anchor tags from line numbers
Shitiz Garg <mail@dragooon.net>
parents: 1199
diff changeset
737 def _render_data_diff_atom(self, oldrev, newrev):
1211
e63c9c8d0ad9 Move revision info to the end
Shitiz Garg <mail@dragooon.net>
parents: 1210
diff changeset
738 return render_template('atom.html',
1208
92d8f0777a9a Improve handling of other data types in atom feed, also remove anchor tags from line numbers
Shitiz Garg <mail@dragooon.net>
parents: 1199
diff changeset
739 oldrev=oldrev, newrev=newrev, get='binary',
92d8f0777a9a Improve handling of other data types in atom feed, also remove anchor tags from line numbers
Shitiz Garg <mail@dragooon.net>
parents: 1199
diff changeset
740 content=Markup(self._render_data()))
1198
2aa4f4ec6a94 Minor fixes for atom feed
Shitiz Garg <mail@dragooon.net>
parents: 1197
diff changeset
741
1099
2068f99501c5 fix a few bugs exposed by the new view tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1023
diff changeset
742 def _convert(self, doc):
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 204
diff changeset
743 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
744 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
745
509
92cc4c7ea1c0 mimetype parameter added in the download item link, such that we could set the contenttype of item being downloaded as desired.
Akash Sinha <akash2607@gmail.com>
parents: 496
diff changeset
746 def do_get(self, force_attachment=False, mimetype=None):
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
747 hash = self.rev.meta.get(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
748 if is_resource_modified(request.environ, hash): # use hash as etag
509
92cc4c7ea1c0 mimetype parameter added in the download item link, such that we could set the contenttype of item being downloaded as desired.
Akash Sinha <akash2607@gmail.com>
parents: 496
diff changeset
749 return self._do_get_modified(hash, force_attachment=force_attachment, mimetype=mimetype)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
750 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
751 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
752
509
92cc4c7ea1c0 mimetype parameter added in the download item link, such that we could set the contenttype of item being downloaded as desired.
Akash Sinha <akash2607@gmail.com>
parents: 496
diff changeset
753 def _do_get_modified(self, hash, force_attachment=False, mimetype=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
754 member = request.values.get('member')
509
92cc4c7ea1c0 mimetype parameter added in the download item link, such that we could set the contenttype of item being downloaded as desired.
Akash Sinha <akash2607@gmail.com>
parents: 496
diff changeset
755 return self._do_get(hash, member, force_attachment=force_attachment, mimetype=mimetype)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
756
509
92cc4c7ea1c0 mimetype parameter added in the download item link, such that we could set the contenttype of item being downloaded as desired.
Akash Sinha <akash2607@gmail.com>
parents: 496
diff changeset
757 def _do_get(self, hash, member=None, force_attachment=False, mimetype=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
758 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
759 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
760 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
761 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
762 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
763 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
764 rev = self.rev
255
76a4e3cc8705 add +download view for just downloading a revision with forced content-disposition: attachment
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 254
diff changeset
765 filename = rev.item.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
766 try:
860
de6ece090b7d fix download view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
767 mimestr = rev.meta[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
768 except KeyError:
255
76a4e3cc8705 add +download view for just downloading a revision with forced content-disposition: attachment
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 254
diff changeset
769 mt = MimeType(filename=filename)
221
faa06b4873dd more contenttype related changes/fixes, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 216
diff changeset
770 else:
faa06b4873dd more contenttype related changes/fixes, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 216
diff changeset
771 mt = MimeType(mimestr=mimestr)
860
de6ece090b7d fix download view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
772 content_length = rev.meta[SIZE]
de6ece090b7d fix download view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
773 file_to_send = rev.data
509
92cc4c7ea1c0 mimetype parameter added in the download item link, such that we could set the contenttype of item being downloaded as desired.
Akash Sinha <akash2607@gmail.com>
parents: 496
diff changeset
774 if mimetype:
92cc4c7ea1c0 mimetype parameter added in the download item link, such that we could set the contenttype of item being downloaded as desired.
Akash Sinha <akash2607@gmail.com>
parents: 496
diff changeset
775 content_type = mimetype
92cc4c7ea1c0 mimetype parameter added in the download item link, such that we could set the contenttype of item being downloaded as desired.
Akash Sinha <akash2607@gmail.com>
parents: 496
diff changeset
776 else:
92cc4c7ea1c0 mimetype parameter added in the download item link, such that we could set the contenttype of item being downloaded as desired.
Akash Sinha <akash2607@gmail.com>
parents: 496
diff changeset
777 content_type = mt.content_type()
255
76a4e3cc8705 add +download view for just downloading a revision with forced content-disposition: attachment
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 254
diff changeset
778 as_attachment = force_attachment or mt.as_attachment(app.cfg)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
779 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
780 mimetype=content_type,
255
76a4e3cc8705 add +download view for just downloading a revision with forced content-disposition: attachment
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 254
diff changeset
781 as_attachment=as_attachment, attachment_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
782 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
783 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
784
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 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
786
0
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 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
789 """ 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
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 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
793 """ 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
794
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
795
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
796 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
797 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
798 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
799 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
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 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
802 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
803 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
804 """
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
805 self.rev.data.seek(0)
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
806 tf = tarfile.open(fileobj=self.rev.data, mode='r')
0
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 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
808
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
809 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
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 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
812
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
813 :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
814 """
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
815 self.rev.data.seek(0)
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
816 tf = tarfile.open(fileobj=self.rev.data, mode='r')
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
817 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
818
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
819 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
820 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
821 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
822 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
823 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
824
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
825 :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
826 :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
827 :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
828 :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
829 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
830 if not name in expected_members:
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
831 raise StorageError("tried to add unexpected member {0!r} to container item {1!r}".format(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 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
833 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
834 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
835 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
836 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
837 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
838 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
839 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
840 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
841 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
842 elif not hasattr(content, 'read'):
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
843 logging.error("unsupported content object: {0!r}".format(content))
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
844 raise StorageError("unsupported content object: {0!r}".format(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
845 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
846 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
847 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
848 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
849 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
850 if tf_members - expected_members:
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
851 msg = "found unexpected members in container item {0!r}".format(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
852 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
853 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
854 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
855 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
856 # 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
857 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
858 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
859 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
860 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
861 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
862
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
863
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
864 class ApplicationXTar(TarMixin, Application):
257
eea3a94a4061 refactored calling convention of converters, add rev=n qs argument for Iris (fixes #21)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 256
diff changeset
865 """
eea3a94a4061 refactored calling convention of converters, add rev=n qs argument for Iris (fixes #21)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 256
diff changeset
866 Tar items
eea3a94a4061 refactored calling convention of converters, add rev=n qs argument for Iris (fixes #21)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 256
diff changeset
867 """
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
868
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
869 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
870 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
871
0
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 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
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 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
876 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
877 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
878 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
879 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
880 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
881 """
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
882 self.rev.data.seek(0)
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
883 zf = zipfile.ZipFile(self.rev.data, mode='r')
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
884 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
885
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
886 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
887 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
888 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
889
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
890 :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
891 """
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
892 self.rev.data.seek(0)
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
893 zf = zipfile.ZipFile(self.rev.data, mode='r')
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
894 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
895
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 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
897 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
898
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
899
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
900 class ApplicationZip(ZipMixin, Application):
257
eea3a94a4061 refactored calling convention of converters, add rev=n qs argument for Iris (fixes #21)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 256
diff changeset
901 """
eea3a94a4061 refactored calling convention of converters, add rev=n qs argument for Iris (fixes #21)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 256
diff changeset
902 Zip items
eea3a94a4061 refactored calling convention of converters, add rev=n qs argument for Iris (fixes #21)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 256
diff changeset
903 """
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
904
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
905 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
906
0
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 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
909 """ 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
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(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
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 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
915 """ 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
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(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
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 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
921 """ 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
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(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
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 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
927 """ Base class for image/* """
1214
8d547ec39a76 Cosmetic changes
Shitiz Garg <mail@dragooon.net>
parents: 1213
diff changeset
928
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
929 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
930
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
931
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
932 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
933 """ 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
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 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
937 """ 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
938
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
939 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
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
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
942 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
943 """ 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
944 # 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
945
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 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
948 """ 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
949 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
950 """ 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
951 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
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 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
954 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
955 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
956 # no PIL, we can't do anything, we just output the revision data as is
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
957 return content_type, self.rev.data.read()
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
958
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
959 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
960 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
961 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
962 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
963 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
964 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
965 else:
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
966 raise ValueError("content_type {0!r} not supported".format(content_type))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
967
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
968 # revision obj has read() seek() tell(), thus this works:
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
969 image = PILImage.open(self.rev.data)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
970 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
971
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
972 try:
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 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
974 # 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
975 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
976 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
977 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
978
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
979 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
980 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
981 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
982
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
983 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
984 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
985 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
986 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
987 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
988 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
989 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
990 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
991 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
992 }
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
993 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
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 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
996 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
997 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
998 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
999 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
1000
509
92cc4c7ea1c0 mimetype parameter added in the download item link, such that we could set the contenttype of item being downloaded as desired.
Akash Sinha <akash2607@gmail.com>
parents: 496
diff changeset
1001 def _do_get_modified(self, hash, force_attachment=False, mimetype=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
1002 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1003 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
1004 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
1005 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
1006 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1007 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
1008 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
1009 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
1010 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1011 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
1012 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
1013 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
1014 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
1015 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
1016 # 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
1017 hash_name = HASH_ALGORITHM
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
1018 hash_hexdigest = self.rev.meta[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
1019 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
1020 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
1021 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
1022 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
1023 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
1024 if c is None:
509
92cc4c7ea1c0 mimetype parameter added in the download item link, such that we could set the contenttype of item being downloaded as desired.
Akash Sinha <akash2607@gmail.com>
parents: 496
diff changeset
1025 if mimetype:
92cc4c7ea1c0 mimetype parameter added in the download item link, such that we could set the contenttype of item being downloaded as desired.
Akash Sinha <akash2607@gmail.com>
parents: 496
diff changeset
1026 content_type = mimetype
92cc4c7ea1c0 mimetype parameter added in the download item link, such that we could set the contenttype of item being downloaded as desired.
Akash Sinha <akash2607@gmail.com>
parents: 496
diff changeset
1027 else:
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
1028 content_type = self.rev.meta[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
1029 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
1030 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
1031 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
1032 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
1033 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1034 # 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
1035 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
1036 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
1037 else:
509
92cc4c7ea1c0 mimetype parameter added in the download item link, such that we could set the contenttype of item being downloaded as desired.
Akash Sinha <akash2607@gmail.com>
parents: 496
diff changeset
1038 return self._do_get(hash, force_attachment=force_attachment, mimetype=mimetype)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1039
1209
c0eaed311e0e Try using PIL for image diffs
Shitiz Garg <mail@dragooon.net>
parents: 1208
diff changeset
1040 def _render_data_diff_atom(self, oldrev, newrev):
c0eaed311e0e Try using PIL for image diffs
Shitiz Garg <mail@dragooon.net>
parents: 1208
diff changeset
1041 if PIL is None:
c0eaed311e0e Try using PIL for image diffs
Shitiz Garg <mail@dragooon.net>
parents: 1208
diff changeset
1042 # no PIL, we can't do anything, we just call the base class method
c0eaed311e0e Try using PIL for image diffs
Shitiz Garg <mail@dragooon.net>
parents: 1208
diff changeset
1043 return super(TransformableBitmapImage, self)._render_data_diff_atom(oldrev, newrev)
1210
d5c6c9ada478 Fix incorrect URL while fetching images' diff
Shitiz Garg <mail@dragooon.net>
parents: 1209
diff changeset
1044 url = url_for('frontend.diffraw', _external=True, item_name=self.name, rev1=oldrev.revid, rev2=newrev.revid)
1209
c0eaed311e0e Try using PIL for image diffs
Shitiz Garg <mail@dragooon.net>
parents: 1208
diff changeset
1045 return render_template('atom.html',
c0eaed311e0e Try using PIL for image diffs
Shitiz Garg <mail@dragooon.net>
parents: 1208
diff changeset
1046 oldrev=oldrev, newrev=newrev, get='binary',
c0eaed311e0e Try using PIL for image diffs
Shitiz Garg <mail@dragooon.net>
parents: 1208
diff changeset
1047 content=Markup('<img src="{0}" />'.format(escape(url))))
c0eaed311e0e Try using PIL for image diffs
Shitiz Garg <mail@dragooon.net>
parents: 1208
diff changeset
1048
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1049 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
1050 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
1051 # 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
1052 return super(TransformableBitmapImage, self)._render_data_diff(oldrev, newrev)
859
95d1033b7808 fix show/meta view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 852
diff changeset
1053 url = url_for('frontend.diffraw', item_name=self.name, rev1=oldrev.revid, rev2=newrev.revid)
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
1054 return Markup('<img src="{0}" />'.format(escape(url)))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1055
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1056 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
1057 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
1058 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
1059 hash_name=hash_name,
860
de6ece090b7d fix download view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
1060 hash_old=oldrev.meta[hash_name],
de6ece090b7d fix download view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
1061 hash_new=newrev.meta[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
1062 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
1063 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
1064 if PIL is None:
256
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
1065 abort(404) # TODO render user friendly error 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
1066
860
de6ece090b7d fix download view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
1067 content_type = newrev.meta[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
1068 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
1069 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
1070 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
1071 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
1072 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
1073 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
1074 else:
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
1075 raise ValueError("content_type {0!r} not supported".format(content_type))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1076
256
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
1077 try:
1152
a284e43d1292 Use rev.data instead of rev, to fix crash that occured on image diff
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1112
diff changeset
1078 oldimage = PILImage.open(oldrev.data)
a284e43d1292 Use rev.data instead of rev, to fix crash that occured on image diff
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1112
diff changeset
1079 newimage = PILImage.open(newrev.data)
256
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
1080 oldimage.load()
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
1081 newimage.load()
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
1082 diffimage = PILdiff(newimage, oldimage)
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
1083 outfile = StringIO()
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
1084 diffimage.save(outfile, output_type)
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
1085 data = outfile.getvalue()
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
1086 outfile.close()
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
1087 headers = wikiutil.file_headers(content_type=content_type, content_length=len(data))
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
1088 app.cache.set(cid, (headers, data))
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
1089 except (IOError, ValueError) as err:
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
1090 logging.exception("error during PILdiff: {0}".format(err.message))
256
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
1091 abort(404) # TODO render user friendly error 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
1092 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1093 # 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
1094 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
1095 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
1096
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1097 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
1098 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
1099
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
1100 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
1101 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
1102 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
1103
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1104
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1105 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
1106 """ 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
1107 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
1108
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1109 # 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
1110 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
1111 """ 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
1112 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
1113
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1114 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
1115 """ 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
1116 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
1117
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1118 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
1119 """ 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
1120 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
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 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
1123 """ 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
1124 return data.decode(config.charset).replace(u'\r\n', u'\n')
1198
2aa4f4ec6a94 Minor fixes for atom feed
Shitiz Garg <mail@dragooon.net>
parents: 1197
diff changeset
1125
1197
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
1126 def _get_data_diff_html(self, oldrev, newrev, template):
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1127 from MoinMoin.util.diff_html import diff
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
1128 old_text = self.data_storage_to_internal(oldrev.data.read())
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
1129 new_text = self.data_storage_to_internal(newrev.data.read())
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
1130 storage_item = flaskg.storage[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
1131 diffs = [(d[0], Markup(d[1]), d[2], Markup(d[3])) for d in diff(old_text, new_text)]
1197
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
1132 return render_template(template,
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
1133 item_name=self.name,
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
1134 oldrev=oldrev,
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
1135 newrev=newrev,
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
1136 diffs=diffs,
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
1137 )
1198
2aa4f4ec6a94 Minor fixes for atom feed
Shitiz Garg <mail@dragooon.net>
parents: 1197
diff changeset
1138
1197
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
1139 def _render_data_diff_atom(self, oldrev, newrev):
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
1140 """ renders diff in HTML for atom feed """
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
1141 return self._get_data_diff_html(oldrev, newrev, 'diff_text_atom.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
1142
1197
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
1143 def _render_data_diff(self, oldrev, newrev):
1199
a4ce283b0ca2 Text::_render_data_diff should return unicode in keeping it consistent with _render_data_diff_atom
Shitiz Garg <mail@dragooon.net>
parents: 1198
diff changeset
1144 return self._get_data_diff_html(oldrev, newrev, 'diff_text.html')
1198
2aa4f4ec6a94 Minor fixes for atom feed
Shitiz Garg <mail@dragooon.net>
parents: 1197
diff changeset
1145
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1146 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
1147 from MoinMoin.util import diff_text
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
1148 oldlines = self.data_storage_to_internal(oldrev.data.read()).split('\n')
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
1149 newlines = self.data_storage_to_internal(newrev.data.read()).split('\n')
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1150 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
1151 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
1152
1112
b02f88f4428e Fix diffraw view, fix text diffraw
Sam Toyer <samATqxcvDOTnet>
parents: 1099
diff changeset
1153 _render_data_diff_raw = _render_data_diff
b02f88f4428e Fix diffraw view, fix text diffraw
Sam Toyer <samATqxcvDOTnet>
parents: 1099
diff changeset
1154
202
9ffa82e550ba highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 197
diff changeset
1155 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
1156 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
1157 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
1158 # 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
1159 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
1160 pygments_conv = PygmentsConverter(contenttype=self.contenttype)
298
07143bd03aed fix pygments converter call for new converter api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 292
diff changeset
1161 doc = pygments_conv(data_text)
202
9ffa82e550ba highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 197
diff changeset
1162 # 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
1163 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
1164 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
1165 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
1166
242
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
1167 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
1168 # 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
1169 #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
1170 # 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
1171 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
1172 class ModifyForm(CommentForm):
245
52ca5dc1ab15 add a JSON validator, use it to validate meta_text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 244
diff changeset
1173 meta_text = String.using(optional=False).with_properties(placeholder=L_("MetaData (JSON)")).validated_by(ValidJSON())
1272
4c4ee1f25e9f do not strip text item data, fixes #129
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1266
diff changeset
1174 data_text = String.using(strip=False, optional=True).with_properties(placeholder=L_("Type your text here"))
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
1175 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
1176
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
1177 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
1178 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
1179 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
1180 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
1181 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
1182 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
1183 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
1184 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
1185 else:
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
1186 form['data_text'] = self.data_storage_to_internal(self.data)
892
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
1187 form['meta_text'] = self.meta_dict_to_text(self.prepare_meta_for_modify(self.meta))
242
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
1188 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
1189 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
1190 TextCha(form).amend_form()
246
727e03c59dbf simplify form validation check, fix indentation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 245
diff changeset
1191 if form.validate():
242
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
1192 try:
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
1193 self.modify() # XXX
1005
c36f61f85e97 AccessDeniedError replaced by AccessDenied, from the new storage api.
Bruno Martin <bruno@hacklab.com.br>
parents: 1004
diff changeset
1194 except AccessDenied:
242
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
1195 abort(403)
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
1196 else:
316
4ee796d759bf use url_for_item where appropriate (in py code, no template changes yet)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 315
diff changeset
1197 return redirect(url_for_item(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
1198 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
1199 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
1200 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
1201 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
1202 form=form,
1229
29301b8a2718 Hide search box in modify views.
Sam Toyer <samATqxcvDOTnet>
parents: 1214
diff changeset
1203 search_form=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
1204 )
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1205
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
1206 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
1207
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1208
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1209 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
1210 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1211 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
1212 (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
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
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
1215
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1216 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
1217 """ 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
1218
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
1219 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
1220
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1221
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 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
1223 """ 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
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(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
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 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
1229 """ 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
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(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
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 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
1235 """ 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
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(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
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 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
1241 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1242 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
1243
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1244 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
1245 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
1246 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
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 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
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 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
1251
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
1252 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
1253
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1254
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1255 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
1256 """ 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
1257 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
1258 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
1259 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
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 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
1262
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1263 # 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
1264 # 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
1265 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
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 = 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
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 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
1270 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
1271 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
1272 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
1273 }
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1274