annotate MoinMoin/items/content.py @ 1801:f6afb9aeb861

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