annotate MoinMoin/items/__init__.py @ 1451:c32ff2e07e7a

Introduce itemtype. itemtype is used to affect the overall frontend view of an item, and to affect the indexer by offering a set of metadata keys. The original items.Item hierarchy was mosted turned into the new Content hierarchy, leaving code affecting the overview in the new Item and Default (which is an Item descent) classes. Item instances now have a `content` property which is what used to be an Item instance (now a Content instance). This is the first itemtype changeset which just moves codes around ensure they are not broken. More changesets follow soon.
author Cheer Xiao <xiaqqaix@gmail.com>
date Sat, 28 Jul 2012 01:22:44 +0800
parents 9f36555901db
children 35024b2245c5
rev   line source
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1361
diff changeset
1 # Copyright: 2012 MoinMoin:CheerXiao
26
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
2 # Copyright: 2009 MoinMoin: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
3 # 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
4 # 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
5 # 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
6 # 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
7 # 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
8 # 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
9
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
10 """
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
11 MoinMoin - high-level (frontend) 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
12
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
13 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
14 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
15 e.g. showing, editing, etc. of wiki items.
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
16
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
17 Each class in this module corresponds to an itemtype.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
18 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
19
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
20 import re, time
486
b6149c732926 contenttype filtering added to global index page
Akash Sinha <akash2607@gmail.com>
parents: 484
diff changeset
21 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
22 from StringIO import StringIO
173
89f50aed143f move mimetype related code from wikiutil to util.mimetype
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 170
diff changeset
23
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
24 from flatland import Form
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
25 from flatland.validation import Validator
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
26
780
f5e0f85e66ce whooshify get_index()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 779
diff changeset
27 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
28
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
29 from MoinMoin.forms import RequiredText, OptionalText, OptionalMultilineText, Tags, Submit
242
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
30
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
31 from MoinMoin.security.textcha import TextCha, TextChaizedForm
242
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
32 from MoinMoin.signalling import item_modified
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
33 from MoinMoin.util.mime import Type
1005
c36f61f85e97 AccessDeniedError replaced by AccessDenied, from the new storage api.
Bruno Martin <bruno@hacklab.com.br>
parents: 1004
diff changeset
34 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
35
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
36 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
37 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
38
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
39 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
40 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
41 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
42 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
43
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 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
45 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
46
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
47 from flask import request, Response, redirect, abort, escape
242
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
48
0
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 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
50
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
51 from MoinMoin.i18n import L_
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
52 from MoinMoin.themes import render_template
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
53 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
54 from MoinMoin.storage.error import NoSuchItemError, NoSuchRevisionError, StorageError
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
55 from MoinMoin.util.registry import RegistryBase
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
56 from MoinMoin.constants.keys import (
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
57 NAME, NAME_OLD, NAME_EXACT, WIKINAME, MTIME, SYSITEM_VERSION, ITEMTYPE,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
58 CONTENTTYPE, SIZE, TAGS, ACTION, ADDRESS, HOSTNAME, USERID, COMMENT,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
59 HASH_ALGORITHM, ITEMID, REVID, DATAID, CURRENT, PARENTID
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
60 )
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
61 from MoinMoin.constants.contenttypes import charset, CONTENTTYPE_GROUPS
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
62
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
63 #from .content import content_registry
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
64
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
65
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
66 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
67 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
68
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
69
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
70 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
71 class Entry(object):
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
72 def __init__(self, factory, itemtype, priority):
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
73 self.factory = factory
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
74 self.itemtype = itemtype
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
75 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
76
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
77 def __call__(self, name, itemtype, kw):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
78 if self.itemtype == itemtype:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
79 return self.factory(name, itemtype, **kw)
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
80
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
81 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
82 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
83 return (self.factory == other.factory and
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
84 self.itemtype == other.itemtype and
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
85 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
86 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
87
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
88 def __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
89 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
90 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
91 return True
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
92 return self.itemtype == other.itemtype
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
93 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
94
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 def __repr__(self):
1389
522d2cea9ec8 Fix string formatting in RegistryItem.__repr__
DasIch <dasdasich@gmail.com>
parents: 1361
diff changeset
96 return '<{0}: {1}, prio {2} [{3!r}]>'.format(self.__class__.__name__,
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
97 self.itemtype,
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
98 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
99 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
100
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
101 def get(self, name, itemtype, **kw):
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
102 for entry in self._entries:
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
103 item = entry(name, itemtype, kw)
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
104 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
105 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
106
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
107 def register(self, factory, itemtype, priority=RegistryBase.PRIORITY_MIDDLE):
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
108 """
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 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
110
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 :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
112 """
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
113 return self._register(self.Entry(factory, itemtype, priority))
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
114
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
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
116 item_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
117
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
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
119 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
120 """ 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
121 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
122 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
123 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
124 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
125 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
126
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
127
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
128 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
129 """ 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
130 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
131 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
132 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
133 return [] # same as an empty Item
1180
1c5a013b9ebd Fix the three failing tests.
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1152
diff changeset
134 def destroy_all_revisions(self):
1c5a013b9ebd Fix the three failing tests.
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1152
diff changeset
135 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
136
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
137
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
138 # XXX To code reviewers: Code chunks within {{{ }}} were moved verbatim from
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
139 # somewhere else. Wherever I declare it to be "untouched", "untouched except
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
140 # for ..." I double checked by isolating the same chunk in old and new
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
141 # revisions and did a manual `diff` on that. FYI, the workflow is (in Vim):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
142
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
143 # 1. in the new revision select the chunk in visual line mode (V)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
144 # 2. :'<,'>w! /tmp/chunk.new
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
145 # 3. do the same with the old revision, writing to /tmp/chunk.old
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
146 # 4. :!diff /tmp/chunk.old /tmp/chunk.new
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
147
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
148 # So trust me :-P
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
149
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
150
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
151 # XXX Moved verbatim from below Item untouched {{{
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
152 class ValidJSON(Validator):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
153 """Validator for JSON
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
154 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
155 invalid_json_msg = L_('Invalid JSON.')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
156
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
157 def validate(self, element, state):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
158 try:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
159 json.loads(element.value)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
160 except:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
161 return self.note_error(element, state, 'invalid_json_msg')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
162 return True
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
163
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
164
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
165 class BaseChangeForm(TextChaizedForm):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
166 comment = OptionalText.using(label=L_('Comment')).with_properties(placeholder=L_("Comment about your change"))
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
167 submit = Submit
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
168 # }}}
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
169
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
170
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
171 class Item(object):
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
172 """ Highlevel (not storage) Item, wraps around a storage 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
173 @classmethod
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
174 def _factory(cls, name=u'', itemtype=None, **kw):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
175 return cls(name, **kw)
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
176
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
177 # TODO split Content creation to Content.create
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
178 @classmethod
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
179 def create(cls, name=u'', itemtype=None, contenttype=None, rev_id=CURRENT, item=None):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
180 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
181 Create a highlevel Item by looking up :name or directly wrapping
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
182 :item and extract the Revision designated by :rev_id revision.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
183
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
184 The highlevel Item is created by creating an instance of Content
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
185 subclass according to the item's contenttype metadata entry; The
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
186 :contenttype argument can be used to override contenttype. It is used
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
187 only when handling +convert (when deciding the contenttype of target
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
188 item), +modify (when creating a new item whose contenttype is not yet
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
189 decided), +diff and +diffraw (to coerce the Content to a common
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
190 super-contenttype of both revisions).
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
191
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
192 After that the Content instance, an instance of Item subclass is
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
193 created according to the item's itemtype metadata entry, and the
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
194 previously created Content instance is assigned to its content
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
195 property.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
196 """
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 204
diff changeset
197 if contenttype is None:
415
d755f798fe66 fix some tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 402
diff changeset
198 contenttype = u'application/x-nonexistent'
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
199 if itemtype is None:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
200 itemtype = u'nonexistent'
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
201 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
202 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
203 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
204 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
205 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
206 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
207 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
208 item = DummyItem(name)
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 204
diff changeset
209 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
210 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
211 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
212 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
213 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
214 rev = item.get_revision(rev_id)
415
d755f798fe66 fix some tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 402
diff changeset
215 contenttype = u'application/octet-stream' # it exists
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
216 itemtype = u'default' # default itemtype to u'default' for compatibility
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
217 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
218 try:
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
219 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
220 # 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
221 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
222 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
223 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
224 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
225 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
226 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
227 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
228 #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
229
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
230 # XXX Cannot pass item=item to Content.__init__ via
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
231 # content_registry.get yet, have to patch it later.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
232 content = content_registry.get(name, Type(contenttype))
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
233 logging.debug("Content class {0!r} handles {1!r}".format(content.__class__, contenttype))
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
234
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
235 itemtype = rev.meta.get(ITEMTYPE) or itemtype
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
236 logging.debug("Item {0!r}, got itemtype {1!r} from revision meta".format(name, itemtype))
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
237
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
238 item = item_registry.get(name, itemtype, rev=rev, content=content)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
239 logging.debug("Item class {0!r} handles {1!r}".format(item.__class__, itemtype))
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
240
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
241 content.item = item
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
242
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
243 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
244
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
245 def __init__(self, name, rev=None, content=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
246 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
247 self.rev = rev
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
248 self.content = 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
249
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
250 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
251 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
252 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
253
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
254 # XXX Backward compatibility, remove soon
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
255 @property
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
256 def contenttype(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
257 return self.content.contenttype if self.content else 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
258
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
259 def _render_meta(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
260 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
261
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
262 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
263 """ 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
264 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
265 SYSITEM_VERSION,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
266 NAME_OLD,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
267 # are automatically implanted when saving
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
268 NAME,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
269 ITEMID, REVID, DATAID,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
270 HASH_ALGORITHM,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
271 SIZE,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
272 COMMENT,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
273 MTIME,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
274 ACTION,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
275 ADDRESS, HOSTNAME, USERID,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
276 ]
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 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
278 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
279 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
280
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
281 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
282 """ 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
283 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
284 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
285
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
286 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
287 """ 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
288 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
289 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
290 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
291 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
292
892
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
293 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
294 """
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
295 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
296 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
297 """
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
298 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
299 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
300 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
301 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
302 return meta
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
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 _rename(self, name, comment, action):
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
305 self._save(self.meta, self.content.data, name=name, action=action, comment=comment)
1019
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
306 for child in self.get_index():
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
307 item = Item.create(child[0])
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
308 item._save(item.meta, item.content.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
309
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
310 def 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
311 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
312 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
313 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
314 return 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
315
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
316 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
317 """
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
318 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
319 """
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
320 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
321 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
322 # 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
323 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
324 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
325
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
326 def revert(self, comment=u''):
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
327 return self._save(self.meta, self.content.data, action=u'REVERT', 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
328
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
329 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
330 # 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
331 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
332 # destroy complete item with all revisions, metadata, etc.
910
5b7e522d97af fix destroy
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 908
diff changeset
333 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
334 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
335 # just destroy this revision
910
5b7e522d97af fix destroy
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 908
diff changeset
336 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
337
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
338 def modify(self, meta, data, comment=u'', contenttype_guessed=None, contenttype_qs=None):
236
7a77ae08161e items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 225
diff changeset
339 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
340 # 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
341 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
342
7a77ae08161e items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 225
diff changeset
343 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
344
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
345 class _ModifyForm(BaseChangeForm):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
346 """Base class for ModifyForm of Item subclasses."""
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
347 meta_text = OptionalMultilineText.using(label=L_("MetaData (JSON)")).with_properties(rows=ROWS_META, cols=COLS).validated_by(ValidJSON())
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
348
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
349 def _load(self, item):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
350 self['meta_text'] = item.meta_dict_to_text(item.prepare_meta_for_modify(item.meta))
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
351 self['content_form']._load(item.content)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
352
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
353 def _dump(self, item):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
354 meta = item.meta_text_to_dict(self['meta_text'].value)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
355 data, contenttype_guessed = self['content_form']._dump(item.content)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
356 comment = self['comment'].value
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
357 return meta, data, contenttype_guessed, comment
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
358
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
359 @classmethod
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
360 def from_item(cls, item):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
361 form = cls.from_defaults()
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
362 TextCha(form).amend_form()
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
363 form._load(item)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
364 return form
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
365
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
366 @classmethod
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
367 def from_request(cls, request):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
368 form = cls.from_flat(request.form.items() + request.files.items())
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
369 TextCha(form).amend_form()
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
370 return form
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
371
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
372 def do_modify(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
373 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
374 Handle +modify requests, both GET and POST.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
375
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
376 This method should be overridden in subclasses, providing polymorphic
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
377 behavior for the +modify view.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
378 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
379 raise NotImplementedError
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
380
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
381 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
382 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
383 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
384 try:
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
385 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
386 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
387 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
388 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
389 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
390 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
391 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
392
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
393 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
394
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
395 # 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
396 # 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
397 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
398 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
399 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
400 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
401 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
402 meta[NAME] = name
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
403
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
404 if comment:
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
405 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
406
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
407 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
408 # 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
409 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
410
236
7a77ae08161e items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 225
diff changeset
411 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
412 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
413 # 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
414 # 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
415 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
416 else:
f464adcc3a51 fix saving no data if no previous revision exists
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 236
diff changeset
417 data = ''
236
7a77ae08161e items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 225
diff changeset
418
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
419 if isinstance(data, unicode):
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
420 data = data.encode(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
421
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
422 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
423 data = StringIO(data)
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
424
1266
1c66f39aa44f implement validation for revision metadata storage using flatland
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1236
diff changeset
425 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
426 action=unicode(action),
1c66f39aa44f implement validation for revision metadata storage using flatland
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1236
diff changeset
427 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
428 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
429 )
242
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
430 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
431 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
432
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
433 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
434 """ 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
435 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
436 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
437 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
438 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
439 # 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
440 # 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
441 prefix = u''
827
94e388cd4e28 use 'constants' for metadata keys / whoosh field names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 794
diff changeset
442 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
443 # 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
444 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
445 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
446 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
447 for rev in revs]
780
f5e0f85e66ce whooshify get_index()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 779
diff changeset
448 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
449
993
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
450 def _connect_levels(self, index):
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
451 new_index = []
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
452 last = self.name
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
453 for item in index:
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
454 name = item[0]
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
455
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
456 while not name.startswith(last):
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
457 last = last.rpartition('/')[0]
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
458
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
459 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
460
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
461 for layer in missing_layers:
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
462 last = '/'.join([last, layer])
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
463 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
464
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
465 last = item[0]
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
466 new_index.append(item)
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
467
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
468 return new_index
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
469
486
b6149c732926 contenttype filtering added to global index page
Akash Sinha <akash2607@gmail.com>
parents: 484
diff changeset
470 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
471 """
993
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
472 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
473 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
474 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
475 """
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
476 index = self.get_index()
993
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
477 index = self._connect_levels(index)
486
b6149c732926 contenttype filtering added to global index page
Akash Sinha <akash2607@gmail.com>
parents: 484
diff changeset
478
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
479 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
480 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
481 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
482 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
483 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
484 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
485 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
486 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
487
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
488 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
489 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
490 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
491 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
492 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
493 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
494 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
495 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
496 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
497 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
498 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
499 selected_contenttypes = all_contenttypes
486
b6149c732926 contenttype filtering added to global index page
Akash Sinha <akash2607@gmail.com>
parents: 484
diff changeset
500
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
501 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
502 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
503 startswith = (u'{0}'.format(startswith), u'{0}'.format(startswith.swapcase()))
520
6332dda59cb6 some pep8 fixes
Akash Sinha <akash2607@gmail.com>
parents: 518
diff changeset
504 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
505 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
506 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
507 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
508 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
509 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
510 # 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
511 # 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
512 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
513 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
514 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
515 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
516 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
517 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
518
477
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 257
diff changeset
519 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
520 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
521 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
522 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
523 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
524 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
525 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
526 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
527 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
528 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
529 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
530
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
531 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
532
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
533 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
534
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
535 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
536 """ 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
537 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
538 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
539 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
540 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
541 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
542 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
543 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
544 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
545 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
546 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
547 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
548
477
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 257
diff changeset
549 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
550 initials = [(name[1][0])
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 257
diff changeset
551 for name in names]
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 257
diff changeset
552 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
553
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
554 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
555 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
556 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
557 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
558 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
559
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
560
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
561 class Contentful(Item):
245
52ca5dc1ab15 add a JSON validator, use it to validate meta_text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 244
diff changeset
562 """
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
563 Base class for Item subclasses that have content.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
564 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
565 @property
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
566 def ModifyForm(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
567 class C(Item._ModifyForm):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
568 content_form = self.content.ModifyForm
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
569 C.__name__ = 'ModifyForm'
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
570 return C
1420
100197cb69ab Convert Flatland forms to contain rendering hints.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1408
diff changeset
571
100197cb69ab Convert Flatland forms to contain rendering hints.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1408
diff changeset
572
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
573 # TODO better name and clearer definition
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
574 class Default(Contentful):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
575 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
576 A "conventional" wiki item.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
577 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
578 # XXX this method was moved from Item, untouched except for the addition
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
579 # of itemtype keyword argument plus the comment above it.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
580 def _do_modify_show_templates(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
581 # call this if the item is still empty
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
582 rev_ids = []
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
583 item_templates = self.content.get_templates(self.contenttype)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
584 return render_template('modify_show_template_selection.html',
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
585 item_name=self.name,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
586 # XXX avoid the magic string
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
587 itemtype=u'default',
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
588 rev=self.rev,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
589 contenttype=self.contenttype,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
590 templates=item_templates,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
591 first_rev_id=rev_ids and rev_ids[0],
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
592 last_rev_id=rev_ids and rev_ids[-1],
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
593 meta_rendered='',
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
594 data_rendered='',
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
595 )
242
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
596
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
597 # To code reviewers: this method was mostly merged from Item.do_modify and
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
598 # Draw, with modifications.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
599 def do_modify(self):
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
600 method = request.method
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
601 if method == 'GET':
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
602 if isinstance(self.content, NonExistentContent):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
603 return render_template('modify_show_contenttype_selection.html',
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
604 item_name=self.name,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
605 # XXX avoid the magic string
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
606 itemtype=u'default',
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
607 contenttype_groups=CONTENTTYPE_GROUPS,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
608 )
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
609 item = self
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
610 if isinstance(self.rev, DummyRev):
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
611 template_name = request.values.get('template')
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
612 if template_name is None:
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
613 return self._do_modify_show_templates()
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
614 elif template_name:
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
615 item = Item.create(template_name)
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
616 form = self.ModifyForm.from_item(item)
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
617 elif method == 'POST':
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
618 # XXX workaround for *Draw items
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
619 if isinstance(self.content, Draw):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
620 try:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
621 self.content.handle_post()
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
622 except AccessDenied:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
623 abort(403)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
624 else:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
625 # *Draw Applets POSTs more than once, redirecting would
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
626 # break them
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
627 return "OK"
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
628 form = self.ModifyForm.from_request(request)
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
629 if form.validate():
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
630 meta, data, contenttype_guessed, comment = form._dump(self)
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
631 contenttype_qs = request.values.get('contenttype')
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
632 try:
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
633 self.modify(meta, data, comment, contenttype_guessed, contenttype_qs)
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
634 except AccessDenied:
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
635 abort(403)
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
636 else:
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
637 return redirect(url_for_item(self.name))
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
638 return render_template(self.modify_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
639 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
640 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
641 form=form,
1229
29301b8a2718 Hide search box in modify views.
Sam Toyer <samATqxcvDOTnet>
parents: 1214
diff changeset
642 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
643 )
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
644
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
645 modify_template = 'modify.html'
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
646
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
647 item_registry.register(Default._factory, u'default')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
648
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
649
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
650 class Ticket(Contentful):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
651 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
652 Stub for ticket item class.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
653 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
654
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
655 item_registry.register(Ticket._factory, u'ticket')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
656
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
657
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
658 class Userprofile(Item):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
659 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
660 Currently userprofile is implemented as a contenttype. This is a stub of an
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
661 itemtype implementation of userprofile.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
662 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
663
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
664 item_registry.register(Userprofile._factory, u'userprofile')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
665
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
666
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
667 class NonExistent(Item):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
668 def _convert(self, doc):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
669 abort(404)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
670
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
671 def do_modify(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
672 # First, check if the current user has the required privileges
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
673 if not flaskg.user.may.create(self.name):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
674 abort(403)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
675
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
676 # TODO Construct this list from the item_registry. Two more fields (ie.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
677 # display name and description) are needed in the registry then to
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
678 # support the automatic construction.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
679 ITEMTYPES = [
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
680 (u'default', u'Default', 'Wiki item'),
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
681 (u'ticket', u'Ticket', 'Ticket item'),
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
682 ]
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
683
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
684 return render_template('modify_show_itemtype_selection.html',
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
685 item_name=self.name,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
686 itemtypes=ITEMTYPES,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
687 )
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
688
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
689 item_registry.register(NonExistent._factory, u'nonexistent')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
690
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
691
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
692 # This should be a separate module items/content.py. Included here to
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
693 # faciliate codereview.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
694 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
695 MoinMoin - item contents
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
696
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
697 Classes handling the content part of items (ie. minus metadata). The
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
698 content part is sometimes called the "data" part in other places, but is
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
699 always called content in this module to avoid confusion.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
700
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
701 Each class in this module corresponds to a contenttype value.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
702 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
703
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
704 import os, re, base64
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
705 import tarfile
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
706 import zipfile
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
707 import tempfile
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
708 from StringIO import StringIO
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
709 from array import array
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
710
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
711 from flatland import Form, String
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
712
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
713 from whoosh.query import Term, And
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
714
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
715 from MoinMoin.forms import File
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
716
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
717 from MoinMoin.util.mimetype import MimeType
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
718 from MoinMoin.util.mime import Type, type_moin_document
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
719 from MoinMoin.util.tree import moin_page, html, xlink, docbook
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
720 from MoinMoin.util.iri import Iri
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
721 from MoinMoin.util.crypto import cache_key
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
722 from MoinMoin.storage.middleware.protecting import AccessDenied
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
723
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
724 try:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
725 import PIL
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
726 from PIL import Image as PILImage
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
727 from PIL.ImageChops import difference as PILdiff
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
728 except ImportError:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
729 PIL = None
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
730
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
731 from MoinMoin import log
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
732 logging = log.getLogger(__name__)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
733
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
734 from flask import current_app as app
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
735 from flask import g as flaskg
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
736
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
737 from flask import request, url_for, Response, abort, escape
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
738
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
739 from jinja2 import Markup
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
740
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
741 from MoinMoin.i18n import _, L_
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
742 from MoinMoin.themes import render_template
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
743 from MoinMoin import wikiutil, config
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
744 from MoinMoin.util.send_file import send_file
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
745 from MoinMoin.util.interwiki import url_for_item
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
746 from MoinMoin.storage.error import StorageError
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
747 from MoinMoin.util.registry import RegistryBase
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
748 from MoinMoin.constants.keys import (
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
749 NAME, NAME_EXACT, WIKINAME, CONTENTTYPE, SIZE, TAGS, HASH_ALGORITHM
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
750 )
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
751
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
752
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
753 COLS = 80
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
754 ROWS_DATA = 20
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
755
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
756
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
757 # XXX Too much boilerplate in Entry implementation. Maybe use namedtuple
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
758 # as a starting point?
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
759 # Renamed from old RegistryItem, whole class untouched
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
760 class RegistryContent(RegistryBase):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
761 class Entry(object):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
762 def __init__(self, factory, content_type, priority):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
763 self.factory = factory
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
764 self.content_type = content_type
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
765 self.priority = priority
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
766
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
767 def __call__(self, name, content_type, kw):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
768 if self.content_type.issupertype(content_type):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
769 return self.factory(name, content_type, **kw)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
770
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
771 def __eq__(self, other):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
772 if isinstance(other, self.__class__):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
773 return (self.factory == other.factory and
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
774 self.content_type == other.content_type and
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
775 self.priority == other.priority)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
776 return NotImplemented
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
777
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
778 def __lt__(self, other):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
779 if isinstance(other, self.__class__):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
780 if self.priority < other.priority:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
781 return True
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
782 if self.content_type != other.content_type:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
783 return other.content_type.issupertype(self.content_type)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
784 return False
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
785 return NotImplemented
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
786
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
787 def __repr__(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
788 return '<{0}: {1}, prio {2} [{3!r}]>'.format(self.__class__.__name__,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
789 self.content_type,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
790 self.priority,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
791 self.factory)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
792
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
793 def get(self, name, content_type, **kw):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
794 for entry in self._entries:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
795 item = entry(name, content_type, kw)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
796 if item is not None:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
797 return item
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
798
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
799 def register(self, factory, content_type, priority=RegistryBase.PRIORITY_MIDDLE):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
800 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
801 Register a factory
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
802
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
803 :param factory: Factory to register. Callable, must return an object.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
804 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
805 return self._register(self.Entry(factory, content_type, priority))
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
806
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
807
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
808 content_registry = RegistryContent()
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
809
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
810
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
811 def conv_serialize(doc, namespaces, method='polyglot'):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
812 out = array('u')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
813 flaskg.clock.start('conv_serialize')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
814 doc.write(out.fromunicode, namespaces=namespaces, method=method)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
815 out = out.tounicode()
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
816 flaskg.clock.stop('conv_serialize')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
817 return out
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
818
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
819
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
820 class Content(object):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
821 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
822 Base for content classes defining some helpers, agnostic about content
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
823 data.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
824 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
825 @classmethod
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
826 def _factory(cls, name=u'', contenttype=None, **kw):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
827 return cls(name, contenttype=unicode(contenttype), **kw)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
828
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
829 def __init__(self, item, contenttype=None):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
830 self.item = item
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
831 # TODO gradually remove self.contenttype as theoretically there is
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
832 # one-to-one correspondance of contenttype and Content type
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
833 # (pun intended :)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
834 self.contenttype = contenttype
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
835
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
836 # XXX For backward-compatibility (so code can be moved from Item
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
837 # untouched), remove soon
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
838 @property
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
839 def rev(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
840 return self.item.rev
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
841
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
842 @property
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
843 def name(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
844 return self.item.name
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
845
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
846 def get_data(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
847 return '' # TODO create a better method for binary stuff
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
848 data = property(fget=get_data)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
849
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
850 # Moved from Item, untouched {{{
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
851 def internal_representation(self, converters=['smiley']):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
852 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
853 Return the internal representation of a document using a DOM Tree
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
854 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
855 flaskg.clock.start('conv_in_dom')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
856 hash_name = HASH_ALGORITHM
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
857 hash_hexdigest = self.rev.meta.get(hash_name)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
858 if hash_hexdigest:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
859 cid = cache_key(usage="internal_representation",
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
860 hash_name=hash_name,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
861 hash_hexdigest=hash_hexdigest)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
862 doc = app.cache.get(cid)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
863 else:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
864 # likely a non-existing item
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
865 doc = cid = None
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
866 if doc is None:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
867 # We will see if we can perform the conversion:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
868 # FROM_mimetype --> DOM
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
869 # if so we perform the transformation, otherwise we don't
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
870 from MoinMoin.converter import default_registry as reg
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
871 input_conv = reg.get(Type(self.contenttype), type_moin_document)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
872 if not input_conv:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
873 raise TypeError("We cannot handle the conversion from {0} to the DOM tree".format(self.contenttype))
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
874 smiley_conv = reg.get(type_moin_document, type_moin_document,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
875 icon='smiley')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
876
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
877 # We can process the conversion
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
878 links = Iri(scheme='wiki', authority='', path='/' + self.name)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
879 doc = input_conv(self.rev, self.contenttype)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
880 # XXX is the following assuming that the top element of the doc tree
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
881 # is a moin_page.page element? if yes, this is the wrong place to do that
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
882 # as not every doc will have that element (e.g. for images, we just get
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
883 # moin_page.object, for a tar item, we get a moin_page.table):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
884 doc.set(moin_page.page_href, unicode(links))
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
885 for conv in converters:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
886 if conv == 'smiley':
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
887 doc = smiley_conv(doc)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
888 if cid:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
889 app.cache.set(cid, doc)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
890 flaskg.clock.stop('conv_in_dom')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
891 return doc
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
892
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
893 def _expand_document(self, doc):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
894 from MoinMoin.converter import default_registry as reg
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
895 include_conv = reg.get(type_moin_document, type_moin_document, includes='expandall')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
896 macro_conv = reg.get(type_moin_document, type_moin_document, macros='expandall')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
897 link_conv = reg.get(type_moin_document, type_moin_document, links='extern')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
898 flaskg.clock.start('conv_include')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
899 doc = include_conv(doc)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
900 flaskg.clock.stop('conv_include')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
901 flaskg.clock.start('conv_macro')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
902 doc = macro_conv(doc)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
903 flaskg.clock.stop('conv_macro')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
904 flaskg.clock.start('conv_link')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
905 doc = link_conv(doc)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
906 flaskg.clock.stop('conv_link')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
907 return doc
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
908
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
909 def _render_data(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
910 from MoinMoin.converter import default_registry as reg
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
911 # TODO: Real output format
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
912 doc = self.internal_representation()
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
913 doc = self._expand_document(doc)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
914 flaskg.clock.start('conv_dom_html')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
915 html_conv = reg.get(type_moin_document, Type('application/x-xhtml-moin-page'))
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
916 doc = html_conv(doc)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
917 flaskg.clock.stop('conv_dom_html')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
918 rendered_data = conv_serialize(doc, {html.namespace: ''})
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
919 return rendered_data
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
920
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
921 def _render_data_xml(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
922 doc = self.internal_representation()
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
923 return conv_serialize(doc,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
924 {moin_page.namespace: '',
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
925 xlink.namespace: 'xlink',
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
926 html.namespace: 'html',
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
927 },
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
928 'xml')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
929
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
930 def _render_data_highlight(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
931 # override this in child classes
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
932 return ''
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
933 # }}}
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
934
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
935 # Moved from Binary, untouched {{{
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
936 def get_templates(self, contenttype=None):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
937 """ create a list of templates (for some specific contenttype) """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
938 terms = [Term(WIKINAME, app.cfg.interwikiname), Term(TAGS, u'template')]
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
939 if contenttype is not None:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
940 terms.append(Term(CONTENTTYPE, contenttype))
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
941 query = And(terms)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
942 revs = flaskg.storage.search(query, sortedby=NAME_EXACT, limit=None)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
943 return [rev.meta[NAME] for rev in revs]
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
944 # }}}
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
945
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
946
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
947 class NonExistentContent(Content):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
948 """Dummy Content to use with NonExistent."""
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
949 def do_get(self, force_attachment=False, mimetype=None):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
950 abort(404)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
951
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
952 def _convert(self, doc):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
953 abort(404)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
954
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
955
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
956 content_registry.register(NonExistentContent._factory, Type('application/x-nonexistent'))
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
957
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
958
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
959 class Binary(Content):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
960 """ An arbitrary binary item, fallback class for every item mimetype. """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
961
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
962 # XXX reads item rev data into memory!
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
963 def get_data(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
964 if self.rev is not None:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
965 return self.rev.data.read()
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
966 else:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
967 return ''
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
968 data = property(fget=get_data)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
969
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
970 class ModifyForm(Form):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
971 template = 'modify_binary.html'
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
972 help = """\
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
973 There is no help, you're doomed!
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
974 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
975 data_file = File.using(optional=True, label=L_('Upload file:'))
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
976
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
977 def _load(self, item):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
978 pass
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
979
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
980 def _dump(self, item):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
981 data_file = self['data_file'].value
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
982 if data_file:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
983 data = data_file.stream
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
984 # this is likely a guess by the browser, based on the filename
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
985 contenttype_guessed = data_file.content_type # comes from form multipart data
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
986 return data, contenttype_guessed
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
987 else:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
988 return None, None
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
989
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
990 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
991 hash_name = HASH_ALGORITHM
860
de6ece090b7d fix download view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
992 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
993 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
994 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
995 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
996
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
997 _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
998 _render_data_diff_raw = _render_data_diff
1211
e63c9c8d0ad9 Move revision info to the end
Shitiz Garg <mail@dragooon.net>
parents: 1210
diff changeset
999
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
1000 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
1001 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
1002 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
1003 content=Markup(self._render_data()))
1198
2aa4f4ec6a94 Minor fixes for atom feed
Shitiz Garg <mail@dragooon.net>
parents: 1197
diff changeset
1004
1099
2068f99501c5 fix a few bugs exposed by the new view tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1023
diff changeset
1005 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
1006 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
1007 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
1008
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
1009 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
1010 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
1011 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
1012 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
1013 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1014 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
1015
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
1016 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
1017 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
1018 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
1019
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
1020 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
1021 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
1022 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
1023 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
1024 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
1025 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
1026 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
1027 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
1028 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
1029 try:
860
de6ece090b7d fix download view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
1030 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
1031 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
1032 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
1033 else:
faa06b4873dd more contenttype related changes/fixes, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 216
diff changeset
1034 mt = MimeType(mimestr=mimestr)
860
de6ece090b7d fix download view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
1035 content_length = rev.meta[SIZE]
de6ece090b7d fix download view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
1036 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
1037 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
1038 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
1039 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
1040 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
1041 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
1042 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
1043 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
1044 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
1045 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
1046 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
1047
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
1048 content_registry.register(Binary._factory, Type('*/*'))
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
1049
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1050
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1051 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
1052 """ 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
1053
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1054
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1055 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
1056 """ 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
1057
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1058
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1059 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
1060 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1061 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
1062 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
1063 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1064 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
1065 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1066 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
1067 """
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
1068 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
1069 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
1070 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
1071
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1072 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
1073 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1074 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
1075
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
1076 :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
1077 """
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
1078 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
1079 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
1080 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
1081
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1082 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
1083 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1084 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
1085 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
1086 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
1087
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
1088 :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
1089 :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
1090 :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
1091 :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
1092 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1093 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
1094 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
1095 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
1096 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
1097 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
1098 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
1099 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
1100 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
1101 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
1102 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
1103 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
1104 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
1105 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
1106 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
1107 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
1108 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
1109 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
1110 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
1111 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
1112 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
1113 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
1114 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
1115 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
1116 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
1117 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
1118 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
1119 # 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
1120 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
1121 data = open(temp_fname, 'rb')
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
1122 self.item._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
1123 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
1124 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
1125
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1126
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1127 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
1128 """
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
1129 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
1130 """
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
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
1132 content_registry.register(ApplicationXTar._factory, Type('application/x-tar'))
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
1133 content_registry.register(ApplicationXTar._factory, Type('application/x-gtar'))
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
1134
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1135
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1136 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
1137 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1138 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
1139 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
1140 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1141 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
1142 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1143 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
1144 """
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
1145 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
1146 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
1147 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
1148
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1149 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
1150 """
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 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
1152
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
1153 :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
1154 """
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
1155 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
1156 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
1157 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
1158
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1159 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
1160 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
1161
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1162
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1163 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
1164 """
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
1165 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
1166 """
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1167
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
1168 content_registry.register(ApplicationZip._factory, Type('application/zip'))
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
1169
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1170
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1171 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
1172 """ 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
1173
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
1174 content_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
1175
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1176
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1177 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
1178 """ 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
1179
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
1180 content_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
1181
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1182
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1183 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
1184 """ 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
1185
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
1186 content_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
1187
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1188
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1189 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
1190 """ Base class for image/* """
1214
8d547ec39a76 Cosmetic changes
Shitiz Garg <mail@dragooon.net>
parents: 1213
diff changeset
1191
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
1192 content_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
1193
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1194
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1195 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
1196 """ 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
1197
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1198
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1199 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
1200 """ 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
1201
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
1202 content_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
1203
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 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
1206 """ 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
1207 # 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
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
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1210 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
1211 """ 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
1212 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
1213 """ 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
1214 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
1215 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1216 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1217 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
1218 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
1219 # 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
1220 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
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 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
1223 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
1224 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
1225 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
1226 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
1227 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
1228 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
1229 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
1230
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1231 # 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
1232 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
1233 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
1234
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1235 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1236 # 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
1237 # 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
1238 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
1239 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
1240 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
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 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
1243 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
1244 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
1245
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1246 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
1247 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
1248 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
1249 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
1250 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
1251 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
1252 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
1253 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
1254 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
1255 }
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1256 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
1257
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1258 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
1259 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
1260 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
1261 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
1262 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
1263
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
1264 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
1265 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1266 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
1267 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
1268 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
1269 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1270 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
1271 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
1272 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
1273 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1274 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
1275 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
1276 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
1277 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
1278 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
1279 # 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
1280 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
1281 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
1282 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
1283 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
1284 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
1285 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
1286 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
1287 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
1288 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
1289 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
1290 else:
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
1291 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
1292 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
1293 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
1294 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
1295 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
1296 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1297 # 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
1298 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
1299 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
1300 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
1301 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
1302
1209
c0eaed311e0e Try using PIL for image diffs
Shitiz Garg <mail@dragooon.net>
parents: 1208
diff changeset
1303 def _render_data_diff_atom(self, oldrev, newrev):
c0eaed311e0e Try using PIL for image diffs
Shitiz Garg <mail@dragooon.net>
parents: 1208
diff changeset
1304 if PIL is None:
c0eaed311e0e Try using PIL for image diffs
Shitiz Garg <mail@dragooon.net>
parents: 1208
diff changeset
1305 # 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
1306 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
1307 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
1308 return render_template('atom.html',
c0eaed311e0e Try using PIL for image diffs
Shitiz Garg <mail@dragooon.net>
parents: 1208
diff changeset
1309 oldrev=oldrev, newrev=newrev, get='binary',
1409
ac1059572d80 use unicode object for .format() operation to avoid unicode issues, fixes #198
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1408
diff changeset
1310 content=Markup(u'<img src="{0}" />'.format(escape(url))))
1209
c0eaed311e0e Try using PIL for image diffs
Shitiz Garg <mail@dragooon.net>
parents: 1208
diff changeset
1311
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1312 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
1313 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
1314 # 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
1315 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
1316 url = url_for('frontend.diffraw', item_name=self.name, rev1=oldrev.revid, rev2=newrev.revid)
1409
ac1059572d80 use unicode object for .format() operation to avoid unicode issues, fixes #198
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1408
diff changeset
1317 return Markup(u'<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
1318
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1319 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
1320 hash_name = HASH_ALGORITHM
174
e8f61cbd661b modularize crypto/random stuff, move it to MoinMoin.util.crypto, pw change bugfix
Thomas&#