annotate MoinMoin/items/__init__.py @ 1614:5b5e7190452f

Fix various registry Entry `__lt__` methods. This resolves issue #221.
author Cheer Xiao <xiaqqaix@gmail.com>
date Wed, 01 Aug 2012 00:21:41 +0800
parents bc8a2546468b
children 8f0a17a04e60 c6974ba2e2b2
rev   line source
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1361
diff changeset
1 # Copyright: 2012 MoinMoin:CheerXiao
26
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
2 # Copyright: 2009 MoinMoin:ThomasWaldmann
254
91330de48b9c items: implemented 2.6 r:2031 alpha of svg-edit using a save extension for doing a single post for svg and png data.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 248
diff changeset
3 # Copyright: 2009-2011 MoinMoin:ReimarBauer
26
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
4 # Copyright: 2009 MoinMoin:ChristopherDenter
225
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
5 # Copyright: 2008,2009 MoinMoin:BastianBlank
26
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
6 # Copyright: 2010 MoinMoin:ValentinJaniaut
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
7 # Copyright: 2010 MoinMoin:DiogenesAugusto
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
8 # License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
9
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
10 """
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
11 MoinMoin - high-level (frontend) items
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
12
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
13 While MoinMoin.storage cares for backend storage of items,
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
14 this module cares for more high-level, frontend items,
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
15 e.g. showing, editing, etc. of wiki items.
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
16
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
17 Each class in this module corresponds to an itemtype.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
18 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
19
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
20 import re, time
486
b6149c732926 contenttype filtering added to global index page
Akash Sinha <akash2607@gmail.com>
parents: 484
diff changeset
21 import itertools
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
22 from StringIO import StringIO
1613
bc8a2546468b Clean up registry code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1460
diff changeset
23 from collections import namedtuple
bc8a2546468b Clean up registry code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1460
diff changeset
24 from functools import partial
173
89f50aed143f move mimetype related code from wikiutil to util.mimetype
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 170
diff changeset
25
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
26 from flatland import Form
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
27 from flatland.validation import Validator
779
815c46100e2c whooshify get_templates, adapt MimeType analyzer so it yields also a full and normalized contenttype
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 525
diff changeset
28
780
f5e0f85e66ce whooshify get_index()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 779
diff changeset
29 from whoosh.query import Term, And, Prefix
779
815c46100e2c whooshify get_templates, adapt MimeType analyzer so it yields also a full and normalized contenttype
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 525
diff changeset
30
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
31 from MoinMoin.forms import RequiredText, OptionalText, OptionalMultilineText, Tags, Submit
242
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
32
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
33 from MoinMoin.security.textcha import TextCha, TextChaizedForm
242
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
34 from MoinMoin.signalling import item_modified
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
35 from MoinMoin.util.mime import Type
1005
c36f61f85e97 AccessDeniedError replaced by AccessDenied, from the new storage api.
Bruno Martin <bruno@hacklab.com.br>
parents: 1004
diff changeset
36 from MoinMoin.storage.middleware.protecting import AccessDenied
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
37
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
38 from MoinMoin import log
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
39 logging = log.getLogger(__name__)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
40
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
41 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
42 import json
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
43 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
44 import simplejson as json
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
45
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
46 from flask import current_app as app
109
e4c332436733 remove flask monkeypatch, use 'from flask import g as flaskg'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 103
diff changeset
47 from flask import g as flaskg
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
48
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
49 from flask import request, Response, redirect, abort, escape
242
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
50
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
51 from werkzeug import is_resource_modified
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
52
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
53 from MoinMoin.i18n import L_
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
54 from MoinMoin.themes import render_template
316
4ee796d759bf use url_for_item where appropriate (in py code, no template changes yet)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 315
diff changeset
55 from MoinMoin.util.interwiki import url_for_item
1005
c36f61f85e97 AccessDeniedError replaced by AccessDenied, from the new storage api.
Bruno Martin <bruno@hacklab.com.br>
parents: 1004
diff changeset
56 from MoinMoin.storage.error import NoSuchItemError, NoSuchRevisionError, StorageError
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
57 from MoinMoin.util.registry import RegistryBase
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
58 from MoinMoin.constants.keys import (
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
59 NAME, NAME_OLD, NAME_EXACT, WIKINAME, MTIME, SYSITEM_VERSION, ITEMTYPE,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
60 CONTENTTYPE, SIZE, TAGS, ACTION, ADDRESS, HOSTNAME, USERID, COMMENT,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
61 HASH_ALGORITHM, ITEMID, REVID, DATAID, CURRENT, PARENTID
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
62 )
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
63 from MoinMoin.constants.contenttypes import charset, CONTENTTYPE_GROUPS
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
64
1456
fc1f874695e1 Fix missing imports due to Content sepration, discovered with pyflakes
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1454
diff changeset
65 from .content import Draw, NonExistentContent, content_registry
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
66
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
67
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
68 COLS = 80
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
69 ROWS_META = 10
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
70
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
71
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
72 class RegistryItem(RegistryBase):
1613
bc8a2546468b Clean up registry code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1460
diff changeset
73 class Entry(namedtuple('Entry', 'factory itemtype priority')):
bc8a2546468b Clean up registry code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1460
diff changeset
74 def __call__(self, itemtype, *args, **kw):
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
75 if self.itemtype == itemtype:
1613
bc8a2546468b Clean up registry code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1460
diff changeset
76 return self.factory(*args, **kw)
225
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
77
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
78 def __lt__(self, other):
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
79 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
80 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
81 return self.priority < other.priority
5b5e7190452f Fix various registry Entry `__lt__` methods. This resolves issue #221.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1613
diff changeset
82 return self.itemtype < other.itemtype
225
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
83 return NotImplemented
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
84
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
85
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
86 def register(self, factory, itemtype, priority=RegistryBase.PRIORITY_MIDDLE):
225
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
87 """
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
88 Register a factory
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
89
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
90 :param factory: Factory to register. Callable, must return an object.
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
91 """
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
92 return self._register(self.Entry(factory, itemtype, priority))
225
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
93
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
94
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
95 item_registry = RegistryItem()
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
96
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
97
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
98 class DummyRev(dict):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
99 """ if we have no stored Revision, we use this dummy """
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 204
diff changeset
100 def __init__(self, item, contenttype):
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
101 self.item = item
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
102 self.meta = {CONTENTTYPE: contenttype}
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
103 self.data = StringIO('')
891
d90782ad8b24 instead of parent revno (int), we give parent revid (str) now
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 890
diff changeset
104 self.revid = None
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
105
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
106
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
107 class DummyItem(object):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
108 """ if we have no stored Item, we use this dummy """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
109 def __init__(self, name):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
110 self.name = name
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
111 def list_revisions(self):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
112 return [] # same as an empty Item
1180
1c5a013b9ebd Fix the three failing tests.
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1152
diff changeset
113 def destroy_all_revisions(self):
1c5a013b9ebd Fix the three failing tests.
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1152
diff changeset
114 return True
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
115
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
116
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
117 class ValidJSON(Validator):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
118 """Validator for JSON
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
119 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
120 invalid_json_msg = L_('Invalid JSON.')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
121
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
122 def validate(self, element, state):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
123 try:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
124 json.loads(element.value)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
125 except:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
126 return self.note_error(element, state, 'invalid_json_msg')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
127 return True
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
128
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
129
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
130 class BaseChangeForm(TextChaizedForm):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
131 comment = OptionalText.using(label=L_('Comment')).with_properties(placeholder=L_("Comment about your change"))
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
132 submit = Submit
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
133
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
134
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
135 class Item(object):
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
136 """ Highlevel (not storage) Item, wraps around a storage Revision"""
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
137 @classmethod
1613
bc8a2546468b Clean up registry code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1460
diff changeset
138 def _factory(cls, *args, **kw):
bc8a2546468b Clean up registry code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1460
diff changeset
139 return cls(*args, **kw)
225
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
140
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
141 # TODO split Content creation to Content.create
225
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
142 @classmethod
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
143 def create(cls, name=u'', itemtype=None, contenttype=None, rev_id=CURRENT, item=None):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
144 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
145 Create a highlevel Item by looking up :name or directly wrapping
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
146 :item and extract the Revision designated by :rev_id revision.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
147
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
148 The highlevel Item is created by creating an instance of Content
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
149 subclass according to the item's contenttype metadata entry; The
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
150 :contenttype argument can be used to override contenttype. It is used
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
151 only when handling +convert (when deciding the contenttype of target
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
152 item), +modify (when creating a new item whose contenttype is not yet
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
153 decided), +diff and +diffraw (to coerce the Content to a common
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
154 super-contenttype of both revisions).
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
155
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
156 After that the Content instance, an instance of Item subclass is
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
157 created according to the item's itemtype metadata entry, and the
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
158 previously created Content instance is assigned to its content
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
159 property.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
160 """
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 204
diff changeset
161 if contenttype is None:
415
d755f798fe66 fix some tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 402
diff changeset
162 contenttype = u'application/x-nonexistent'
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
163 if itemtype is None:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
164 itemtype = u'nonexistent'
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
165 if 1: # try:
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
166 if item is None:
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
167 item = flaskg.storage[name]
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
168 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
169 name = item.name
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
170 if not item: # except NoSuchItemError:
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
171 logging.debug("No such item: {0!r}".format(name))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
172 item = DummyItem(name)
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 204
diff changeset
173 rev = DummyRev(item, contenttype)
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
174 logging.debug("Item {0!r}, created dummy revision with contenttype {1!r}".format(name, contenttype))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
175 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
176 logging.debug("Got item: {0!r}".format(name))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
177 try:
905
51475954290f rename all revno usages to revid (no numbers any more), remove update_item param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 904
diff changeset
178 rev = item.get_revision(rev_id)
415
d755f798fe66 fix some tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 402
diff changeset
179 contenttype = u'application/octet-stream' # it exists
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
180 itemtype = u'default' # default itemtype to u'default' for compatibility
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
181 except KeyError: # NoSuchRevisionError:
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
182 try:
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
183 rev = item.get_revision(CURRENT) # fall back to current revision
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
184 # XXX add some message about invalid revision
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
185 except KeyError: # NoSuchRevisionError:
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
186 logging.debug("Item {0!r} has no revisions.".format(name))
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 204
diff changeset
187 rev = DummyRev(item, contenttype)
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
188 logging.debug("Item {0!r}, created dummy revision with contenttype {1!r}".format(name, contenttype))
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
189 logging.debug("Got item {0!r}, revision: {1!r}".format(name, rev_id))
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
190 contenttype = rev.meta.get(CONTENTTYPE) or contenttype # use contenttype in case our metadata does not provide CONTENTTYPE
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
191 logging.debug("Item {0!r}, got contenttype {1!r} from revision meta".format(name, contenttype))
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
192 #logging.debug("Item %r, rev meta dict: %r" % (name, dict(rev.meta)))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
193
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
194 # XXX Cannot pass item=item to Content.__init__ via
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
195 # content_registry.get yet, have to patch it later.
1613
bc8a2546468b Clean up registry code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1460
diff changeset
196 content = content_registry.get(contenttype)
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
197 logging.debug("Content class {0!r} handles {1!r}".format(content.__class__, contenttype))
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
198
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
199 itemtype = rev.meta.get(ITEMTYPE) or itemtype
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
200 logging.debug("Item {0!r}, got itemtype {1!r} from revision meta".format(name, itemtype))
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
201
1613
bc8a2546468b Clean up registry code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1460
diff changeset
202 item = item_registry.get(itemtype, name, rev=rev, content=content)
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
203 logging.debug("Item class {0!r} handles {1!r}".format(item.__class__, itemtype))
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
204
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
205 content.item = item
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
206
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
207 return item
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
208
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
209 def __init__(self, name, rev=None, content=None):
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
210 self.name = name
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
211 self.rev = rev
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
212 self.content = content
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
213
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
214 def get_meta(self):
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
215 return self.rev.meta
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
216 meta = property(fget=get_meta)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
217
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
218 # XXX Backward compatibility, remove soon
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
219 @property
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
220 def contenttype(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
221 return self.content.contenttype if self.content else None
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
222
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
223 def _render_meta(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
224 return "<pre>{0}</pre>".format(escape(self.meta_dict_to_text(self.meta, use_filter=False)))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
225
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
226 def meta_filter(self, meta):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
227 """ kill metadata entries that we set automatically when saving """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
228 kill_keys = [# shall not get copied from old rev to new rev
1019
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
229 SYSITEM_VERSION,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
230 NAME_OLD,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
231 # are automatically implanted when saving
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
232 NAME,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
233 ITEMID, REVID, DATAID,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
234 HASH_ALGORITHM,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
235 SIZE,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
236 COMMENT,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
237 MTIME,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
238 ACTION,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
239 ADDRESS, HOSTNAME, USERID,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
240 ]
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
241 for key in kill_keys:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
242 meta.pop(key, None)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
243 return meta
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
244
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
245 def meta_text_to_dict(self, text):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
246 """ convert meta data from a text fragment to a dict """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
247 meta = json.loads(text)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
248 return self.meta_filter(meta)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
249
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
250 def meta_dict_to_text(self, meta, use_filter=True):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
251 """ convert meta data from a dict to a text fragment """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
252 meta = dict(meta)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
253 if use_filter:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
254 meta = self.meta_filter(meta)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
255 return json.dumps(meta, sort_keys=True, indent=2, ensure_ascii=False)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
256
892
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
257 def prepare_meta_for_modify(self, meta):
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
258 """
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
259 transform the meta dict of the current revision into a meta dict
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
260 that can be used for savind next revision (after "modify").
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
261 """
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
262 meta = dict(meta)
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
263 revid = meta.pop(REVID, None)
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
264 if revid is not None:
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
265 meta[PARENTID] = revid
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
266 return meta
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
267
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
268 def _rename(self, name, comment, action):
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
269 self._save(self.meta, self.content.data, name=name, action=action, comment=comment)
1019
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
270 for child in self.get_index():
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
271 item = Item.create(child[0])
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
272 item._save(item.meta, item.content.data, name='/'.join((name, child[1])), action=action, comment=comment)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
273
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
274 def rename(self, name, comment=u''):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
275 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
276 rename this item to item <name>
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
277 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
278 return self._rename(name, comment, action=u'RENAME')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
279
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
280 def delete(self, comment=u''):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
281 """
904
46263060782e remove references to "trash" (is an implementation detail and might change)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 903
diff changeset
282 delete this item
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
283 """
903
50aa61c9b952 fixed rename issue: do not use the new name to load the item, but the old one
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 902
diff changeset
284 trash_prefix = u'Trash/' # XXX move to config
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
285 now = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime())
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
286 # make trash name unique by including timestamp:
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
287 trashname = u'{0}{1} ({2} UTC)'.format(trash_prefix, self.name, now)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
288 return self._rename(trashname, comment, action=u'TRASH')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
289
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
290 def revert(self, comment=u''):
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
291 return self._save(self.meta, self.content.data, action=u'REVERT', comment=comment)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
292
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
293 def destroy(self, comment=u'', destroy_item=False):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
294 # called from destroy UI/POST
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
295 if destroy_item:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
296 # destroy complete item with all revisions, metadata, etc.
910
5b7e522d97af fix destroy
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 908
diff changeset
297 self.rev.item.destroy_all_revisions()
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
298 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
299 # just destroy this revision
910
5b7e522d97af fix destroy
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 908
diff changeset
300 self.rev.item.destroy_revision(self.rev.revid)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
301
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
302 def modify(self, meta, data, comment=u'', contenttype_guessed=None, contenttype_qs=None):
236
7a77ae08161e items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 225
diff changeset
303 if contenttype_qs:
7a77ae08161e items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 225
diff changeset
304 # we use querystring param to FORCE content type
7a77ae08161e items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 225
diff changeset
305 meta[CONTENTTYPE] = contenttype_qs
7a77ae08161e items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 225
diff changeset
306
7a77ae08161e items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 225
diff changeset
307 return self._save(meta, data, contenttype_guessed=contenttype_guessed, comment=comment)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
308
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
309 class _ModifyForm(BaseChangeForm):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
310 """Base class for ModifyForm of Item subclasses."""
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
311 meta_text = OptionalMultilineText.using(label=L_("MetaData (JSON)")).with_properties(rows=ROWS_META, cols=COLS).validated_by(ValidJSON())
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
312
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
313 def _load(self, item):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
314 self['meta_text'] = item.meta_dict_to_text(item.prepare_meta_for_modify(item.meta))
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
315 self['content_form']._load(item.content)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
316
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
317 def _dump(self, item):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
318 meta = item.meta_text_to_dict(self['meta_text'].value)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
319 data, contenttype_guessed = self['content_form']._dump(item.content)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
320 comment = self['comment'].value
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
321 return meta, data, contenttype_guessed, comment
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
322
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
323 @classmethod
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
324 def from_item(cls, item):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
325 form = cls.from_defaults()
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
326 TextCha(form).amend_form()
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
327 form._load(item)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
328 return form
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
329
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
330 @classmethod
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
331 def from_request(cls, request):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
332 form = cls.from_flat(request.form.items() + request.files.items())
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
333 TextCha(form).amend_form()
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
334 return form
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
335
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
336 def do_modify(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
337 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
338 Handle +modify requests, both GET and POST.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
339
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
340 This method should be overridden in subclasses, providing polymorphic
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
341 behavior for the +modify view.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
342 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
343 raise NotImplementedError
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
344
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
345 def _save(self, meta, data=None, name=None, action=u'SAVE', contenttype_guessed=None, comment=u'', overwrite=False):
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
346 backend = flaskg.storage
903
50aa61c9b952 fixed rename issue: do not use the new name to load the item, but the old one
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 902
diff changeset
347 storage_item = backend[self.name]
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
348 try:
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
349 currentrev = storage_item.get_revision(CURRENT)
905
51475954290f rename all revno usages to revid (no numbers any more), remove update_item param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 904
diff changeset
350 rev_id = currentrev.revid
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
351 contenttype_current = currentrev.meta.get(CONTENTTYPE)
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
352 except KeyError: # XXX was: NoSuchRevisionError:
241
f464adcc3a51 fix saving no data if no previous revision exists
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 236
diff changeset
353 currentrev = None
905
51475954290f rename all revno usages to revid (no numbers any more), remove update_item param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 904
diff changeset
354 rev_id = None
236
7a77ae08161e items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 225
diff changeset
355 contenttype_current = None
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
356
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
357 meta = dict(meta) # we may get a read-only dict-like, copy it
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
358
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
359 # we store the previous (if different) and current item name into revision metadata
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
360 # this is useful for rename history and backends that use item uids internally
903
50aa61c9b952 fixed rename issue: do not use the new name to load the item, but the old one
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 902
diff changeset
361 if name is None:
50aa61c9b952 fixed rename issue: do not use the new name to load the item, but the old one
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 902
diff changeset
362 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
363 oldname = meta.get(NAME)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
364 if oldname and oldname != name:
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
365 meta[NAME_OLD] = oldname
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
366 meta[NAME] = name
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
367
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
368 if comment:
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
369 meta[COMMENT] = unicode(comment)
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
370
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
371 if not overwrite and REVID in meta:
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
372 # we usually want to create a new revision, thus we must remove the existing REVID
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
373 del meta[REVID]
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
374
236
7a77ae08161e items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 225
diff changeset
375 if data is None:
241
f464adcc3a51 fix saving no data if no previous revision exists
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 236
diff changeset
376 if currentrev is not None:
f464adcc3a51 fix saving no data if no previous revision exists
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 236
diff changeset
377 # we don't have (new) data, just copy the old one.
f464adcc3a51 fix saving no data if no previous revision exists
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 236
diff changeset
378 # a valid usecase of this is to just edit metadata.
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
379 data = currentrev.data
241
f464adcc3a51 fix saving no data if no previous revision exists
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 236
diff changeset
380 else:
f464adcc3a51 fix saving no data if no previous revision exists
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 236
diff changeset
381 data = ''
236
7a77ae08161e items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 225
diff changeset
382
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
383 if isinstance(data, unicode):
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
384 data = data.encode(charset) # XXX wrong! if contenttype gives a coding, we MUST use THAT.
236
7a77ae08161e items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 225
diff changeset
385
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
386 if isinstance(data, str):
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
387 data = StringIO(data)
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
388
1266
1c66f39aa44f implement validation for revision metadata storage using flatland
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1236
diff changeset
389 newrev = storage_item.store_revision(meta, data, overwrite=overwrite,
1c66f39aa44f implement validation for revision metadata storage using flatland
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1236
diff changeset
390 action=unicode(action),
1c66f39aa44f implement validation for revision metadata storage using flatland
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1236
diff changeset
391 contenttype_current=contenttype_current,
1c66f39aa44f implement validation for revision metadata storage using flatland
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1236
diff changeset
392 contenttype_guessed=contenttype_guessed,
1c66f39aa44f implement validation for revision metadata storage using flatland
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1236
diff changeset
393 )
242
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
394 item_modified.send(app._get_current_object(), item_name=name)
905
51475954290f rename all revno usages to revid (no numbers any more), remove update_item param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 904
diff changeset
395 return newrev.revid, newrev.meta[SIZE]
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
396
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
397 def get_index(self):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
398 """ create an index of sub items of this item """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
399 if self.name:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
400 prefix = self.name + u'/'
827
94e388cd4e28 use 'constants' for metadata keys / whoosh field names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 794
diff changeset
401 query = And([Term(WIKINAME, app.cfg.interwikiname), Prefix(NAME_EXACT, prefix)])
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
402 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
403 # trick: an item of empty name can be considered as "virtual root item",
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
404 # that has all wiki items as sub items
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
405 prefix = u''
827
94e388cd4e28 use 'constants' for metadata keys / whoosh field names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 794
diff changeset
406 query = Term(WIKINAME, app.cfg.interwikiname)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
407 # We only want the sub-item part of the item names, not the whole item objects.
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
408 prefix_len = len(prefix)
953
326f7a365007 search/indexing: remove all_revs=False params (it is the default)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 910
diff changeset
409 revs = flaskg.storage.search(query, sortedby=NAME_EXACT, limit=None)
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
410 items = [(rev.meta[NAME], rev.meta[NAME][prefix_len:], rev.meta[CONTENTTYPE])
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
411 for rev in revs]
780
f5e0f85e66ce whooshify get_index()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 779
diff changeset
412 return items
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
413
993
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
414 def _connect_levels(self, index):
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
415 new_index = []
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
416 last = self.name
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
417 for item in index:
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
418 name = item[0]
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
419
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
420 while not name.startswith(last):
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
421 last = last.rpartition('/')[0]
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
422
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
423 missing_layers = name.split('/')[last.count('/')+1:-1]
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
424
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
425 for layer in missing_layers:
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
426 last = '/'.join([last, layer])
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
427 new_index.append((last, last[len(self.name)+1:], u'application/x-nonexistent'))
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
428
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
429 last = item[0]
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
430 new_index.append(item)
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
431
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
432 return new_index
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
433
486
b6149c732926 contenttype filtering added to global index page
Akash Sinha <akash2607@gmail.com>
parents: 484
diff changeset
434 def flat_index(self, startswith=None, selected_groups=None):
b6149c732926 contenttype filtering added to global index page
Akash Sinha <akash2607@gmail.com>
parents: 484
diff changeset
435 """
993
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
436 creates a top level index of sub items of this item
486
b6149c732926 contenttype filtering added to global index page
Akash Sinha <akash2607@gmail.com>
parents: 484
diff changeset
437 if startswith is set, filtering is done on the basis of starting letter of item name
b6149c732926 contenttype filtering added to global index page
Akash Sinha <akash2607@gmail.com>
parents: 484
diff changeset
438 if selected_groups is set, items whose contentype belonging to the selected contenttype_groups, are filtered.
b6149c732926 contenttype filtering added to global index page
Akash Sinha <akash2607@gmail.com>
parents: 484
diff changeset
439 """
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
440 index = self.get_index()
993
6dd0b0755b6a disconnected levels now shown in index, fixes #75
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 969
diff changeset
441 index = self._connect_levels(index)
486
b6149c732926 contenttype filtering added to global index page
Akash Sinha <akash2607@gmail.com>
parents: 484
diff changeset
442
496
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
443 all_ctypes = [[ctype for ctype, clabel in contenttypes]
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
444 for gname, contenttypes in CONTENTTYPE_GROUPS]
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
445 all_ctypes_chain = itertools.chain(*all_ctypes)
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
446 all_contenttypes = list(all_ctypes_chain)
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
447 contenttypes_without_encoding = [contenttype[:contenttype.index(u';')]
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
448 for contenttype in all_contenttypes
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
449 if u';' in contenttype]
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
450 all_contenttypes.extend(contenttypes_without_encoding) # adding more mime-types without the encoding term
486
b6149c732926 contenttype filtering added to global index page
Akash Sinha <akash2607@gmail.com>
parents: 484
diff changeset
451
496
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
452 if selected_groups:
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
453 ctypes = [[ctype for ctype, clabel in contenttypes]
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
454 for gname, contenttypes in CONTENTTYPE_GROUPS
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
455 if gname in selected_groups]
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
456 ctypes_chain = itertools.chain(*ctypes)
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
457 selected_contenttypes = list(ctypes_chain)
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
458 contenttypes_without_encoding = [contenttype[:contenttype.index(u';')]
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
459 for contenttype in selected_contenttypes
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
460 if u';' in contenttype]
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
461 selected_contenttypes.extend(contenttypes_without_encoding)
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
462 else:
a286df67f294 contenttype filter code updated, due to lack of encoding information for uploaded files, some extra checks have been added.
Akash Sinha <akash2607@gmail.com>
parents: 492
diff changeset
463 selected_contenttypes = all_contenttypes
486
b6149c732926 contenttype filtering added to global index page
Akash Sinha <akash2607@gmail.com>
parents: 484
diff changeset
464
518
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
465 unknown_item_group = "unknown items"
477
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 257
diff changeset
466 if startswith:
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
467 startswith = (u'{0}'.format(startswith), u'{0}'.format(startswith.swapcase()))
520
6332dda59cb6 some pep8 fixes
Akash Sinha <akash2607@gmail.com>
parents: 518
diff changeset
468 if not selected_groups or unknown_item_group in selected_groups:
518
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
469 index = [(fullname, relname, contenttype)
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
470 for fullname, relname, contenttype in index
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
471 if u'/' not in relname
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
472 and relname.startswith(startswith)
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
473 and (contenttype not in all_contenttypes or contenttype in selected_contenttypes)]
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
474 # If an item's contenttype not present in the default contenttype list,
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
475 # then it will be shown without going through any filter.
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
476 else:
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
477 index = [(fullname, relname, contenttype)
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
478 for fullname, relname, contenttype in index
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
479 if u'/' not in relname
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
480 and relname.startswith(startswith)
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
481 and (contenttype in selected_contenttypes)]
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
482
477
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 257
diff changeset
483 else:
518
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
484 if not selected_groups or unknown_item_group in selected_groups:
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
485 index = [(fullname, relname, contenttype)
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
486 for fullname, relname, contenttype in index
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
487 if u'/' not in relname
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
488 and (contenttype not in all_contenttypes or contenttype in selected_contenttypes)]
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
489 else:
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
490 index = [(fullname, relname, contenttype)
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
491 for fullname, relname, contenttype in index
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
492 if u'/' not in relname
0398d1eb14c1 small change in contenttype filter (now items with unknown mime types have a different filter, as earlier it was shown regardless of the filter selected)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
493 and contenttype in selected_contenttypes]
477
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 257
diff changeset
494
0
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 index
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
496
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
497 index_template = 'index.html'
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
498
484
19b257c0e102 code to get the subitem index flag has been refactored and moved under items/__init__.py and also unitest is added for the same.
Akash Sinha <akash2607@gmail.com>
parents: 477
diff changeset
499 def get_detailed_index(self, index):
19b257c0e102 code to get the subitem index flag has been refactored and moved under items/__init__.py and also unitest is added for the same.
Akash Sinha <akash2607@gmail.com>
parents: 477
diff changeset
500 """ appends a flag in the index of items indicating that the parent has sub items """
19b257c0e102 code to get the subitem index flag has been refactored and moved under items/__init__.py and also unitest is added for the same.
Akash Sinha <akash2607@gmail.com>
parents: 477
diff changeset
501 detailed_index = []
19b257c0e102 code to get the subitem index flag has been refactored and moved under items/__init__.py and also unitest is added for the same.
Akash Sinha <akash2607@gmail.com>
parents: 477
diff changeset
502 all_item_index = self.get_index()
19b257c0e102 code to get the subitem index flag has been refactored and moved under items/__init__.py and also unitest is added for the same.
Akash Sinha <akash2607@gmail.com>
parents: 477
diff changeset
503 all_item_text = "\n".join(item_info[1] for item_info in all_item_index)
19b257c0e102 code to get the subitem index flag has been refactored and moved under items/__init__.py and also unitest is added for the same.
Akash Sinha <akash2607@gmail.com>
parents: 477
diff changeset
504 for fullname, relname, contenttype in index:
19b257c0e102 code to get the subitem index flag has been refactored and moved under items/__init__.py and also unitest is added for the same.
Akash Sinha <akash2607@gmail.com>
parents: 477
diff changeset
505 hassubitem = False
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 957
diff changeset
506 subitem_name_re = u"^{0}/[^/]+$".format(re.escape(relname))
524
77a9bd2d3dc8 regex search function updated, to get the subitem flag correctly
Akash Sinha <akash2607@gmail.com>
parents: 520
diff changeset
507 regex = re.compile(subitem_name_re, re.UNICODE|re.M)
484
19b257c0e102 code to get the subitem index flag has been refactored and moved under items/__init__.py and also unitest is added for the same.
Akash Sinha <akash2607@gmail.com>
parents: 477
diff changeset
508 if regex.search(all_item_text):
19b257c0e102 code to get the subitem index flag has been refactored and moved under items/__init__.py and also unitest is added for the same.
Akash Sinha <akash2607@gmail.com>
parents: 477
diff changeset
509 hassubitem = True
19b257c0e102 code to get the subitem index flag has been refactored and moved under items/__init__.py and also unitest is added for the same.
Akash Sinha <akash2607@gmail.com>
parents: 477
diff changeset
510 detailed_index.append((fullname, relname, contenttype, hassubitem))
19b257c0e102 code to get the subitem index flag has been refactored and moved under items/__init__.py and also unitest is added for the same.
Akash Sinha <akash2607@gmail.com>
parents: 477
diff changeset
511 return detailed_index
19b257c0e102 code to get the subitem index flag has been refactored and moved under items/__init__.py and also unitest is added for the same.
Akash Sinha <akash2607@gmail.com>
parents: 477
diff changeset
512
477
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 257
diff changeset
513 def name_initial(self, names=None):
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 257
diff changeset
514 initials = [(name[1][0])
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 257
diff changeset
515 for name in names]
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 257
diff changeset
516 return initials
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
517
1003
8621c3e273a1 fixes #72. Implements the page to handle 404 error, and calls abort(404) in some view, when apropriate.
Bruno Martin <bruno@hacklab.com.br>
parents: 969
diff changeset
518 delete_template = 'delete.html'
8621c3e273a1 fixes #72. Implements the page to handle 404 error, and calls abort(404) in some view, when apropriate.
Bruno Martin <bruno@hacklab.com.br>
parents: 969
diff changeset
519 destroy_template = 'destroy.html'
8621c3e273a1 fixes #72. Implements the page to handle 404 error, and calls abort(404) in some view, when apropriate.
Bruno Martin <bruno@hacklab.com.br>
parents: 969
diff changeset
520 diff_template = 'diff.html'
8621c3e273a1 fixes #72. Implements the page to handle 404 error, and calls abort(404) in some view, when apropriate.
Bruno Martin <bruno@hacklab.com.br>
parents: 969
diff changeset
521 rename_template = 'rename.html'
8621c3e273a1 fixes #72. Implements the page to handle 404 error, and calls abort(404) in some view, when apropriate.
Bruno Martin <bruno@hacklab.com.br>
parents: 969
diff changeset
522 revert_template = 'revert.html'
8621c3e273a1 fixes #72. Implements the page to handle 404 error, and calls abort(404) in some view, when apropriate.
Bruno Martin <bruno@hacklab.com.br>
parents: 969
diff changeset
523
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
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
525 class Contentful(Item):
245
52ca5dc1ab15 add a JSON validator, use it to validate meta_text
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 244
diff changeset
526 """
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
527 Base class for Item subclasses that have content.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
528 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
529 @property
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
530 def ModifyForm(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
531 class C(Item._ModifyForm):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
532 content_form = self.content.ModifyForm
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
533 C.__name__ = 'ModifyForm'
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
534 return C
1420
100197cb69ab Convert Flatland forms to contain rendering hints.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1408
diff changeset
535
100197cb69ab Convert Flatland forms to contain rendering hints.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1408
diff changeset
536
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
537 class Default(Contentful):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
538 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
539 A "conventional" wiki item.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
540 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
541 def _do_modify_show_templates(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
542 # call this if the item is still empty
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
543 rev_ids = []
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
544 item_templates = self.content.get_templates(self.contenttype)
1460
157d41b326b1 Rename modify_show_*_selection.html templates to modify_select_*.html
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1456
diff changeset
545 return render_template('modify_select_template.html',
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
546 item_name=self.name,
1453
accea307e94e Fix some comments in the itemtype changeset.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1452
diff changeset
547 # XXX u'default' should be a constant
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
548 itemtype=u'default',
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
549 rev=self.rev,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
550 contenttype=self.contenttype,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
551 templates=item_templates,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
552 first_rev_id=rev_ids and rev_ids[0],
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
553 last_rev_id=rev_ids and rev_ids[-1],
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
554 meta_rendered='',
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
555 data_rendered='',
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
556 )
242
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
557
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
558 def do_modify(self):
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
559 method = request.method
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
560 if method == 'GET':
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
561 if isinstance(self.content, NonExistentContent):
1460
157d41b326b1 Rename modify_show_*_selection.html templates to modify_select_*.html
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1456
diff changeset
562 return render_template('modify_select_contenttype.html',
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
563 item_name=self.name,
1453
accea307e94e Fix some comments in the itemtype changeset.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1452
diff changeset
564 # XXX see comment above
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
565 itemtype=u'default',
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
566 contenttype_groups=CONTENTTYPE_GROUPS,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
567 )
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
568 item = self
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
569 if isinstance(self.rev, DummyRev):
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
570 template_name = request.values.get('template')
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
571 if template_name is None:
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
572 return self._do_modify_show_templates()
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
573 elif template_name:
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
574 item = Item.create(template_name)
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
575 form = self.ModifyForm.from_item(item)
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
576 elif method == 'POST':
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
577 # XXX workaround for *Draw items
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
578 if isinstance(self.content, Draw):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
579 try:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
580 self.content.handle_post()
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
581 except AccessDenied:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
582 abort(403)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
583 else:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
584 # *Draw Applets POSTs more than once, redirecting would
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
585 # break them
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
586 return "OK"
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
587 form = self.ModifyForm.from_request(request)
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
588 if form.validate():
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
589 meta, data, contenttype_guessed, comment = form._dump(self)
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
590 contenttype_qs = request.values.get('contenttype')
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
591 try:
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
592 self.modify(meta, data, comment, contenttype_guessed, contenttype_qs)
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
593 except AccessDenied:
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
594 abort(403)
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
595 else:
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
596 return redirect(url_for_item(self.name))
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
597 return render_template(self.modify_template,
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
598 item_name=self.name,
242
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
599 rows_meta=str(ROWS_META), cols=str(COLS),
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
600 form=form,
1229
29301b8a2718 Hide search box in modify views.
Sam Toyer <samATqxcvDOTnet>
parents: 1214
diff changeset
601 search_form=None,
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
602 )
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
603
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
604 modify_template = 'modify.html'
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
605
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
606 item_registry.register(Default._factory, u'default')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
607
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
608
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
609 class Ticket(Contentful):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
610 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
611 Stub for ticket item class.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
612 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
613
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
614 item_registry.register(Ticket._factory, u'ticket')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
615
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
616
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
617 class Userprofile(Item):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
618 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
619 Currently userprofile is implemented as a contenttype. This is a stub of an
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
620 itemtype implementation of userprofile.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
621 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
622
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
623 item_registry.register(Userprofile._factory, u'userprofile')
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
624
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
625
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
626 class NonExistent(Item):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
627 def _convert(self, doc):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
628 abort(404)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
629
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
630 def do_modify(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
631 # First, check if the current user has the required privileges
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
632 if not flaskg.user.may.create(self.name):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
633 abort(403)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
634
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
635 # TODO Construct this list from the item_registry. Two more fields (ie.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
636 # display name and description) are needed in the registry then to
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
637 # support the automatic construction.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
638 ITEMTYPES = [
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
639 (u'default', u'Default', 'Wiki item'),
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
640 (u'ticket', u'Ticket', 'Ticket item'),
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
641 ]
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
642
1460
157d41b326b1 Rename modify_show_*_selection.html templates to modify_select_*.html
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1456
diff changeset
643 return render_template('modify_select_itemtype.html',
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
644 item_name=self.name,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
645 itemtypes=ITEMTYPES,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
646 )
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
647
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
648 item_registry.register(NonExistent._factory, u'nonexistent')