annotate MoinMoin/items/content.py @ 1454:7f85d95ec4e4

Split Content and derived claases to module items.content. Test cases were split too.
author Cheer Xiao <xiaqqaix@gmail.com>
date Sat, 28 Jul 2012 11:21:19 +0800
parents MoinMoin/items/__init__.py@accea307e94e
children fc1f874695e1
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 - item contents
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
12
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
13 Classes handling the content part of items (ie. minus metadata). The
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
14 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
15 always called content in this module to avoid confusion.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
16
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
17 Each class in this module corresponds to a contenttype value.
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 os, re, base64
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
21 import tarfile
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
22 import zipfile
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
23 import tempfile
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
24 from StringIO import StringIO
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
25 from array import array
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
26
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
27 from flatland import Form, String
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
28
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
29 from whoosh.query import Term, And
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
30
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
31 from MoinMoin.forms import File
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
32
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
33 from MoinMoin.util.mimetype import MimeType
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
34 from MoinMoin.util.mime import Type, type_moin_document
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
35 from MoinMoin.util.tree import moin_page, html, xlink, docbook
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
36 from MoinMoin.util.iri import Iri
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
37 from MoinMoin.util.crypto import cache_key
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
38 from MoinMoin.storage.middleware.protecting import AccessDenied
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
39
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
40 try:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
41 import PIL
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
42 from PIL import Image as PILImage
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
43 from PIL.ImageChops import difference as PILdiff
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
44 except ImportError:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
45 PIL = None
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
46
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
47 from MoinMoin import log
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
48 logging = log.getLogger(__name__)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
49
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
50 from flask import current_app as app
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
51 from flask import g as flaskg
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
52
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
53 from flask import request, url_for, Response, abort, escape
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
54
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
55 from jinja2 import Markup
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
56
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
57 from MoinMoin.i18n import _, L_
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
58 from MoinMoin.themes import render_template
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
59 from MoinMoin import wikiutil, config
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
60 from MoinMoin.util.send_file import send_file
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
61 from MoinMoin.util.interwiki import url_for_item
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
62 from MoinMoin.storage.error import StorageError
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
63 from MoinMoin.util.registry import RegistryBase
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
64 from MoinMoin.constants.keys import (
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
65 NAME, NAME_EXACT, WIKINAME, CONTENTTYPE, SIZE, TAGS, HASH_ALGORITHM
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
66 )
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
67
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
68
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
69 COLS = 80
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
70 ROWS_DATA = 20
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
71
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
72
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
73 # XXX Too much boilerplate in Entry implementation. Maybe use namedtuple
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
74 # as a starting point?
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
75 class RegistryContent(RegistryBase):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
76 class Entry(object):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
77 def __init__(self, factory, content_type, priority):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
78 self.factory = factory
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
79 self.content_type = content_type
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
80 self.priority = priority
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
81
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
82 def __call__(self, name, content_type, kw):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
83 if self.content_type.issupertype(content_type):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
84 return self.factory(name, content_type, **kw)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
85
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
86 def __eq__(self, other):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
87 if isinstance(other, self.__class__):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
88 return (self.factory == other.factory and
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
89 self.content_type == other.content_type and
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
90 self.priority == other.priority)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
91 return NotImplemented
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
92
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
93 def __lt__(self, other):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
94 if isinstance(other, self.__class__):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
95 if self.priority < other.priority:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
96 return True
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
97 if self.content_type != other.content_type:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
98 return other.content_type.issupertype(self.content_type)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
99 return False
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
100 return NotImplemented
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
101
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
102 def __repr__(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
103 return '<{0}: {1}, prio {2} [{3!r}]>'.format(self.__class__.__name__,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
104 self.content_type,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
105 self.priority,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
106 self.factory)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
107
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
108 def get(self, name, content_type, **kw):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
109 for entry in self._entries:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
110 item = entry(name, content_type, kw)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
111 if item is not None:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
112 return item
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
113
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
114 def register(self, factory, content_type, priority=RegistryBase.PRIORITY_MIDDLE):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
115 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
116 Register a factory
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
117
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
118 :param factory: Factory to register. Callable, must return an object.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
119 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
120 return self._register(self.Entry(factory, content_type, priority))
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
121
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
122
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
123 content_registry = RegistryContent()
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
124
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
125
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
126 def conv_serialize(doc, namespaces, method='polyglot'):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
127 out = array('u')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
128 flaskg.clock.start('conv_serialize')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
129 doc.write(out.fromunicode, namespaces=namespaces, method=method)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
130 out = out.tounicode()
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
131 flaskg.clock.stop('conv_serialize')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
132 return out
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
133
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
134
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
135 class Content(object):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
136 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
137 Base for content classes defining some helpers, agnostic about content
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
138 data.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
139 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
140 @classmethod
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
141 def _factory(cls, name=u'', contenttype=None, **kw):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
142 return cls(name, contenttype=unicode(contenttype), **kw)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
143
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
144 def __init__(self, item, contenttype=None):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
145 self.item = item
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
146 # TODO gradually remove self.contenttype as theoretically there is
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
147 # one-to-one correspondance of contenttype and Content type
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
148 # (pun intended :)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
149 self.contenttype = contenttype
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 For backward-compatibility (so code can be moved from Item
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
152 # untouched), remove soon
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
153 @property
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
154 def rev(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
155 return self.item.rev
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 @property
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
158 def name(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
159 return self.item.name
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
160
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
161 def get_data(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
162 return '' # TODO create a better method for binary stuff
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
163 data = property(fget=get_data)
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 def internal_representation(self, converters=['smiley']):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
166 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
167 Return the internal representation of a document using a DOM Tree
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 flaskg.clock.start('conv_in_dom')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
170 hash_name = HASH_ALGORITHM
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
171 hash_hexdigest = self.rev.meta.get(hash_name)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
172 if hash_hexdigest:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
173 cid = cache_key(usage="internal_representation",
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
174 hash_name=hash_name,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
175 hash_hexdigest=hash_hexdigest)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
176 doc = app.cache.get(cid)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
177 else:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
178 # likely a non-existing item
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
179 doc = cid = None
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
180 if doc is None:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
181 # We will see if we can perform the conversion:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
182 # FROM_mimetype --> DOM
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
183 # if so we perform the transformation, otherwise we don't
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
184 from MoinMoin.converter import default_registry as reg
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
185 input_conv = reg.get(Type(self.contenttype), type_moin_document)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
186 if not input_conv:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
187 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
188 smiley_conv = reg.get(type_moin_document, type_moin_document,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
189 icon='smiley')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
190
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
191 # We can process the conversion
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
192 links = Iri(scheme='wiki', authority='', path='/' + self.name)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
193 doc = input_conv(self.rev, self.contenttype)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
194 # 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
195 # 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
196 # 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
197 # 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
198 doc.set(moin_page.page_href, unicode(links))
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
199 for conv in converters:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
200 if conv == 'smiley':
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
201 doc = smiley_conv(doc)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
202 if cid:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
203 app.cache.set(cid, doc)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
204 flaskg.clock.stop('conv_in_dom')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
205 return doc
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
206
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
207 def _expand_document(self, doc):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
208 from MoinMoin.converter import default_registry as reg
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
209 include_conv = reg.get(type_moin_document, type_moin_document, includes='expandall')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
210 macro_conv = reg.get(type_moin_document, type_moin_document, macros='expandall')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
211 link_conv = reg.get(type_moin_document, type_moin_document, links='extern')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
212 flaskg.clock.start('conv_include')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
213 doc = include_conv(doc)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
214 flaskg.clock.stop('conv_include')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
215 flaskg.clock.start('conv_macro')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
216 doc = macro_conv(doc)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
217 flaskg.clock.stop('conv_macro')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
218 flaskg.clock.start('conv_link')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
219 doc = link_conv(doc)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
220 flaskg.clock.stop('conv_link')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
221 return doc
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
222
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
223 def _render_data(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
224 from MoinMoin.converter import default_registry as reg
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
225 # TODO: Real output format
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
226 doc = self.internal_representation()
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
227 doc = self._expand_document(doc)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
228 flaskg.clock.start('conv_dom_html')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
229 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
230 doc = html_conv(doc)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
231 flaskg.clock.stop('conv_dom_html')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
232 rendered_data = conv_serialize(doc, {html.namespace: ''})
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
233 return rendered_data
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 def _render_data_xml(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
236 doc = self.internal_representation()
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
237 return conv_serialize(doc,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
238 {moin_page.namespace: '',
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
239 xlink.namespace: 'xlink',
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
240 html.namespace: 'html',
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
241 },
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
242 'xml')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
243
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
244 def _render_data_highlight(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
245 # override this in child classes
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
246 return ''
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
247
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
248 def get_templates(self, contenttype=None):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
249 """ create a list of templates (for some specific contenttype) """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
250 terms = [Term(WIKINAME, app.cfg.interwikiname), Term(TAGS, u'template')]
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
251 if contenttype is not None:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
252 terms.append(Term(CONTENTTYPE, contenttype))
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
253 query = And(terms)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
254 revs = flaskg.storage.search(query, sortedby=NAME_EXACT, limit=None)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
255 return [rev.meta[NAME] for rev in revs]
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
256
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
257
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
258 class NonExistentContent(Content):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
259 """Dummy Content to use with NonExistent."""
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
260 def do_get(self, force_attachment=False, mimetype=None):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
261 abort(404)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
262
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
263 def _convert(self, doc):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
264 abort(404)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
265
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
266
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
267 content_registry.register(NonExistentContent._factory, Type('application/x-nonexistent'))
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
268
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
269
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
270 class Binary(Content):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
271 """ An arbitrary binary item, fallback class for every item mimetype. """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
272
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
273 # XXX reads item rev data into memory!
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
274 def get_data(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
275 if self.rev is not None:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
276 return self.rev.data.read()
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
277 else:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
278 return ''
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
279 data = property(fget=get_data)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
280
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
281 class ModifyForm(Form):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
282 template = 'modify_binary.html'
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
283 help = """\
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
284 There is no help, you're doomed!
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
285 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
286 data_file = File.using(optional=True, label=L_('Upload file:'))
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
287
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
288 def _load(self, item):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
289 pass
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
290
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
291 def _dump(self, item):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
292 data_file = self['data_file'].value
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
293 if data_file:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
294 data = data_file.stream
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
295 # this is likely a guess by the browser, based on the filename
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
296 contenttype_guessed = data_file.content_type # comes from form multipart data
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
297 return data, contenttype_guessed
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
298 else:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
299 return None, None
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
300
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
301 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
302 hash_name = HASH_ALGORITHM
860
de6ece090b7d fix download view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
303 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
304 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
305 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
306 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
307
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
308 _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
309 _render_data_diff_raw = _render_data_diff
1211
e63c9c8d0ad9 Move revision info to the end
Shitiz Garg <mail@dragooon.net>
parents: 1210
diff changeset
310
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
311 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
312 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
313 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
314 content=Markup(self._render_data()))
1198
2aa4f4ec6a94 Minor fixes for atom feed
Shitiz Garg <mail@dragooon.net>
parents: 1197
diff changeset
315
1099
2068f99501c5 fix a few bugs exposed by the new view tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1023
diff changeset
316 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
317 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
318 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
319
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
320 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
321 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
322 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
323 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
324 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
325 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
326
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
327 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
328 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
329 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
330
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
331 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
332 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
333 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
334 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
335 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
336 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
337 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
338 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
339 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
340 try:
860
de6ece090b7d fix download view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
341 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
342 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
343 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
344 else:
faa06b4873dd more contenttype related changes/fixes, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 216
diff changeset
345 mt = MimeType(mimestr=mimestr)
860
de6ece090b7d fix download view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
346 content_length = rev.meta[SIZE]
de6ece090b7d fix download view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
347 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
348 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
349 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
350 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
351 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
352 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
353 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
354 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
355 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
356 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
357 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
358
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
359 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
360
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
361
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
362 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
363 """ 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
364
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
365
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
366 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
367 """ 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
368
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
369
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
370 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
371 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
372 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
373 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
374 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
375 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
376 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
377 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
378 """
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
379 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
380 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
381 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
382
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
383 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
384 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
385 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
386
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
387 :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
388 """
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
389 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
390 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
391 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
392
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
393 def 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
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 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
396 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
397 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
398
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
399 :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
400 :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
401 :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
402 :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
403 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
404 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
405 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
406 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
407 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
408 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
409 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
410 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
411 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
412 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
413 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
414 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
415 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
416 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
417 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
418 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
419 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
420 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
421 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
422 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
423 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
424 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
425 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
426 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
427 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
428 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
429 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
430 # 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
431 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
432 data = open(temp_fname, 'rb')
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
433 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
434 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
435 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
436
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
437
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
438 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
439 """
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
440 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
441 """
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
442
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
443 content_registry.register(ApplicationXTar._factory, Type('application/x-tar'))
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
444 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
445
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
446
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
447 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
448 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
449 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
450 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
451 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
452 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
453 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
454 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
455 """
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
456 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
457 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
458 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
459
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
460 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
461 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
462 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
463
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
464 :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
465 """
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
466 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
467 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
468 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
469
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
470 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
471 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
472
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
473
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
474 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
475 """
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
476 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
477 """
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
478
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
479 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
480
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
481
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
482 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
483 """ 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
484
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
485 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
486
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
487
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
488 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
489 """ 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
490
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
491 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
492
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
493
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
494 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
495 """ 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
496
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
497 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
498
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
499
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
500 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
501 """ Base class for image/* """
1214
8d547ec39a76 Cosmetic changes
Shitiz Garg <mail@dragooon.net>
parents: 1213
diff changeset
502
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
503 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
504
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
505
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
506 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
507 """ 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
508
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
509
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
510 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
511 """ 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
512
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
513 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
514
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
515
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
516 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
517 """ 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
518 # 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
519
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
520
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
521 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
522 """ 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
523 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
524 """ 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
525 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
526 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
527 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
528 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
529 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
530 # 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
531 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
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 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
534 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
535 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
536 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
537 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
538 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
539 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
540 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
541
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
542 # 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
543 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
544 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
545
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
546 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
547 # 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
548 # 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
549 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
550 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
551 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
552
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
553 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
554 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
555 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
556
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
557 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
558 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
559 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
560 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
561 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
562 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
563 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
564 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
565 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
566 }
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
567 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
568
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
569 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
570 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
571 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
572 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
573 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
574
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
575 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
576 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
577 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
578 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
579 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
580 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
581 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
582 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
583 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
584 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
585 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
586 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
587 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
588 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
589 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
590 # 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
591 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
592 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
593 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
594 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
595 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
596 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
597 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
598 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
599 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
600 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
601 else:
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
602 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
603 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
604 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
605 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
606 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
607 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
608 # 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
609 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
610 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
611 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
612 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
613
1209
c0eaed311e0e Try using PIL for image diffs
Shitiz Garg <mail@dragooon.net>
parents: 1208
diff changeset
614 def _render_data_diff_atom(self, oldrev, newrev):
c0eaed311e0e Try using PIL for image diffs
Shitiz Garg <mail@dragooon.net>
parents: 1208
diff changeset
615 if PIL is None:
c0eaed311e0e Try using PIL for image diffs
Shitiz Garg <mail@dragooon.net>
parents: 1208
diff changeset
616 # 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
617 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
618 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
619 return render_template('atom.html',
c0eaed311e0e Try using PIL for image diffs
Shitiz Garg <mail@dragooon.net>
parents: 1208
diff changeset
620 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
621 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
622
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
623 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
624 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
625 # 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
626 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
627 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
628 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
629
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
630 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
631 hash_name = HASH_ALGORITHM
174
e8f61cbd661b modularize crypto/random stuff, move it to MoinMoin.util.crypto, pw change bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 173
diff changeset
632 cid = cache_key(usage="ImageDiff",
e8f61cbd661b modularize crypto/random stuff, move it to MoinMoin.util.crypto, pw change bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 173
diff changeset
633 hash_name=hash_name,
860
de6ece090b7d fix download view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
634 hash_old=oldrev.meta[hash_name],
de6ece090b7d fix download view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
635 hash_new=newrev.meta[hash_name])
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
636 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
637 if c is None:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
638 if PIL is None:
256
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
639 abort(404) # TODO render user friendly error image
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
640
860
de6ece090b7d fix download view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
641 content_type = newrev.meta[CONTENTTYPE]
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
642 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
643 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
644 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
645 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
646 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
647 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
648 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
649 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
650
256
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
651 try:
1152
a284e43d1292 Use rev.data instead of rev, to fix crash that occured on image diff
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1112
diff changeset
652 oldimage = PILImage.open(oldrev.data)
a284e43d1292 Use rev.data instead of rev, to fix crash that occured on image diff
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1112
diff changeset
653 newimage = PILImage.open(newrev.data)
256
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
654 oldimage.load()
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
655 newimage.load()
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
656 diffimage = PILdiff(newimage, oldimage)
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
657 outfile = StringIO()
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
658 diffimage.save(outfile, output_type)
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
659 data = outfile.getvalue()
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
660 outfile.close()
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
661 headers = wikiutil.file_headers(content_type=content_type, content_length=len(data))
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
662 app.cache.set(cid, (headers, data))
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
663 except (IOError, ValueError) as err:
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
664 logging.exception("error during PILdiff: {0}".format(err.message))
256
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
665 abort(404) # TODO render user friendly error image
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
666 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
667 # 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
668 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
669 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
670
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
671 def _render_data_diff_text(self, oldrev, newrev):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
672 return super(TransformableBitmapImage, self)._render_data_diff_text(oldrev, newrev)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
673
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
674 content_registry.register(TransformableBitmapImage._factory, Type('image/png'))
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
675 content_registry.register(TransformableBitmapImage._factory, Type('image/jpeg'))
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
676 content_registry.register(TransformableBitmapImage._factory, Type('image/gif'))
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
677
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
678
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
679 class Text(Binary):
225
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
680 """ Base class for text/* """
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
681
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1361
diff changeset
682 class ModifyForm(Binary.ModifyForm):
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
683 template = 'modify_text.html'
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1361
diff changeset
684 data_text = String.using(strip=False, optional=True).with_properties(placeholder=L_("Type your text here"))
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
685 rows = ROWS_DATA
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
686 cols = COLS
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1361
diff changeset
687
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
688 def _load(self, item):
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
689 super(Text.ModifyForm, self)._load(item)
1408
94dda5c633d2 Minor fixes to previous items cleanup changeset.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1407
diff changeset
690 data = item.data
94dda5c633d2 Minor fixes to previous items cleanup changeset.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1407
diff changeset
691 data = item.data_storage_to_internal(data)
94dda5c633d2 Minor fixes to previous items cleanup changeset.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1407
diff changeset
692 data = item.data_internal_to_form(data)
94dda5c633d2 Minor fixes to previous items cleanup changeset.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1407
diff changeset
693 self['data_text'] = data
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1361
diff changeset
694
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
695 def _dump(self, item):
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
696 data, contenttype_guessed = super(Text.ModifyForm, self)._dump(item)
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
697 if data is None:
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
698 data = self['data_text'].value
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
699 data = item.data_form_to_internal(data)
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
700 data = item.data_internal_to_storage(data)
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
701 # we know it is text and utf-8 - XXX is there a way to get the charset of the form?
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
702 contenttype_guessed = u'text/plain;charset=utf-8'
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
703 return data, contenttype_guessed
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1361
diff changeset
704
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
705 # text/plain mandates crlf - but in memory, we want lf only
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
706 def data_internal_to_form(self, text):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
707 """ convert data from memory format to form format """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
708 return text.replace(u'\n', u'\r\n')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
709
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
710 def data_form_to_internal(self, data):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
711 """ convert data from form format to memory format """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
712 return data.replace(u'\r\n', u'\n')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
713
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
714 def data_internal_to_storage(self, text):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
715 """ convert data from memory format to storage format """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
716 return text.replace(u'\n', u'\r\n').encode(config.charset)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
717
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
718 def data_storage_to_internal(self, data):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
719 """ convert data from storage format to memory format """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
720 return data.decode(config.charset).replace(u'\r\n', u'\n')
1198
2aa4f4ec6a94 Minor fixes for atom feed
Shitiz Garg <mail@dragooon.net>
parents: 1197
diff changeset
721
1197
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
722 def _get_data_diff_html(self, oldrev, newrev, template):
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
723 from MoinMoin.util.diff_html import diff
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
724 old_text = self.data_storage_to_internal(oldrev.data.read())
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
725 new_text = self.data_storage_to_internal(newrev.data.read())
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
726 storage_item = flaskg.storage[self.name]
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
727 diffs = [(d[0], Markup(d[1]), d[2], Markup(d[3])) for d in diff(old_text, new_text)]
1197
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
728 return render_template(template,
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
729 item_name=self.name,
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
730 oldrev=oldrev,
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
731 newrev=newrev,
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
732 diffs=diffs,
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
733 )
1198
2aa4f4ec6a94 Minor fixes for atom feed
Shitiz Garg <mail@dragooon.net>
parents: 1197
diff changeset
734
1197
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
735 def _render_data_diff_atom(self, oldrev, newrev):
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
736 """ renders diff in HTML for atom feed """
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
737 return self._get_data_diff_html(oldrev, newrev, 'diff_text_atom.html')
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
738
1197
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
739 def _render_data_diff(self, oldrev, newrev):
1199
a4ce283b0ca2 Text::_render_data_diff should return unicode in keeping it consistent with _render_data_diff_atom
Shitiz Garg <mail@dragooon.net>
parents: 1198
diff changeset
740 return self._get_data_diff_html(oldrev, newrev, 'diff_text.html')
1198
2aa4f4ec6a94 Minor fixes for atom feed
Shitiz Garg <mail@dragooon.net>
parents: 1197
diff changeset
741
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
742 def _render_data_diff_text(self, oldrev, newrev):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
743 from MoinMoin.util import diff_text
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
744 oldlines = self.data_storage_to_internal(oldrev.data.read()).split('\n')
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
745 newlines = self.data_storage_to_internal(newrev.data.read()).split('\n')
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
746 difflines = diff_text.diff(oldlines, newlines)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
747 return '\n'.join(difflines)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
748
1112
b02f88f4428e Fix diffraw view, fix text diffraw
Sam Toyer <samATqxcvDOTnet>
parents: 1099
diff changeset
749 _render_data_diff_raw = _render_data_diff
b02f88f4428e Fix diffraw view, fix text diffraw
Sam Toyer <samATqxcvDOTnet>
parents: 1099
diff changeset
750
202
9ffa82e550ba highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 197
diff changeset
751 def _render_data_highlight(self):
9ffa82e550ba highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 197
diff changeset
752 from MoinMoin.converter import default_registry as reg
9ffa82e550ba highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 197
diff changeset
753 data_text = self.data_storage_to_internal(self.data)
9ffa82e550ba highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 197
diff changeset
754 # TODO: use registry as soon as it is in there
9ffa82e550ba highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 197
diff changeset
755 from MoinMoin.converter.pygments_in import Converter as PygmentsConverter
221
faa06b4873dd more contenttype related changes/fixes, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 216
diff changeset
756 pygments_conv = PygmentsConverter(contenttype=self.contenttype)
298
07143bd03aed fix pygments converter call for new converter api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 292
diff changeset
757 doc = pygments_conv(data_text)
202
9ffa82e550ba highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 197
diff changeset
758 # TODO: Real output format
9ffa82e550ba highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 197
diff changeset
759 html_conv = reg.get(type_moin_document, Type('application/x-xhtml-moin-page'))
9ffa82e550ba highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 197
diff changeset
760 doc = html_conv(doc)
204
af274db0ed53 items: move duplicated code to function conv_serialize
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 203
diff changeset
761 return conv_serialize(doc, {html.namespace: ''})
202
9ffa82e550ba highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 197
diff changeset
762
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
763 content_registry.register(Text._factory, Type('text/*'))
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
764
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
765
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
766 class MarkupItem(Text):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
767 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
768 some kind of item with markup
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
769 (internal links and transcluded items)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
770 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
771
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
772
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
773 class MoinWiki(MarkupItem):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
774 """ MoinMoin wiki markup """
225
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
775
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
776 content_registry.register(MoinWiki._factory, Type('text/x.moin.wiki'))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
777
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
778
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
779 class CreoleWiki(MarkupItem):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
780 """ Creole wiki markup """
225
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
781
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
782 content_registry.register(CreoleWiki._factory, Type('text/x.moin.creole'))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
783
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
784
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
785 class MediaWiki(MarkupItem):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
786 """ MediaWiki markup """
225
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
787
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
788 content_registry.register(MediaWiki._factory, Type('text/x-mediawiki'))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
789
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
790
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
791 class ReST(MarkupItem):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
792 """ ReStructured Text markup """
225
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
793
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
794 content_registry.register(ReST._factory, Type('text/x-rst'))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
795
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
796
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
797 class HTML(Text):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
798 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
799 HTML markup
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
800
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
801 Note: As we use html_in converter to convert this to DOM and later some
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
802 output converterter to produce output format (e.g. html_out for html
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
803 output), all(?) unsafe stuff will get lost.
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
804
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
805 Note: If raw revision data is accessed, unsafe stuff might be present!
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
806 """
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
807 class ModifyForm(Text.ModifyForm):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
808 template = "modify_text_html.html"
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
809
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
810 content_registry.register(HTML._factory, Type('text/html'))
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
811
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
812
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
813 class DocBook(MarkupItem):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
814 """ DocBook Document """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
815 def _convert(self, doc):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
816 from emeraldtree import ElementTree as ET
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
817 from MoinMoin.converter import default_registry as reg
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
818
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
819 doc = self._expand_document(doc)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
820
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
821 # We convert the internal representation of the document
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
822 # into a DocBook document
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
823 conv = reg.get(type_moin_document, Type('application/docbook+xml'))
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
824
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
825 doc = conv(doc)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
826
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
827 # We determine the different namespaces of the output form
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
828 output_namespaces = {
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
829 docbook.namespace: '',
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
830 xlink.namespace: 'xlink',
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
831 }
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
832
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
833 # We convert the result into a StringIO object
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
834 # With the appropriate namespace
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
835 # TODO: Some other operation should probably be done here too
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
836 # like adding a doctype
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
837 file_to_send = StringIO()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
838 tree = ET.ElementTree(doc)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
839 tree.write(file_to_send, namespaces=output_namespaces)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
840
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
841 # We determine the different parameters for the reply
221
faa06b4873dd more contenttype related changes/fixes, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 216
diff changeset
842 mt = MimeType(mimestr='application/docbook+xml;charset=utf-8')
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
843 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
844 as_attachment = 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
845 # After creation of the StringIO, we are at the end of the file
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
846 # so position is the size the file.
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
847 # and then we should move it back at the beginning of the file
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
848 content_length = file_to_send.tell()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
849 file_to_send.seek(0)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
850 # Important: empty filename keeps flask from trying to autodetect filename,
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
851 # as this would not work for us, because our file's are not necessarily fs files.
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
852 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
853 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
854 as_attachment=as_attachment, attachment_filename=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
855 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
856 add_etags=False, etag=None, conditional=True)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
857
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
858 content_registry.register(DocBook._factory, Type('application/docbook+xml'))
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
859
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
860
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1361
diff changeset
861 class Draw(TarMixin, Image):
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1361
diff changeset
862 """
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1361
diff changeset
863 Base class for *Draw that use special Java/Javascript applets to modify and store data in a tar file.
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1361
diff changeset
864 """
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1361
diff changeset
865 class ModifyForm(Binary.ModifyForm):
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
866 # Set the workaround flag respected in modify.html
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
867 is_draw = True
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1361
diff changeset
868
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
869 def handle_post():
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
870 raise NotImplementedError
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
871
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1361
diff changeset
872
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1361
diff changeset
873 class TWikiDraw(Draw):
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
874 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
875 drawings by TWikiDraw applet. It creates three files which are stored as tar file.
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
876 """
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
877
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
878 class ModifyForm(Draw.ModifyForm):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
879 template = "modify_twikidraw.html"
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
880 help = ""
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
881
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
882 def handle_post(self):
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
883 # called from modify UI/POST
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
884 file_upload = request.files.get('filepath')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
885 filename = request.form['filename']
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
886 basepath, basename = os.path.split(filename)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
887 basename, ext = os.path.splitext(basename)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
888
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
889 filecontent = file_upload.stream
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
890 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
891 if ext == '.draw': # TWikiDraw POSTs this first
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
892 filecontent = filecontent.read() # read file completely into memory
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
893 filecontent = filecontent.replace("\r", "")
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
894 elif ext == '.map':
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
895 filecontent = filecontent.read() # read file completely into memory
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
896 filecontent = filecontent.strip()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
897 elif ext == '.png':
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
898 #content_length = file_upload.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
899 # XXX gives -1 for wsgiref, gives 0 for werkzeug :(
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
900 # If this is fixed, we could use the file obj, without reading it into memory completely:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
901 filecontent = filecontent.read()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
902
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
903 self.put_member('drawing' + ext, filecontent, 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
904 expected_members=set(['drawing.draw', 'drawing.map', 'drawing.png']))
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
905
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
906 def _render_data(self):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
907 # TODO: this could be a converter -> dom, then transcluding this kind
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
908 # of items and also rendering them with the code in base class could work
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
909 item_name = self.name
1212
98d0b7dfaf1a Fix drawable items would always render the latest revision
Shitiz Garg <mail@dragooon.net>
parents: 1211
diff changeset
910 drawing_url = url_for('frontend.get_item', item_name=item_name, member='drawing.draw', rev=self.rev.revid)
98d0b7dfaf1a Fix drawable items would always render the latest revision
Shitiz Garg <mail@dragooon.net>
parents: 1211
diff changeset
911 png_url = url_for('frontend.get_item', item_name=item_name, member='drawing.png', rev=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
912 title = _('Edit drawing %(filename)s (opens in new window)', filename=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
913
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
914 mapfile = self.get_member('drawing.map')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
915 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
916 image_map = mapfile.read()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
917 mapfile.close()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
918 except (IOError, OSError):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
919 image_map = ''
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
920 if image_map:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
921 # we have a image map. inline it and add a map ref to the img tag
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
922 mapid = 'ImageMapOf' + 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
923 image_map = image_map.replace('%MAPNAME%', mapid)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
924 # add alt and title tags to areas
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
925 image_map = re.sub(r'href\s*=\s*"((?!%TWIKIDRAW%).+?)"', r'href="\1" alt="\1" title="\1"', image_map)
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
926 image_map = image_map.replace('%TWIKIDRAW%"', '{0}" alt="{1}" title="{2}"'.format((drawing_url, title, title)))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
927 title = _('Clickable drawing: %(filename)s', filename=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
928
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
929 return Markup(image_map + u'<img src="{0}" alt="{1}" usemap="#{2}" />'.format(png_url, title, mapid))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
930 else:
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
931 return Markup(u'<img src="{0}" alt="{1}" />'.format(png_url, title))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
932
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
933 content_registry.register(TWikiDraw._factory, Type('application/x-twikidraw'))
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
934
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
935
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1361
diff changeset
936 class AnyWikiDraw(Draw):
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
937 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
938 drawings by AnyWikiDraw applet. It creates three files which are stored as tar file.
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
939 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
940
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1361
diff changeset
941 class ModifyForm(Draw.ModifyForm):
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
942 template = "modify_anywikidraw.html"
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
943 help = ""
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
944 def _load(self, item):
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
945 super(AnyWikiDraw.ModifyForm, self)._load(item)
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1361
diff changeset
946 try:
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
947 drawing_exists = 'drawing.svg' in item.list_members()
1393
0f0932809e1e Fix broken AnyWikiDraw.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1392
diff changeset
948 except tarfile.TarError: # item doesn't exist yet
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1361
diff changeset
949 drawing_exists = False
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
950 self.drawing_exists = drawing_exists
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1361
diff changeset
951
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
952 def handle_post(self):
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
953 # called from modify UI/POST
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
954 file_upload = request.files.get('filepath')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
955 filename = request.form['filename']
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
956 basepath, basename = os.path.split(filename)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
957 basename, ext = os.path.splitext(basename)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
958 filecontent = file_upload.stream
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
959 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
960 if ext == '.svg':
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
961 filecontent = filecontent.read() # read file completely into memory
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
962 filecontent = filecontent.replace("\r", "")
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
963 elif ext == '.map':
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
964 filecontent = filecontent.read() # read file completely into memory
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
965 filecontent = filecontent.strip()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
966 elif ext == '.png':
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
967 #content_length = file_upload.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
968 # XXX gives -1 for wsgiref, gives 0 for werkzeug :(
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
969 # If this is fixed, we could use the file obj, without reading it into memory completely:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
970 filecontent = filecontent.read()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
971 self.put_member('drawing' + ext, filecontent, 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
972 expected_members=set(['drawing.svg', 'drawing.map', 'drawing.png']))
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
973
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
974 def _render_data(self):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
975 # TODO: this could be a converter -> dom, then transcluding this kind
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
976 # of items and also rendering them with the code in base class could work
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
977 item_name = self.name
1212
98d0b7dfaf1a Fix drawable items would always render the latest revision
Shitiz Garg <mail@dragooon.net>
parents: 1211
diff changeset
978 drawing_url = url_for('frontend.get_item', item_name=item_name, member='drawing.svg', rev=self.rev.revid)
98d0b7dfaf1a Fix drawable items would always render the latest revision
Shitiz Garg <mail@dragooon.net>
parents: 1211
diff changeset
979 png_url = url_for('frontend.get_item', item_name=item_name, member='drawing.png', rev=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
980 title = _('Edit drawing %(filename)s (opens in new window)', filename=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
981
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
982 mapfile = self.get_member('drawing.map')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
983 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
984 image_map = mapfile.read()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
985 mapfile.close()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
986 except (IOError, OSError):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
987 image_map = ''
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
988 if image_map:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
989 # ToDo mapid must become uniq
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
990 # we have a image map. inline it and add a map ref to the img tag
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
991 # we have also to set a unique ID
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
992 mapid = 'ImageMapOf' + 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
993 image_map = image_map.replace(u'id="drawing.svg"', '')
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
994 image_map = image_map.replace(u'name="drawing.svg"', u'name="{0}"'.format(mapid))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
995 # unxml, because 4.01 concrete will not validate />
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
996 image_map = image_map.replace(u'/>', u'>')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
997 title = _('Clickable drawing: %(filename)s', filename=self.name)
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
998 return Markup(image_map + u'<img src="{0}" alt="{1}" usemap="#{2}" />'.format(png_url, title, mapid))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
999 else:
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
1000 return Markup(u'<img src="{0}" alt="{1}" />'.format(png_url, title))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1001
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
1002 content_registry.register(AnyWikiDraw._factory, Type('application/x-anywikidraw'))
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
1003
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
1004
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1361
diff changeset
1005 class SvgDraw(Draw):
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1006 """ drawings by svg-edit. It creates two files (svg, png) which are stored as tar file. """
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
1007
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
1008 class ModifyForm(Draw.ModifyForm):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
1009 template = "modify_svg-edit.html"
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
1010 help = ""
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
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
1012 def handle_post(self):
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 # called from modify UI/POST
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
1014 png_upload = request.values.get('png_data')
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
1015 svg_upload = request.values.get('filepath')
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1016 filename = request.form['filename']
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
1017 png_content = png_upload.decode('base_64')
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
1018 png_content = base64.urlsafe_b64decode(png_content.split(',')[1])
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
1019 svg_content = svg_upload.decode('base_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
1020 content_length = None
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
1021 self.put_member("drawing.svg", svg_content, content_length,
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
1022 expected_members=set(['drawing.svg', 'drawing.png']))
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
1023 self.put_member("drawing.png", png_content, content_length,
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 expected_members=set(['drawing.svg', 'drawing.png']))
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1025
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1026 def _render_data(self):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1027 # TODO: this could be a converter -> dom, then transcluding this kind
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1028 # of items and also rendering them with the code in base class could work
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1029 item_name = self.name
1212
98d0b7dfaf1a Fix drawable items would always render the latest revision
Shitiz Garg <mail@dragooon.net>
parents: 1211
diff changeset
1030 drawing_url = url_for('frontend.get_item', item_name=item_name, member='drawing.svg', rev=self.rev.revid)
98d0b7dfaf1a Fix drawable items would always render the latest revision
Shitiz Garg <mail@dragooon.net>
parents: 1211
diff changeset
1031 png_url = url_for('frontend.get_item', item_name=item_name, member='drawing.png', rev=self.rev.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
1032 return Markup(u'<img src="{0}" alt="{1}" />'.format(png_url, drawing_url))
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
1033
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
1034 content_registry.register(SvgDraw._factory, Type('application/x-svgdraw'))