annotate MoinMoin/items/content.py @ 1901:77d7c15299c9

error logging: include error uuid in the log, tell user the uuid on the UI (so it is easier to lookup the problem in the log)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 24 Dec 2012 17:44:07 +0100
parents d4a382f781c9
children 78b7a1136984
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
1613
bc8a2546468b Clean up registry code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1456
diff changeset
26 from collections import namedtuple
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
27 from operator import attrgetter
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
28
1763
347d11826f95 Clean up imports in items/{__init__,content}.py
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1666
diff changeset
29 from flask import current_app as app
347d11826f95 Clean up imports in items/{__init__,content}.py
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1666
diff changeset
30 from flask import g as flaskg
347d11826f95 Clean up imports in items/{__init__,content}.py
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1666
diff changeset
31 from flask import request, url_for, Response, abort, escape
1456
fc1f874695e1 Fix missing imports due to Content sepration, discovered with pyflakes
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1454
diff changeset
32
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
33 from flatland import Form, String
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
34
1763
347d11826f95 Clean up imports in items/{__init__,content}.py
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1666
diff changeset
35 from jinja2 import Markup
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
36
1763
347d11826f95 Clean up imports in items/{__init__,content}.py
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1666
diff changeset
37 from werkzeug import is_resource_modified
347d11826f95 Clean up imports in items/{__init__,content}.py
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1666
diff changeset
38
347d11826f95 Clean up imports in items/{__init__,content}.py
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1666
diff changeset
39 from whoosh.query import Term, And
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
40
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
41 try:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
42 import PIL
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
43 from PIL import Image as PILImage
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
44 from PIL.ImageChops import difference as PILdiff
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
45 except ImportError:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
46 PIL = None
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
47
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
48 from MoinMoin import log
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
49 logging = log.getLogger(__name__)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
50
1763
347d11826f95 Clean up imports in items/{__init__,content}.py
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1666
diff changeset
51 from MoinMoin import wikiutil, config
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
52 from MoinMoin.i18n import _, L_
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
53 from MoinMoin.themes import render_template
1763
347d11826f95 Clean up imports in items/{__init__,content}.py
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1666
diff changeset
54 from MoinMoin.storage.error import StorageError
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
55 from MoinMoin.util.send_file import send_file
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
56 from MoinMoin.util.registry import RegistryBase
1763
347d11826f95 Clean up imports in items/{__init__,content}.py
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1666
diff changeset
57 from MoinMoin.util.mimetype import MimeType
347d11826f95 Clean up imports in items/{__init__,content}.py
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1666
diff changeset
58 from MoinMoin.util.mime import Type, type_moin_document
347d11826f95 Clean up imports in items/{__init__,content}.py
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1666
diff changeset
59 from MoinMoin.util.tree import moin_page, html, xlink, docbook
347d11826f95 Clean up imports in items/{__init__,content}.py
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1666
diff changeset
60 from MoinMoin.util.iri import Iri
347d11826f95 Clean up imports in items/{__init__,content}.py
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1666
diff changeset
61 from MoinMoin.util.crypto import cache_key
1764
19b19d4d9291 Add a @timed decorator.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
62 from MoinMoin.util.clock import timed
1763
347d11826f95 Clean up imports in items/{__init__,content}.py
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1666
diff changeset
63 from MoinMoin.forms import File
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
64 from MoinMoin.constants.contenttypes import (
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
65 GROUP_MARKUP_TEXT, GROUP_OTHER_TEXT, GROUP_IMAGE, GROUP_AUDIO, GROUP_VIDEO,
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
66 GROUP_DRAWING, GROUP_OTHER,
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
67 )
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
68 from MoinMoin.constants.keys import (
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
69 NAME, NAME_EXACT, WIKINAME, CONTENTTYPE, SIZE, TAGS, HASH_ALGORITHM
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
70 )
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 COLS = 80
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
74 ROWS_DATA = 20
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
75
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
76
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
77 class RegistryContent(RegistryBase):
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
78 class Entry(namedtuple('Entry', 'factory content_type default_contenttype_params display_name ingroup_order priority')):
1613
bc8a2546468b Clean up registry code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1456
diff changeset
79 def __call__(self, content_type, *args, **kw):
bc8a2546468b Clean up registry code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1456
diff changeset
80 if self.content_type.issupertype(Type(content_type)):
bc8a2546468b Clean up registry code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1456
diff changeset
81 return self.factory(content_type, *args, **kw)
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
82
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
83 def __lt__(self, other):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
84 if isinstance(other, self.__class__):
1826
8231bca193ef Demote priority in registry entries so that it is only compared when other fields are equal.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1819
diff changeset
85 if self.content_type != other.content_type:
8231bca193ef Demote priority in registry entries so that it is only compared when other fields are equal.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1819
diff changeset
86 return other.content_type.issupertype(self.content_type)
1614
5b5e7190452f Fix various registry Entry `__lt__` methods. This resolves issue #221.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1613
diff changeset
87 if self.priority != other.priority:
5b5e7190452f Fix various registry Entry `__lt__` methods. This resolves issue #221.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1613
diff changeset
88 return self.priority < other.priority
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
89 return False
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
90 return NotImplemented
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
91
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
92 def __init__(self, group_names):
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
93 super(RegistryContent, self).__init__()
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
94 self.group_names = group_names
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
95 self.groups = dict([(g, []) for g in group_names])
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
96
1819
38632887ca57 Make RegistryContent.register accept an Entry and group name for slightly cleaner code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1801
diff changeset
97 def register(self, e, group):
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
98 """
1819
38632887ca57 Make RegistryContent.register accept an Entry and group name for slightly cleaner code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1801
diff changeset
99 Register a contenttype entry and optionally add it to a specific group.
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
100 """
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
101 # If group is specified and contenttype is not a wildcard one
1819
38632887ca57 Make RegistryContent.register accept an Entry and group name for slightly cleaner code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1801
diff changeset
102 if group and e.content_type.type and e.content_type.subtype:
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
103 if group not in self.groups:
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
104 raise ValueError('Unknown group name: {0}'.format(group))
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
105 self.groups[group].append(e)
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
106 self.groups[group].sort(key=attrgetter('ingroup_order'))
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
107 return self._register(e)
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
108
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
109
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
110 content_registry = RegistryContent([
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
111 GROUP_MARKUP_TEXT,
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
112 GROUP_OTHER_TEXT,
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
113 GROUP_IMAGE,
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
114 GROUP_AUDIO,
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
115 GROUP_VIDEO,
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
116 GROUP_DRAWING,
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
117 GROUP_OTHER
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
118 ])
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
119
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
120 def register(cls):
1819
38632887ca57 Make RegistryContent.register accept an Entry and group name for slightly cleaner code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1801
diff changeset
121 content_registry.register(RegistryContent.Entry(cls._factory, Type(cls.contenttype), cls.default_contenttype_params, cls.display_name, cls.ingroup_order, RegistryContent.PRIORITY_MIDDLE), cls.group)
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
122 return cls
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
123
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
124
1764
19b19d4d9291 Add a @timed decorator.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
125 @timed()
1451
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 doc.write(out.fromunicode, namespaces=namespaces, method=method)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
129 out = out.tounicode()
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
130 return out
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
131
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
132
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
133 class Content(object):
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 Base for content classes defining some helpers, agnostic about content
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
136 data.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
137 """
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
138 # placeholder values for registry entry properties
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
139 contenttype = None
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
140 default_contenttype_params = {}
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
141 display_name = None
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
142 group = GROUP_OTHER
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
143 ingroup_order = 0
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
144
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
145 @classmethod
1613
bc8a2546468b Clean up registry code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1456
diff changeset
146 def _factory(cls, *args, **kw):
bc8a2546468b Clean up registry code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1456
diff changeset
147 return cls(*args, **kw)
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
148
1648
1a2c53092ea1 items/content.py: Implement Content.create.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1617
diff changeset
149 @classmethod
1a2c53092ea1 items/content.py: Implement Content.create.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1617
diff changeset
150 def create(cls, contenttype, item=None):
1a2c53092ea1 items/content.py: Implement Content.create.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1617
diff changeset
151 content = content_registry.get(contenttype, item)
1a2c53092ea1 items/content.py: Implement Content.create.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1617
diff changeset
152 logging.debug("Content class {0!r} handles {1!r}".format(content.__class__, contenttype))
1a2c53092ea1 items/content.py: Implement Content.create.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1617
diff changeset
153 return content
1a2c53092ea1 items/content.py: Implement Content.create.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1617
diff changeset
154
1613
bc8a2546468b Clean up registry code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1456
diff changeset
155 def __init__(self, contenttype, item=None):
bc8a2546468b Clean up registry code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1456
diff changeset
156 # We need to keep the exact contenttype since contents may be handled
bc8a2546468b Clean up registry code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1456
diff changeset
157 # by a Content subclass with wildcard contenttype (eg. an unknown
bc8a2546468b Clean up registry code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1456
diff changeset
158 # contenttype some/type gets handled by Binary)
bc8a2546468b Clean up registry code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1456
diff changeset
159 # TODO use Type instead of strings?
bc8a2546468b Clean up registry code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1456
diff changeset
160 self.contenttype = contenttype
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
161 self.item = item
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
162
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
163 # XXX For backward-compatibility (so code can be moved from Item
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
164 # untouched), remove soon
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
165 @property
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
166 def rev(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
167 return self.item.rev
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 @property
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
170 def name(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
171 return self.item.name
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
172
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
173 def get_data(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
174 return '' # TODO create a better method for binary stuff
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
175 data = property(fget=get_data)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
176
1764
19b19d4d9291 Add a @timed decorator.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
177 @timed('conv_in_dom')
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
178 def internal_representation(self, converters=['smiley']):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
179 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
180 Return the internal representation of a document using a DOM Tree
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
181 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
182 hash_name = HASH_ALGORITHM
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
183 hash_hexdigest = self.rev.meta.get(hash_name)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
184 if hash_hexdigest:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
185 cid = cache_key(usage="internal_representation",
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
186 hash_name=hash_name,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
187 hash_hexdigest=hash_hexdigest)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
188 doc = app.cache.get(cid)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
189 else:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
190 # likely a non-existing item
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
191 doc = cid = None
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
192 if doc is None:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
193 # We will see if we can perform the conversion:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
194 # FROM_mimetype --> DOM
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
195 # if so we perform the transformation, otherwise we don't
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
196 from MoinMoin.converter import default_registry as reg
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
197 input_conv = reg.get(Type(self.contenttype), type_moin_document)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
198 if not input_conv:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
199 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
200 smiley_conv = reg.get(type_moin_document, type_moin_document,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
201 icon='smiley')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
202
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
203 # We can process the conversion
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
204 links = Iri(scheme='wiki', authority='', path='/' + self.name)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
205 doc = input_conv(self.rev, self.contenttype)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
206 # 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
207 # 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
208 # 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
209 # 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
210 doc.set(moin_page.page_href, unicode(links))
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
211 for conv in converters:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
212 if conv == 'smiley':
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
213 doc = smiley_conv(doc)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
214 if cid:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
215 app.cache.set(cid, doc)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
216 return doc
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
217
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
218 def _expand_document(self, doc):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
219 from MoinMoin.converter import default_registry as reg
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
220 include_conv = reg.get(type_moin_document, type_moin_document, includes='expandall')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
221 macro_conv = reg.get(type_moin_document, type_moin_document, macros='expandall')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
222 link_conv = reg.get(type_moin_document, type_moin_document, links='extern')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
223 flaskg.clock.start('conv_include')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
224 doc = include_conv(doc)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
225 flaskg.clock.stop('conv_include')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
226 flaskg.clock.start('conv_macro')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
227 doc = macro_conv(doc)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
228 flaskg.clock.stop('conv_macro')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
229 flaskg.clock.start('conv_link')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
230 doc = link_conv(doc)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
231 flaskg.clock.stop('conv_link')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
232 return doc
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
233
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
234 def _render_data(self):
1897
df3e72208eed catch exceptions happening in the converters, show time/url for crash and hint to look into the log file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1881
diff changeset
235 try:
df3e72208eed catch exceptions happening in the converters, show time/url for crash and hint to look into the log file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1881
diff changeset
236 from MoinMoin.converter import default_registry as reg
df3e72208eed catch exceptions happening in the converters, show time/url for crash and hint to look into the log file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1881
diff changeset
237 # TODO: Real output format
df3e72208eed catch exceptions happening in the converters, show time/url for crash and hint to look into the log file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1881
diff changeset
238 doc = self.internal_representation()
df3e72208eed catch exceptions happening in the converters, show time/url for crash and hint to look into the log file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1881
diff changeset
239 doc = self._expand_document(doc)
df3e72208eed catch exceptions happening in the converters, show time/url for crash and hint to look into the log file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1881
diff changeset
240 flaskg.clock.start('conv_dom_html')
df3e72208eed catch exceptions happening in the converters, show time/url for crash and hint to look into the log file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1881
diff changeset
241 html_conv = reg.get(type_moin_document, Type('application/x-xhtml-moin-page'))
df3e72208eed catch exceptions happening in the converters, show time/url for crash and hint to look into the log file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1881
diff changeset
242 doc = html_conv(doc)
df3e72208eed catch exceptions happening in the converters, show time/url for crash and hint to look into the log file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1881
diff changeset
243 flaskg.clock.stop('conv_dom_html')
df3e72208eed catch exceptions happening in the converters, show time/url for crash and hint to look into the log file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1881
diff changeset
244 rendered_data = conv_serialize(doc, {html.namespace: ''})
df3e72208eed catch exceptions happening in the converters, show time/url for crash and hint to look into the log file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1881
diff changeset
245 except Exception:
df3e72208eed catch exceptions happening in the converters, show time/url for crash and hint to look into the log file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1881
diff changeset
246 # we really want to make sure that invalid data or a malfunctioning
df3e72208eed catch exceptions happening in the converters, show time/url for crash and hint to look into the log file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1881
diff changeset
247 # converter does not crash the item view (otherwise a user might
df3e72208eed catch exceptions happening in the converters, show time/url for crash and hint to look into the log file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1881
diff changeset
248 # not be able to fix it from the UI).
1901
77d7c15299c9 error logging: include error uuid in the log, tell user the uuid on the UI (so it is easier to lookup the problem in the log)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1900
diff changeset
249 import time, uuid
77d7c15299c9 error logging: include error uuid in the log, tell user the uuid on the UI (so it is easier to lookup the problem in the log)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1900
diff changeset
250 error_id = uuid.uuid4()
77d7c15299c9 error logging: include error uuid in the log, tell user the uuid on the UI (so it is easier to lookup the problem in the log)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1900
diff changeset
251 logging.exception("An exception happened in _render_data (error_id = %s ):" % error_id)
1897
df3e72208eed catch exceptions happening in the converters, show time/url for crash and hint to look into the log file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1881
diff changeset
252 rendered_data = render_template('crash.html',
df3e72208eed catch exceptions happening in the converters, show time/url for crash and hint to look into the log file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1881
diff changeset
253 server_time=time.strftime("%Y-%m-%d %H:%M:%S %Z"),
1901
77d7c15299c9 error logging: include error uuid in the log, tell user the uuid on the UI (so it is easier to lookup the problem in the log)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1900
diff changeset
254 url=request.url,
77d7c15299c9 error logging: include error uuid in the log, tell user the uuid on the UI (so it is easier to lookup the problem in the log)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1900
diff changeset
255 error_id=error_id)
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
256 return rendered_data
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 def _render_data_xml(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
259 doc = self.internal_representation()
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
260 return conv_serialize(doc,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
261 {moin_page.namespace: '',
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
262 xlink.namespace: 'xlink',
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
263 html.namespace: 'html',
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
264 },
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
265 'xml')
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 def _render_data_highlight(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
268 # override this in child classes
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
269 return ''
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
270
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
271 def get_templates(self, contenttype=None):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
272 """ create a list of templates (for some specific contenttype) """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
273 terms = [Term(WIKINAME, app.cfg.interwikiname), Term(TAGS, u'template')]
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
274 if contenttype is not None:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
275 terms.append(Term(CONTENTTYPE, contenttype))
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
276 query = And(terms)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
277 revs = flaskg.storage.search(query, sortedby=NAME_EXACT, limit=None)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
278 return [rev.meta[NAME] for rev in revs]
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
279
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
280
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
281 @register
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
282 class NonExistentContent(Content):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
283 """Dummy Content to use with NonExistent."""
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
284 contenttype = 'application/x-nonexistent'
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
285 group = None
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
286
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
287 def do_get(self, force_attachment=False, mimetype=None):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
288 abort(404)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
289
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
290 def _convert(self, doc):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
291 abort(404)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
292
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
293
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
294 @register
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
295 class Binary(Content):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
296 """ An arbitrary binary item, fallback class for every item mimetype. """
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
297 contenttype = '*/*'
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
298
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
299 # XXX reads item rev data into memory!
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
300 def get_data(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
301 if self.rev is not None:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
302 return self.rev.data.read()
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
303 else:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
304 return ''
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
305 data = property(fget=get_data)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
306
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
307 class ModifyForm(Form):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
308 template = 'modify_binary.html'
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
309 help = """\
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
310 There is no help, you're doomed!
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
311 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
312 data_file = File.using(optional=True, label=L_('Upload file:'))
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
313
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
314 def _load(self, item):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
315 pass
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
316
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
317 def _dump(self, item):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
318 data_file = self['data_file'].value
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
319 if data_file:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
320 data = data_file.stream
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
321 # this is likely a guess by the browser, based on the filename
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
322 contenttype_guessed = data_file.content_type # comes from form multipart data
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
323 return data, contenttype_guessed
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
324 else:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
325 return None, None
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
326
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
327 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
328 hash_name = HASH_ALGORITHM
860
de6ece090b7d fix download view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
329 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
330 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
331 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
332 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
333
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
334 _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
335 _render_data_diff_raw = _render_data_diff
1211
e63c9c8d0ad9 Move revision info to the end
Shitiz Garg <mail@dragooon.net>
parents: 1210
diff changeset
336
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
337 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
338 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
339 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
340 content=Markup(self._render_data()))
1198
2aa4f4ec6a94 Minor fixes for atom feed
Shitiz Garg <mail@dragooon.net>
parents: 1197
diff changeset
341
1099
2068f99501c5 fix a few bugs exposed by the new view tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1023
diff changeset
342 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
343 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
344 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
345
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
346 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
347 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
348 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
349 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
350 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
351 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
352
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
353 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
354 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
355 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
356
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
357 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
358 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
359 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
360 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
361 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
362 file_to_send = self.get_member(member)
1898
2b4bcb80d644 for archive members, force attachment download mode, so it uses the member filename, fixes #306
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1897
diff changeset
363 # force attachment download, so it uses attachment_filename
2b4bcb80d644 for archive members, force attachment download mode, so it uses the member filename, fixes #306
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1897
diff changeset
364 # otherwise it will use the itemname from the URL for saving
2b4bcb80d644 for archive members, force attachment download mode, so it uses the member filename, fixes #306
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1897
diff changeset
365 force_attachment = True
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
366 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
367 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
368 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
369 try:
860
de6ece090b7d fix download view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
370 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
371 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
372 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
373 else:
faa06b4873dd more contenttype related changes/fixes, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 216
diff changeset
374 mt = MimeType(mimestr=mimestr)
860
de6ece090b7d fix download view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
375 content_length = rev.meta[SIZE]
de6ece090b7d fix download view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
376 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
377 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
378 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
379 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
380 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
381 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
382 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
383 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
384 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
385 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
386 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
387
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
388
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
389 @register
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
390 class OctetStream(Binary):
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
391 """
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
392 Fallback Content for uploaded file of unknown contenttype.
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
393 """
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
394 contenttype = 'application/octet-stream'
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
395 display_name = 'binary file'
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
396
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
397
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
398 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
399 """ 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
400
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
401
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
402 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
403 """ 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
404
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
405
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
406 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
407 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
408 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
409 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
410 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
411 def 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
412 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
413 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
414 """
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
415 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
416 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
417 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
418
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
419 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
420 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
421 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
422
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
423 :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
424 """
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
425 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
426 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
427 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
428
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
429 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
430 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
431 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
432 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
433 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
434
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
435 :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
436 :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
437 :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
438 :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
439 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
440 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
441 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
442 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
443 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
444 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
445 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
446 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
447 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
448 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
449 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
450 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
451 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
452 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
453 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
454 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
455 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
456 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
457 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
458 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
459 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
460 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
461 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
462 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
463 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
464 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
465 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
466 # 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
467 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
468 data = open(temp_fname, 'rb')
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
469 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
470 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
471 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
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
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
474 @register
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
475 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
476 """
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 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
478 """
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
479 contenttype = 'application/x-tar'
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
480 display_name = 'TAR'
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
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
482
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
483 @register
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
484 class ApplicationXGTar(ApplicationXTar):
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
485 """
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
486 Compressed tar items
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
487 """
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
488 contenttype = 'application/x-gtar'
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
489 display_name = 'TGZ'
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
490
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
491
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
492 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
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 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
495 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
496 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
497 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
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 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
500 """
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
501 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
502 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
503 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
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 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
506 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
507 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
508
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
509 :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
510 """
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
511 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
512 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
513 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
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 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
516 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
517
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
518
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
519 @register
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
520 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
521 """
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
522 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
523 """
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
524 contenttype = 'application/zip'
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
525 display_name = '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
526
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
527
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
528 @register
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
529 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
530 """ PDF """
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
531 contenttype = 'application/pdf'
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
532 display_name = '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
533
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
534
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
535 @register
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
536 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
537 """ Base class for video/* """
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
538 contenttype = 'video/*'
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
539 group = GROUP_VIDEO
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
540
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
541
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
542 @register
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
543 class OGGVideo(Video):
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
544 contenttype = 'video/ogg'
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
545 display_name = 'OGG'
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
546
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
547
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
548 @register
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
549 class WebMVideo(Video):
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
550 contenttype = 'video/webm'
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
551 display_name = 'WebM'
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
552
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
553
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
554 @register
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
555 class MP4(Video):
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
556 contenttype = 'video/mp4'
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
557 display_name = 'MP4'
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
558
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
559
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
560 @register
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
561 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
562 """ Base class for audio/* """
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
563 contenttype = 'audio/*'
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
564 group = GROUP_AUDIO
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
565
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
566
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
567 @register
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
568 class WAV(Audio):
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
569 contenttype = 'audio/wave'
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
570 display_name = 'WAV'
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
571
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
572
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
573 @register
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
574 class OGGAudio(Audio):
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
575 contenttype = 'audio/ogg'
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
576 display_name = 'OGG'
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
577
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
578
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
579 @register
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
580 class MP3(Audio):
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
581 contenttype = 'audio/mpeg'
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
582 display_name = 'MP3'
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
583
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
584
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
585 @register
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
586 class WebMAudio(Audio):
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
587 contenttype = 'audio/webm'
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
588 display_name = 'WebM'
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
589
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
590
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
591 @register
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
592 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
593 """ Base class for image/* """
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
594 contenttype = '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
595
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
596
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
597 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
598 """ Base class for renderable Image mimetypes """
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
599 group = GROUP_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
600
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
601
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
602 @register
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 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
604 """ SVG images use <object> tag mechanism from RenderableBinary base class """
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
605 contenttype = 'image/svg+xml'
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
606 display_name = 'SVG'
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
607
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
608
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
609 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
610 """ 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
611 # 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
612
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
613
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
614 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
615 """ 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
616 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
617 """ 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
618 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
619 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
620 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
621 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
622 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
623 # 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
624 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
625
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
626 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
627 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
628 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
629 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
630 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
631 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
632 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
633 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
634
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
635 # 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
636 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
637 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
638
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
639 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
640 # 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
641 # 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
642 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
643 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
644 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
645
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
646 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
647 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
648 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
649
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
650 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
651 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
652 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
653 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
654 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
655 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
656 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
657 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
658 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
659 }
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
660 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
661
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
662 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
663 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
664 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
665 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
666 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
667
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
668 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
669 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
670 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
671 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
672 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
673 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
674 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
675 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
676 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
677 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
678 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
679 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
680 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
681 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
682 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
683 # 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
684 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
685 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
686 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
687 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
688 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
689 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
690 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
691 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
692 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
693 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
694 else:
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
695 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
696 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
697 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
698 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
699 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
700 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
701 # 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
702 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
703 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
704 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
705 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
706
1209
c0eaed311e0e Try using PIL for image diffs
Shitiz Garg <mail@dragooon.net>
parents: 1208
diff changeset
707 def _render_data_diff_atom(self, oldrev, newrev):
c0eaed311e0e Try using PIL for image diffs
Shitiz Garg <mail@dragooon.net>
parents: 1208
diff changeset
708 if PIL is None:
c0eaed311e0e Try using PIL for image diffs
Shitiz Garg <mail@dragooon.net>
parents: 1208
diff changeset
709 # 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
710 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
711 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
712 return render_template('atom.html',
c0eaed311e0e Try using PIL for image diffs
Shitiz Garg <mail@dragooon.net>
parents: 1208
diff changeset
713 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
714 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
715
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
716 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
717 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
718 # 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
719 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
720 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
721 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
722
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
723 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
724 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
725 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
726 hash_name=hash_name,
860
de6ece090b7d fix download view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
727 hash_old=oldrev.meta[hash_name],
de6ece090b7d fix download view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
728 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
729 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
730 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
731 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
732 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
733
860
de6ece090b7d fix download view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
734 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
735 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
736 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
737 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
738 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
739 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
740 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
741 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
742 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
743
256
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
744 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
745 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
746 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
747 oldimage.load()
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
748 newimage.load()
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
749 diffimage = PILdiff(newimage, oldimage)
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
750 outfile = StringIO()
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
751 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
752 data = outfile.getvalue()
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
753 outfile.close()
02888ad76719 added exception handling if PIL can't diff the image
bsx <bsx+bitbucket@0xcafec0.de>
parents: 255
diff changeset
754 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
755 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
756 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
757 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
758 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
759 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
760 # 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
761 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
762 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
763
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
764 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
765 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
766
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
767
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
768 @register
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
769 class PNG(TransformableBitmapImage):
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
770 """ PNG image. """
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
771 contenttype = 'image/png'
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
772 display_name = 'PNG'
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
773
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
774
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
775 @register
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
776 class JPEG(TransformableBitmapImage):
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
777 """ JPEG image. """
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
778 contenttype = 'image/jpeg'
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
779 display_name = 'JPEG'
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
780
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
781
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
782 @register
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
783 class GIF(TransformableBitmapImage):
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
784 """ GIF image. """
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
785 contenttype = 'image/gif'
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
786 display_name = 'GIF'
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
787
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
788
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
789 @register
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
790 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
791 """ Base class for text/* """
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
792 contenttype = 'text/*'
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
793 default_contenttype_params = dict(charset='utf-8')
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
794 group = GROUP_OTHER_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
795
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1361
diff changeset
796 class ModifyForm(Binary.ModifyForm):
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
797 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
798 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
799 rows = ROWS_DATA
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
800 cols = COLS
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1361
diff changeset
801
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
802 def _load(self, item):
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
803 super(Text.ModifyForm, self)._load(item)
1408
94dda5c633d2 Minor fixes to previous items cleanup changeset.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1407
diff changeset
804 data = item.data
94dda5c633d2 Minor fixes to previous items cleanup changeset.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1407
diff changeset
805 data = item.data_storage_to_internal(data)
94dda5c633d2 Minor fixes to previous items cleanup changeset.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1407
diff changeset
806 data = item.data_internal_to_form(data)
94dda5c633d2 Minor fixes to previous items cleanup changeset.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1407
diff changeset
807 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
808
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
809 def _dump(self, item):
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
810 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
811 if data is None:
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
812 data = self['data_text'].value
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
813 data = item.data_form_to_internal(data)
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
814 data = item.data_internal_to_storage(data)
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
815 # 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
816 contenttype_guessed = u'text/plain;charset=utf-8'
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
817 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
818
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
819 # 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
820 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
821 """ 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
822 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
823
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
824 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
825 """ 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
826 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
827
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
828 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
829 """ 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
830 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
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 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
833 """ 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
834 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
835
1197
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
836 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
837 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
838 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
839 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
840 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
841 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
842 return render_template(template,
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
843 item_name=self.name,
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
844 oldrev=oldrev,
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
845 newrev=newrev,
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
846 diffs=diffs,
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
847 )
1198
2aa4f4ec6a94 Minor fixes for atom feed
Shitiz Garg <mail@dragooon.net>
parents: 1197
diff changeset
848
1197
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
849 def _render_data_diff_atom(self, oldrev, newrev):
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
850 """ renders diff in HTML for atom feed """
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
851 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
852
1197
98ff5e7a0bec Improved atom feed for page history
Shitiz Garg <mail@dragooon.net>
parents: 1180
diff changeset
853 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
854 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
855
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
856 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
857 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
858 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
859 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
860 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
861 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
862
1112
b02f88f4428e Fix diffraw view, fix text diffraw
Sam Toyer <samATqxcvDOTnet>
parents: 1099
diff changeset
863 _render_data_diff_raw = _render_data_diff
b02f88f4428e Fix diffraw view, fix text diffraw
Sam Toyer <samATqxcvDOTnet>
parents: 1099
diff changeset
864
202
9ffa82e550ba highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 197
diff changeset
865 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
866 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
867 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
868 # 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
869 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
870 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
871 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
872 # 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
873 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
874 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
875 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
876
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
877
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
878 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
879 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
880 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
881 (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
882 """
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
883 group = GROUP_MARKUP_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
884
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
885
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
886 @register
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
887 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
888 """ MoinMoin wiki markup """
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
889 contenttype = 'text/x.moin.wiki'
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
890 display_name = 'Wiki (MoinMoin)'
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
891
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
892
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
893 @register
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
894 class CreoleWiki(MarkupItem):
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
895 """ Creole wiki markup """
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
896 contenttype = 'text/x.moin.creole'
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
897 display_name = 'Wiki (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
898
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
899
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
900 @register
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
901 class MediaWiki(MarkupItem):
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
902 """ MediaWiki markup """
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
903 contenttype = 'text/x-mediawiki'
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
904 display_name = 'Wiki (MediaWiki)'
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
905
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
906
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
907 @register
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
908 class 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
909 """ ReStructured Text markup """
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
910 contenttype = 'text/x-rst'
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
911 display_name = 'ReST'
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
912
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
913
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
914 @register
1666
fa66e4447d63 add markdown converter, thanks to Andreas Kloeckner
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1649
diff changeset
915 class Markdown(MarkupItem):
fa66e4447d63 add markdown converter, thanks to Andreas Kloeckner
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1649
diff changeset
916 """ Markdown markup """
fa66e4447d63 add markdown converter, thanks to Andreas Kloeckner
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1649
diff changeset
917 contenttype = 'text/x-markdown'
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
918 display_name = 'Markdown'
1666
fa66e4447d63 add markdown converter, thanks to Andreas Kloeckner
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1649
diff changeset
919
fa66e4447d63 add markdown converter, thanks to Andreas Kloeckner
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1649
diff changeset
920
fa66e4447d63 add markdown converter, thanks to Andreas Kloeckner
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1649
diff changeset
921 @register
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
922 class HTML(MarkupItem):
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
923 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
924 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
925
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
926 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
927 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
928 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
929
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
930 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
931 """
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
932 contenttype = 'text/html'
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
933 display_name = 'HTML'
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
934
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
935 class ModifyForm(Text.ModifyForm):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
936 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
937
225
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
938
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
939 @register
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
940 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
941 """ DocBook Document """
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
942 contenttype = 'application/docbook+xml'
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
943 display_name = 'DocBook'
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
944
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
945 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
946 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
947 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
948
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
949 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
950
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
951 # 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
952 # 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
953 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
954
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
955 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
956
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
957 # 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
958 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
959 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
960 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
961 }
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
962
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
963 # 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
964 # 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
965 # 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
966 # 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
967 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
968 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
969 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
970
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
971 # 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
972 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
973 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
974 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
975 # 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
976 # 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
977 # 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
978 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
979 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
980 # 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
981 # 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
982 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
983 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
984 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
985 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
986 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
987
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
988
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
989 @register
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
990 class PlainText(Text):
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
991 contenttype = 'text/plain'
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
992 display_name = 'plain text'
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
993
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
994
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
995 @register
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
996 class Diff(Text):
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
997 contenttype = 'text/x-diff'
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
998 display_name = 'diff/patch'
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
999
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
1000
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
1001 @register
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
1002 class PythonCode(Text):
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
1003 contenttype = 'text/x-python'
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
1004 display_name = 'python code'
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
1005
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
1006
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
1007 @register
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
1008 class CSV(Text):
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
1009 contenttype = 'text/csv'
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
1010 display_name = 'csv'
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
1011
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
1012
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
1013 @register
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
1014 class IRCLog(Text):
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
1015 contenttype = 'text/x-irclog'
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
1016 display_name = 'IRC log'
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
1017
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
1018
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1361
diff changeset
1019 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
1020 """
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1361
diff changeset
1021 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
1022 """
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
1023 group = GROUP_DRAWING
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
1024
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1361
diff changeset
1025 class ModifyForm(Binary.ModifyForm):
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
1026 # Set the workaround flag respected in modify.html
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
1027 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
1028
1881
a1edfcdddd34 fix method signature of Draw base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1826
diff changeset
1029 def handle_post(self):
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
1030 raise NotImplementedError
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
1031
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1361
diff changeset
1032
1900
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1033 class DrawPNGMap(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
1034 """
1900
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1035 Base class for drawings that have a png with click map
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1036 """
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1037 def _read_map(self):
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1038 mapfile = self.get_member('drawing.map')
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1039 try:
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1040 image_map = mapfile.read()
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1041 mapfile.close()
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1042 except (IOError, OSError):
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1043 image_map = ''
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1044 return image_map
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
1045
1900
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1046 def _transform_map(self, image_map, title):
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1047 raise NotImplementedError
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1048
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1049 def _render_data(self):
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1050 # TODO: this could be a converter -> dom, then transcluding this kind
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1051 # of items and also rendering them with the code in base class could work
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1052 png_url = url_for('frontend.get_item', item_name=self.name, member='drawing.png', rev=self.rev.revid)
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1053 title = _('Edit drawing %(filename)s (opens in new window)', filename=self.name)
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1054 image_map = self._read_map()
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1055 if image_map:
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1056 mapid, image_map = self._transform_map(image_map, title)
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1057 title = _('Clickable drawing: %(filename)s', filename=self.name)
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1058 return Markup(image_map + u'<img src="{0}" alt="{1}" usemap="#{2}" />'.format(png_url, title, mapid))
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1059 else:
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1060 return Markup(u'<img src="{0}" alt="{1}" />'.format(png_url, title))
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1061
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1062
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1063 class DrawAWDTWDBase(DrawPNGMap):
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1064 """
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1065 Shared code between TWikiDraw and AnyWikiDraw
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1066 """
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1067 _expected_members = set()
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1068
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
1069 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
1070 # 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
1071 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
1072 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
1073 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
1074 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
1075 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
1076 content_length = None
1900
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1077 if ext in ['.svg', '.draw', ]: # handle AWD (svg) and TWD (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
1078 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
1079 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
1080 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
1081 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
1082 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
1083 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
1084 #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
1085 # 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
1086 # 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
1087 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
1088 self.put_member('drawing' + ext, filecontent, content_length,
1900
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1089 expected_members=self._expected_members)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1090
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
1091
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
1092 @register
1900
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1093 class TWikiDraw(DrawAWDTWDBase):
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1094 """
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1095 drawings by TWikiDraw applet. It creates three files which are stored as tar file.
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1096 """
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1097 contenttype = 'application/x-twikidraw'
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1098 display_name = 'TDRAW'
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1099 _expected_members = set(['drawing.draw', 'drawing.map', 'drawing.png'])
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1100
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1101 class ModifyForm(Draw.ModifyForm):
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1102 template = "modify_twikidraw.html"
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1103 help = ""
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1104
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1105 def _transform_map(self, image_map, title):
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1106 mapid = 'ImageMapOf' + self.name # TODO: make it unique
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1107 image_map = image_map.replace('%MAPNAME%', mapid)
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1108 # add alt and title tags to areas
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1109 image_map = re.sub(r'href\s*=\s*"((?!%TWIKIDRAW%).+?)"',
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1110 r'href="\1" alt="\1" title="\1"', image_map)
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1111 drawing_url = url_for('frontend.get_item', item_name=self.name, member='drawing.draw', rev=self.rev.revid)
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1112 image_map = image_map.replace('%TWIKIDRAW%"', '{0}" alt="{1}" title="{2}"'.format(drawing_url, title, title))
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1113 return mapid, image_map
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1114
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1115
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1116 @register
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1117 class AnyWikiDraw(DrawAWDTWDBase):
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1118 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1119 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
1120 """
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
1121 contenttype = 'application/x-anywikidraw'
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
1122 display_name = 'ADRAW'
1900
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1123 _expected_members = set(['drawing.svg', 'drawing.map', 'drawing.png'])
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1124
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1361
diff changeset
1125 class ModifyForm(Draw.ModifyForm):
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
1126 template = "modify_anywikidraw.html"
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
1127 help = ""
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
1128 def _load(self, item):
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
1129 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
1130 try:
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
1131 drawing_exists = 'drawing.svg' in item.list_members()
1393
0f0932809e1e Fix broken AnyWikiDraw.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1392
diff changeset
1132 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
1133 drawing_exists = False
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
1134 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
1135
1900
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1136 def _transform_map(self, image_map, title):
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1137 #drawing_url = url_for('frontend.get_item', item_name=self.name, member='drawing.svg', rev=self.rev.revid)
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1138 mapid = 'ImageMapOf' + self.name # TODO: make it unique
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1139 image_map = image_map.replace(u'id="drawing.svg"', '')
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1140 image_map = image_map.replace(u'name="drawing.svg"', u'name="{0}"'.format(mapid))
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1141 # unxml, because 4.01 concrete will not validate />
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1142 image_map = image_map.replace(u'/>', u'>')
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1143 return mapid, image_map
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1144
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
1145
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
1146 @register
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1361
diff changeset
1147 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
1148 """ drawings by svg-edit. It creates two files (svg, png) which are stored as tar file. """
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
1149 contenttype = 'application/x-svgdraw'
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1764
diff changeset
1150 display_name = 'SVGDRAW'
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
1151
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
1152 class ModifyForm(Draw.ModifyForm):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
1153 template = "modify_svg-edit.html"
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
1154 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
1155
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
1156 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
1157 # 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
1158 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
1159 svg_upload = request.values.get('filepath')
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
1160 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
1161 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
1162 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
1163 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
1164 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
1165 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
1166 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
1167 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
1168
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1169 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
1170 # 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
1171 # of items and also rendering them with the code in base class could work
1900
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1172 drawing_url = url_for('frontend.get_item', item_name=self.name, member='drawing.svg', rev=self.rev.revid)
d4a382f781c9 deduplicated and refactored drawing item code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1898
diff changeset
1173 png_url = url_for('frontend.get_item', item_name=self.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
1174 return Markup(u'<img src="{0}" alt="{1}" />'.format(png_url, drawing_url))