annotate MoinMoin/items/__init__.py @ 1960:5d672f909f27 namespaces

merged default into namespaces branch
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 09 Feb 2013 17:30:19 +0100
parents 3e7fc8bab8b1 70c534eb5596
children 46e8aa18c4d1
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
1623
1e67974bee6e remove simplejson fallback, json is included since python 2.6 (which we require)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1617
diff changeset
20 import json
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
21 from StringIO import StringIO
1613
bc8a2546468b Clean up registry code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1460
diff changeset
22 from collections import namedtuple
1815
a38ad19c9e7c Replace ITEMTYPES with information collected in item_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1801
diff changeset
23 from operator import attrgetter
1763
347d11826f95 Clean up imports in items/{__init__,content}.py
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1727
diff changeset
24
347d11826f95 Clean up imports in items/{__init__,content}.py
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1727
diff changeset
25 from flask import current_app as app
347d11826f95 Clean up imports in items/{__init__,content}.py
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1727
diff changeset
26 from flask import g as flaskg
347d11826f95 Clean up imports in items/{__init__,content}.py
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1727
diff changeset
27 from flask import request, Response, redirect, abort, escape
173
89f50aed143f move mimetype related code from wikiutil to util.mimetype
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 170
diff changeset
28
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
29 from flatland import Form
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
1662
465b22852fae Let Item subclasses handle +show.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1650
diff changeset
31 from jinja2 import Markup
465b22852fae Let Item subclasses handle +show.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1650
diff changeset
32
1958
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
33 from whoosh.query import Term, Prefix, And, Or, Not
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
34
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
35 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
36 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
37
1763
347d11826f95 Clean up imports in items/{__init__,content}.py
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1727
diff changeset
38 from MoinMoin.security.textcha import TextCha, TextChaizedForm
347d11826f95 Clean up imports in items/{__init__,content}.py
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1727
diff changeset
39 from MoinMoin.signalling import item_modified
347d11826f95 Clean up imports in items/{__init__,content}.py
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1727
diff changeset
40 from MoinMoin.storage.middleware.protecting import AccessDenied
1940
c3624283c9ec remove some unused imports
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1939
diff changeset
41 from MoinMoin.storage.error import NoSuchItemError, NoSuchRevisionError
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
42 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
43 from MoinMoin.themes import render_template
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1800
diff changeset
44 from MoinMoin.util.mime import Type
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
45 from MoinMoin.util.interwiki import url_for_item
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
46 from MoinMoin.util.registry import RegistryBase
1798
d139d7aad071 Add @timed() to several methods of Item related to index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1765
diff changeset
47 from MoinMoin.util.clock import timed
1763
347d11826f95 Clean up imports in items/{__init__,content}.py
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1727
diff changeset
48 from MoinMoin.forms import RequiredText, OptionalText, JSON, Tags, Submit
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
49 from MoinMoin.constants.keys import (
1691
28cb88fcc4dd Move Blog item implementation to a separate blog.py module.
Pavel Sviderski <pavel@psviderski.name>
parents: 1690
diff changeset
50 NAME, NAME_OLD, NAME_EXACT, WIKINAME, MTIME, SYSITEM_VERSION, ITEMTYPE,
1763
347d11826f95 Clean up imports in items/{__init__,content}.py
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1727
diff changeset
51 CONTENTTYPE, SIZE, ACTION, ADDRESS, HOSTNAME, USERID, COMMENT,
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
52 HASH_ALGORITHM, ITEMID, REVID, DATAID, CURRENT, PARENTID
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
53 )
1910
78b7a1136984 use constants in MoinMoin.constans.{item,content}types more
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1815
diff changeset
54 from MoinMoin.constants.contenttypes import charset, CONTENTTYPE_NONEXISTENT
78b7a1136984 use constants in MoinMoin.constans.{item,content}types more
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1815
diff changeset
55 from MoinMoin.constants.itemtypes import (
78b7a1136984 use constants in MoinMoin.constans.{item,content}types more
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1815
diff changeset
56 ITEMTYPE_NONEXISTENT, ITEMTYPE_USERPROFILE, ITEMTYPE_DEFAULT,
78b7a1136984 use constants in MoinMoin.constans.{item,content}types more
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1815
diff changeset
57 )
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
58
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1800
diff changeset
59 from .content import content_registry, Content, NonExistentContent, Draw
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
60
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
61
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
62 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
63 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
64
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
65
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
66 class RegistryItem(RegistryBase):
1815
a38ad19c9e7c Replace ITEMTYPES with information collected in item_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1801
diff changeset
67 class Entry(namedtuple('Entry', 'factory itemtype display_name description order')):
1613
bc8a2546468b Clean up registry code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1460
diff changeset
68 def __call__(self, itemtype, *args, **kw):
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
69 if self.itemtype == itemtype:
1613
bc8a2546468b Clean up registry code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1460
diff changeset
70 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
71
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 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
73 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
74 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
75 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
76
1815
a38ad19c9e7c Replace ITEMTYPES with information collected in item_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1801
diff changeset
77 def __init__(self):
a38ad19c9e7c Replace ITEMTYPES with information collected in item_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1801
diff changeset
78 super(RegistryItem, self).__init__()
a38ad19c9e7c Replace ITEMTYPES with information collected in item_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1801
diff changeset
79 self.shown_entries = []
a38ad19c9e7c Replace ITEMTYPES with information collected in item_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1801
diff changeset
80
a38ad19c9e7c Replace ITEMTYPES with information collected in item_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1801
diff changeset
81 def register(self, e, shown):
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
82 """
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 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
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 :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
86 """
1815
a38ad19c9e7c Replace ITEMTYPES with information collected in item_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1801
diff changeset
87 if shown:
a38ad19c9e7c Replace ITEMTYPES with information collected in item_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1801
diff changeset
88 self.shown_entries.append(e)
a38ad19c9e7c Replace ITEMTYPES with information collected in item_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1801
diff changeset
89 self.shown_entries.sort(key=attrgetter('order'))
a38ad19c9e7c Replace ITEMTYPES with information collected in item_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1801
diff changeset
90 return self._register(e)
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
91
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
92
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 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
94
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
95 def register(cls):
1815
a38ad19c9e7c Replace ITEMTYPES with information collected in item_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1801
diff changeset
96 item_registry.register(RegistryItem.Entry(cls._factory, cls.itemtype, cls.display_name, cls.description, cls.order), cls.shown)
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
97 return cls
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
98
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
99
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
100 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
101 """ if we have no stored Revision, we use this dummy """
1672
c093039ac8a5 items/__init__.py: DummyRev.__init__: Add default values for itemtype and
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1670
diff changeset
102 def __init__(self, item, itemtype=None, contenttype=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
103 self.item = item
1672
c093039ac8a5 items/__init__.py: DummyRev.__init__: Add default values for itemtype and
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1670
diff changeset
104 self.meta = {
1910
78b7a1136984 use constants in MoinMoin.constans.{item,content}types more
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1815
diff changeset
105 ITEMTYPE: itemtype or ITEMTYPE_NONEXISTENT,
78b7a1136984 use constants in MoinMoin.constans.{item,content}types more
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1815
diff changeset
106 CONTENTTYPE: contenttype or CONTENTTYPE_NONEXISTENT
1672
c093039ac8a5 items/__init__.py: DummyRev.__init__: Add default values for itemtype and
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1670
diff changeset
107 }
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
108 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
109 self.revid = None
1672
c093039ac8a5 items/__init__.py: DummyRev.__init__: Add default values for itemtype and
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1670
diff changeset
110 if self.item:
1832
ff503e7ea7a0 merged default into namespaces branch, some stuff XXX BROKEN
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1273 1815
diff changeset
111 self.meta[NAME] = [self.item.name]
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
112
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
113
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
114 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
115 """ 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
116 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
117 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
118 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
119 return [] # same as an empty Item
1180
1c5a013b9ebd Fix the three failing tests.
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1152
diff changeset
120 def destroy_all_revisions(self):
1c5a013b9ebd Fix the three failing tests.
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1152
diff changeset
121 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
122
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
123
1765
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
124 def get_storage_revision(name, itemtype=None, contenttype=None, rev_id=CURRENT, item=None):
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
125 """
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
126 Get a storage Revision.
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
127
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
128 If :item is supplied it is used as the storage Item; otherwise the storage
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
129 Item is looked up with :name. If it is not found (either because the item
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
130 doesn't exist or the user does not have the required permissions) a
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
131 DummyItem is created, and a DummyRev is created with appropriate metadata
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
132 properties and the "item" property pointing to the DummyItem. The DummyRev
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
133 is then returned.
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
134
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
135 If the previous step didn't end up with a DummyRev, the revision
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
136 designated by :rev_id is then looked up. If it is not found, current
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
137 revision is looked up and returned instead. If current revision is not
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
138 found (i.e. the item has no revision), a DummyRev is created. (TODO: in
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
139 the last two cases, emit warnings or throw exceptions.)
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
140
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
141 :itemtype and :contenttype are used when creating a DummyRev, where
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
142 metadata is not available from the storage.
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
143 """
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
144 if 1: # try:
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
145 if item is None:
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
146 item = flaskg.storage[name]
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
147 else:
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
148 name = item.name
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
149 if not item: # except NoSuchItemError:
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
150 logging.debug("No such item: {0!r}".format(name))
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
151 item = DummyItem(name)
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
152 rev = DummyRev(item, itemtype, contenttype)
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
153 logging.debug("Item {0!r}, created dummy revision with contenttype {1!r}".format(name, contenttype))
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
154 else:
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
155 logging.debug("Got item: {0!r}".format(name))
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
156 try:
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
157 rev = item.get_revision(rev_id)
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
158 except KeyError: # NoSuchRevisionError:
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
159 try:
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
160 rev = item.get_revision(CURRENT) # fall back to current revision
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
161 # XXX add some message about invalid revision
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
162 except KeyError: # NoSuchRevisionError:
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
163 logging.debug("Item {0!r} has no revisions.".format(name))
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
164 rev = DummyRev(item, itemtype, contenttype)
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
165 logging.debug("Item {0!r}, created dummy revision with contenttype {1!r}".format(name, contenttype))
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
166 logging.debug("Got item {0!r}, revision: {1!r}".format(name, rev_id))
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
167 return rev
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
168
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
169
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
170 class BaseChangeForm(TextChaizedForm):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
171 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
172 submit = Submit
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
173
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
174
1624
c6974ba2e2b2 Widget-based metadata editor.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1614
diff changeset
175 class BaseMetaForm(Form):
c6974ba2e2b2 Widget-based metadata editor.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1614
diff changeset
176 itemtype = RequiredText.using(label=L_("Item type")).with_properties(placeholder=L_("Item type"))
c6974ba2e2b2 Widget-based metadata editor.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1614
diff changeset
177 contenttype = RequiredText.using(label=L_("Content type")).with_properties(placeholder=L_("Content type"))
1627
b0b73fe90f3d Remove wikiname, disable ACL in metadata editor
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1626
diff changeset
178 # Disabled - Flatland doesn't distinguish emtpy value and nonexistent
b0b73fe90f3d Remove wikiname, disable ACL in metadata editor
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1626
diff changeset
179 # value, while an emtpy acl and no acl have different semantics
b0b73fe90f3d Remove wikiname, disable ACL in metadata editor
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1626
diff changeset
180 #acl = OptionalText.using(label=L_('ACL')).with_properties(placeholder=L_("Access Control List"))
1624
c6974ba2e2b2 Widget-based metadata editor.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1614
diff changeset
181 summary = OptionalText.using(label=L_("Summary")).with_properties(placeholder=L_("One-line summary of the item"))
c6974ba2e2b2 Widget-based metadata editor.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1614
diff changeset
182 tags = Tags
c6974ba2e2b2 Widget-based metadata editor.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1614
diff changeset
183
1626
346c52c9c1e5 Fixes to forms.py and items/__init__.py
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1625
diff changeset
184
1677
d74b9e4d41e5 items/__init__.py: Split helper methods from_item and from_requst in
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1676
diff changeset
185 class BaseModifyForm(BaseChangeForm):
d74b9e4d41e5 items/__init__.py: Split helper methods from_item and from_requst in
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1676
diff changeset
186 @classmethod
d74b9e4d41e5 items/__init__.py: Split helper methods from_item and from_requst in
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1676
diff changeset
187 def from_item(cls, item):
d74b9e4d41e5 items/__init__.py: Split helper methods from_item and from_requst in
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1676
diff changeset
188 form = cls.from_defaults()
d74b9e4d41e5 items/__init__.py: Split helper methods from_item and from_requst in
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1676
diff changeset
189 TextCha(form).amend_form()
d74b9e4d41e5 items/__init__.py: Split helper methods from_item and from_requst in
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1676
diff changeset
190 form._load(item)
d74b9e4d41e5 items/__init__.py: Split helper methods from_item and from_requst in
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1676
diff changeset
191 return form
d74b9e4d41e5 items/__init__.py: Split helper methods from_item and from_requst in
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1676
diff changeset
192
d74b9e4d41e5 items/__init__.py: Split helper methods from_item and from_requst in
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1676
diff changeset
193 @classmethod
d74b9e4d41e5 items/__init__.py: Split helper methods from_item and from_requst in
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1676
diff changeset
194 def from_request(cls, request):
d74b9e4d41e5 items/__init__.py: Split helper methods from_item and from_requst in
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1676
diff changeset
195 form = cls.from_flat(request.form.items() + request.files.items())
d74b9e4d41e5 items/__init__.py: Split helper methods from_item and from_requst in
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1676
diff changeset
196 TextCha(form).amend_form()
d74b9e4d41e5 items/__init__.py: Split helper methods from_item and from_requst in
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1676
diff changeset
197 return form
d74b9e4d41e5 items/__init__.py: Split helper methods from_item and from_requst in
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1676
diff changeset
198
d74b9e4d41e5 items/__init__.py: Split helper methods from_item and from_requst in
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1676
diff changeset
199
1958
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
200 UNKNOWN_ITEM_GROUP = "unknown items"
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
201
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
202 def _build_contenttype_query(groups):
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
203 """
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
204 Build a Whoosh query from a list of contenttype groups.
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
205 """
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
206 queries = []
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
207 for g in groups:
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
208 for e in content_registry.groups[g]:
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
209 ct_unicode = unicode(e.content_type)
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
210 queries.append(Term(CONTENTTYPE, ct_unicode))
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
211 queries.append(Prefix(CONTENTTYPE, ct_unicode + u';'))
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
212 return Or(queries)
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
213
1800
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1798
diff changeset
214 IndexEntry = namedtuple('IndexEntry', 'relname meta')
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1798
diff changeset
215
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1798
diff changeset
216 MixedIndexEntry = namedtuple('MixedIndexEntry', 'relname meta hassubitems')
1726
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
217
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
218 class Item(object):
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
219 """ Highlevel (not storage) Item, wraps around a storage Revision"""
1815
a38ad19c9e7c Replace ITEMTYPES with information collected in item_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1801
diff changeset
220 # placeholder values for registry entry properties
a38ad19c9e7c Replace ITEMTYPES with information collected in item_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1801
diff changeset
221 itemtype = ''
a38ad19c9e7c Replace ITEMTYPES with information collected in item_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1801
diff changeset
222 display_name = u''
a38ad19c9e7c Replace ITEMTYPES with information collected in item_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1801
diff changeset
223 description = u''
a38ad19c9e7c Replace ITEMTYPES with information collected in item_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1801
diff changeset
224 shown = True
a38ad19c9e7c Replace ITEMTYPES with information collected in item_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1801
diff changeset
225 order = 0
a38ad19c9e7c Replace ITEMTYPES with information collected in item_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1801
diff changeset
226
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
227 @classmethod
1613
bc8a2546468b Clean up registry code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1460
diff changeset
228 def _factory(cls, *args, **kw):
bc8a2546468b Clean up registry code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1460
diff changeset
229 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
230
bac248bcf98c use a Item/contenttype registry to get the right Item subclass
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 221
diff changeset
231 @classmethod
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
232 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
233 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
234 Create a highlevel Item by looking up :name or directly wrapping
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
235 :item and extract the Revision designated by :rev_id revision.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
236
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
237 The highlevel Item is created by creating an instance of Content
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
238 subclass according to the item's contenttype metadata entry; The
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
239 :contenttype argument can be used to override contenttype. It is used
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
240 only when handling +convert (when deciding the contenttype of target
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
241 item), +modify (when creating a new item whose contenttype is not yet
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
242 decided), +diff and +diffraw (to coerce the Content to a common
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
243 super-contenttype of both revisions).
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
244
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
245 After that the Content instance, an instance of Item subclass is
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
246 created according to the item's itemtype metadata entry, and the
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
247 previously created Content instance is assigned to its content
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
248 property.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
249 """
1765
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
250 rev = get_storage_revision(name, itemtype, contenttype, rev_id, item)
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
251 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
252 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
253 #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
254
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
255 # XXX Cannot pass item=item to Content.__init__ via
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
256 # content_registry.get yet, have to patch it later.
1648
1a2c53092ea1 items/content.py: Implement Content.create.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1631
diff changeset
257 content = Content.create(contenttype)
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
258
1765
54160346e469 items/__init__.py: Add function get_storage_revision().
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1763
diff changeset
259 itemtype = rev.meta.get(ITEMTYPE) or itemtype or u'default'
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
260 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
261
1613
bc8a2546468b Clean up registry code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1460
diff changeset
262 item = item_registry.get(itemtype, name, rev=rev, content=content)
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
263 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
264
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
265 content.item = item
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
266
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
267 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
268
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
269 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
270 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
271 self.rev = rev
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
272 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
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 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
275 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
276 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
277
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
278 # XXX Backward compatibility, remove soon
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
279 @property
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
280 def contenttype(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
281 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
282
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
283 def _render_meta(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
284 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
285
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
286 def meta_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
287 """ 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
288 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
289 SYSITEM_VERSION,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
290 NAME_OLD,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
291 # are automatically implanted when saving
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
292 ITEMID, REVID, DATAID,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
293 HASH_ALGORITHM,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
294 SIZE,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
295 COMMENT,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
296 MTIME,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
297 ACTION,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
298 ADDRESS, HOSTNAME, USERID,
afe0afe4e1a6 recursive rename
"Luis Henrique Fagundes <lhfagundes@gmail.com>"
parents: 993
diff changeset
299 ]
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
300 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
301 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
302 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
303
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
304 def 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
305 """ 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
306 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
307 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
308
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
309 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
310 """ 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
311 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
312 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
313 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
314 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
315
892
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
316 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
317 """
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
318 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
319 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
320 """
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
321 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
322 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
323 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
324 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
325 return meta
79f80ce3cf78 implement parents (key PARENTID), add it to index schema
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
326
1070
ed13847b5d4f implement delete item <name> as removing <name> from the item's NAME list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1053
diff changeset
327 def _rename(self, name, comment, action, delete=False):
1832
ff503e7ea7a0 merged default into namespaces branch, some stuff XXX BROKEN
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1273 1815
diff changeset
328 self._save(self.meta, self.content.data, name=name, action=action, comment=comment, delete=delete)
1935
2589c6bc54d7 fix item rename/delete for NAME meta being a list of names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1932
diff changeset
329 old_prefix = self.subitems_prefix
2589c6bc54d7 fix item rename/delete for NAME meta being a list of names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1932
diff changeset
330 old_prefixlen = len(old_prefix)
2589c6bc54d7 fix item rename/delete for NAME meta being a list of names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1932
diff changeset
331 if not delete:
2589c6bc54d7 fix item rename/delete for NAME meta being a list of names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1932
diff changeset
332 new_prefix = name + '/'
1726
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
333 for child in self.get_subitem_revs():
1935
2589c6bc54d7 fix item rename/delete for NAME meta being a list of names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1932
diff changeset
334 for child_oldname in child.meta[NAME]:
2589c6bc54d7 fix item rename/delete for NAME meta being a list of names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1932
diff changeset
335 if child_oldname.startswith(old_prefix):
2589c6bc54d7 fix item rename/delete for NAME meta being a list of names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1932
diff changeset
336 if delete:
2589c6bc54d7 fix item rename/delete for NAME meta being a list of names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1932
diff changeset
337 child_newname = None
2589c6bc54d7 fix item rename/delete for NAME meta being a list of names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1932
diff changeset
338 else: # rename
2589c6bc54d7 fix item rename/delete for NAME meta being a list of names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1932
diff changeset
339 child_newname = new_prefix + child_oldname[old_prefixlen:]
2589c6bc54d7 fix item rename/delete for NAME meta being a list of names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1932
diff changeset
340 item = Item.create(child_oldname)
2589c6bc54d7 fix item rename/delete for NAME meta being a list of names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1932
diff changeset
341 item._save(item.meta, item.content.data, name=child_newname, action=action, comment=comment, delete=delete)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
342
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
343 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
344 """
1070
ed13847b5d4f implement delete item <name> as removing <name> from the item's NAME list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1053
diff changeset
345 rename this item to item <name> (replace current name by another name in the NAME list)
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 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
347 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
348
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
349 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
350 """
1070
ed13847b5d4f implement delete item <name> as removing <name> from the item's NAME list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1053
diff changeset
351 delete this item (remove current name from NAME list)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
352 """
1070
ed13847b5d4f implement delete item <name> as removing <name> from the item's NAME list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1053
diff changeset
353 return self._rename(None, comment, action=u'TRASH', delete=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
354
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
355 def revert(self, comment=u''):
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
356 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
357
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
358 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
359 # 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
360 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
361 # destroy complete item with all revisions, metadata, etc.
910
5b7e522d97af fix destroy
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 908
diff changeset
362 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
363 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
364 # just destroy this revision
910
5b7e522d97af fix destroy
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 908
diff changeset
365 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
366
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
367 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
368 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
369 # 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
370 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
371
7a77ae08161e items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 225
diff changeset
372 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
373
1677
d74b9e4d41e5 items/__init__.py: Split helper methods from_item and from_requst in
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1676
diff changeset
374 class _ModifyForm(BaseModifyForm):
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
375 """Base class for ModifyForm of Item subclasses."""
1624
c6974ba2e2b2 Widget-based metadata editor.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1614
diff changeset
376 meta_form = BaseMetaForm
1625
6748d609a242 forms.py: Create JSON widget
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1624
diff changeset
377 extra_meta_text = JSON.using(label=L_("Extra MetaData (JSON)")).with_properties(rows=ROWS_META, cols=COLS)
1624
c6974ba2e2b2 Widget-based metadata editor.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1614
diff changeset
378 meta_template = 'modify_meta.html'
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
379
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
380 def _load(self, item):
1624
c6974ba2e2b2 Widget-based metadata editor.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1614
diff changeset
381 meta = item.prepare_meta_for_modify(item.meta)
1630
24c1a4b29c86 items/__init__.py: comment policy='duck' argument passed to Flatland.Dict.set
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1629
diff changeset
382 # Default value of `policy` argument of Flatland.Dict.set's is
24c1a4b29c86 items/__init__.py: comment policy='duck' argument passed to Flatland.Dict.set
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1629
diff changeset
383 # 'strict', which causes KeyError to be thrown when meta contains
24c1a4b29c86 items/__init__.py: comment policy='duck' argument passed to Flatland.Dict.set
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1629
diff changeset
384 # meta keys that are not present in self['meta_form']. Setting
24c1a4b29c86 items/__init__.py: comment policy='duck' argument passed to Flatland.Dict.set
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1629
diff changeset
385 # policy to 'duck' suppresses this behavior.
24c1a4b29c86 items/__init__.py: comment policy='duck' argument passed to Flatland.Dict.set
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1629
diff changeset
386 self['meta_form'].set(meta, policy='duck')
1624
c6974ba2e2b2 Widget-based metadata editor.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1614
diff changeset
387 for k in self['meta_form'].field_schema_mapping.keys():
c6974ba2e2b2 Widget-based metadata editor.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1614
diff changeset
388 meta.pop(k, None)
c6974ba2e2b2 Widget-based metadata editor.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1614
diff changeset
389 self['extra_meta_text'].set(item.meta_dict_to_text(meta))
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
390 self['content_form']._load(item.content)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
391
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
392 def _dump(self, item):
1624
c6974ba2e2b2 Widget-based metadata editor.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1614
diff changeset
393 meta = self['meta_form'].value.copy()
c6974ba2e2b2 Widget-based metadata editor.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1614
diff changeset
394 meta.update(item.meta_text_to_dict(self['extra_meta_text'].value))
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
395 data, contenttype_guessed = self['content_form']._dump(item.content)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
396 comment = self['comment'].value
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
397 return meta, data, contenttype_guessed, comment
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
398
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
399 def do_modify(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
400 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
401 Handle +modify requests, both GET and POST.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
402
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
403 This method should be overridden in subclasses, providing polymorphic
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
404 behavior for the +modify view.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
405 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
406 raise NotImplementedError
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
407
1070
ed13847b5d4f implement delete item <name> as removing <name> from the item's NAME list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1053
diff changeset
408 def _save(self, meta, data=None, name=None, action=u'SAVE', contenttype_guessed=None, comment=u'',
ed13847b5d4f implement delete item <name> as removing <name> from the item's NAME list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1053
diff changeset
409 overwrite=False, delete=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
410 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
411 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
412 try:
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
413 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
414 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
415 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
416 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
417 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
418 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
419 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
420
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
421 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
422
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
423 # 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
424 # 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
425 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
426 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
427 oldname = meta.get(NAME)
1042
e666253e7d0d pages with multiple names are properly renamed
Luis Henrique Fagundes <lhfagundes@gmail.com>
parents: 1039
diff changeset
428 if oldname:
1939
ac5c618b96ca use isinstance instead of type/types.X
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1938
diff changeset
429 if not isinstance(oldname, list):
1042
e666253e7d0d pages with multiple names are properly renamed
Luis Henrique Fagundes <lhfagundes@gmail.com>
parents: 1039
diff changeset
430 oldname = [oldname]
1070
ed13847b5d4f implement delete item <name> as removing <name> from the item's NAME list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1053
diff changeset
431 if delete or name not in oldname: # this is a delete or rename
1042
e666253e7d0d pages with multiple names are properly renamed
Luis Henrique Fagundes <lhfagundes@gmail.com>
parents: 1039
diff changeset
432 meta[NAME_OLD] = oldname[:]
e666253e7d0d pages with multiple names are properly renamed
Luis Henrique Fagundes <lhfagundes@gmail.com>
parents: 1039
diff changeset
433 try:
e666253e7d0d pages with multiple names are properly renamed
Luis Henrique Fagundes <lhfagundes@gmail.com>
parents: 1039
diff changeset
434 oldname.remove(self.name)
e666253e7d0d pages with multiple names are properly renamed
Luis Henrique Fagundes <lhfagundes@gmail.com>
parents: 1039
diff changeset
435 except ValueError:
e666253e7d0d pages with multiple names are properly renamed
Luis Henrique Fagundes <lhfagundes@gmail.com>
parents: 1039
diff changeset
436 pass
1070
ed13847b5d4f implement delete item <name> as removing <name> from the item's NAME list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1053
diff changeset
437 if not delete:
ed13847b5d4f implement delete item <name> as removing <name> from the item's NAME list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1053
diff changeset
438 oldname.append(name)
1042
e666253e7d0d pages with multiple names are properly renamed
Luis Henrique Fagundes <lhfagundes@gmail.com>
parents: 1039
diff changeset
439 meta[NAME] = oldname
e666253e7d0d pages with multiple names are properly renamed
Luis Henrique Fagundes <lhfagundes@gmail.com>
parents: 1039
diff changeset
440 else:
e666253e7d0d pages with multiple names are properly renamed
Luis Henrique Fagundes <lhfagundes@gmail.com>
parents: 1039
diff changeset
441 meta[NAME] = [name]
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
442
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
443 if comment:
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
444 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
445
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
446 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
447 # 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
448 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
449
236
7a77ae08161e items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 225
diff changeset
450 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
451 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
452 # 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
453 # 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
454 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
455 else:
f464adcc3a51 fix saving no data if no previous revision exists
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 236
diff changeset
456 data = ''
236
7a77ae08161e items: cleanup contenttype handling in modify/_save, see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 225
diff changeset
457
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
458 if isinstance(data, unicode):
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
459 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
460
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
461 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
462 data = StringIO(data)
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
463
1266
1c66f39aa44f implement validation for revision metadata storage using flatland
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1236
diff changeset
464 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
465 action=unicode(action),
1c66f39aa44f implement validation for revision metadata storage using flatland
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1236
diff changeset
466 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
467 contenttype_guessed=contenttype_guessed,
1918
f0b346ac6338 added return_rev param to store_revision() to avoid returning a revision object without need
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1910
diff changeset
468 return_rev=True,
1266
1c66f39aa44f implement validation for revision metadata storage using flatland
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1236
diff changeset
469 )
242
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
470 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
471 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
472
1726
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
473 @property
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
474 def subitems_prefix(self):
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
475 return self.name + u'/' if self.name else u''
486
b6149c732926 contenttype filtering added to global index page
Akash Sinha <akash2607@gmail.com>
parents: 484
diff changeset
476
1798
d139d7aad071 Add @timed() to several methods of Item related to index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1765
diff changeset
477 @timed()
1726
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
478 def get_subitem_revs(self):
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
479 """
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
480 Create a list of subitems of this item.
486
b6149c732926 contenttype filtering added to global index page
Akash Sinha <akash2607@gmail.com>
parents: 484
diff changeset
481
1726
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
482 Subitems are in the form of storage Revisions.
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
483 """
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
484 query = Term(WIKINAME, app.cfg.interwikiname)
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
485 # trick: an item of empty name can be considered as "virtual root item"
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
486 # that has all wiki items as sub items
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
487 if self.name:
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
488 query = And([query, Prefix(NAME_EXACT, self.subitems_prefix)])
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
489 revs = flaskg.storage.search(query, sortedby=NAME_EXACT, limit=None)
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
490 return revs
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
491
1798
d139d7aad071 Add @timed() to several methods of Item related to index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1765
diff changeset
492 @timed()
1726
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
493 def make_flat_index(self, subitems):
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
494 """
1800
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1798
diff changeset
495 Create two IndexEntry lists - ``dirs`` and ``files`` - from a list of
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1798
diff changeset
496 subitems.
1726
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
497
1800
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1798
diff changeset
498 Direct subitems are added to the ``files`` list.
1726
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
499
1800
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1798
diff changeset
500 For indirect subitems, its ancestor which is a direct subitem is added
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1798
diff changeset
501 to the ``dirs`` list. Supposing current index root is 'foo' and when
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1798
diff changeset
502 'foo/bar/la' is encountered, 'foo/bar' is added to ``dirs``.
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1798
diff changeset
503
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1798
diff changeset
504 The direct subitem need not exist.
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1798
diff changeset
505
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1798
diff changeset
506 When both a subitem itself and some of its subitems are in the subitems
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1798
diff changeset
507 list, it appears in both ``files`` and ``dirs``.
1726
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
508 """
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
509 prefix = self.subitems_prefix
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
510 prefixlen = len(prefix)
1800
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1798
diff changeset
511 # IndexEntry instances of "file" subitems
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1798
diff changeset
512 files = []
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1798
diff changeset
513 # IndexEntry instances of "directory" subitems
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1798
diff changeset
514 dirs = []
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1798
diff changeset
515 added_dir_relnames = set()
1726
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
516
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
517 for rev in subitems:
1937
483dfd7fc86a fix make_flat_index for NAME being a list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
518 fullnames = rev.meta[NAME]
483dfd7fc86a fix make_flat_index for NAME being a list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
519 for fullname in fullnames:
483dfd7fc86a fix make_flat_index for NAME being a list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
520 if fullname.startswith(prefix):
483dfd7fc86a fix make_flat_index for NAME being a list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
521 relname = fullname[prefixlen:]
483dfd7fc86a fix make_flat_index for NAME being a list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
522 if '/' in relname:
483dfd7fc86a fix make_flat_index for NAME being a list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
523 # Find the *direct* subitem that is the ancestor of current
483dfd7fc86a fix make_flat_index for NAME being a list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
524 # (indirect) subitem. e.g. suppose when the index root is
483dfd7fc86a fix make_flat_index for NAME being a list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
525 # 'foo', and current item (`rev`) is 'foo/bar/lorem/ipsum',
483dfd7fc86a fix make_flat_index for NAME being a list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
526 # 'foo/bar' will be found.
483dfd7fc86a fix make_flat_index for NAME being a list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
527 direct_relname = relname.partition('/')[0]
483dfd7fc86a fix make_flat_index for NAME being a list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
528 if direct_relname not in added_dir_relnames:
483dfd7fc86a fix make_flat_index for NAME being a list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
529 added_dir_relnames.add(direct_relname)
483dfd7fc86a fix make_flat_index for NAME being a list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
530 direct_fullname = prefix + direct_relname
483dfd7fc86a fix make_flat_index for NAME being a list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
531 direct_rev = get_storage_revision(direct_fullname)
483dfd7fc86a fix make_flat_index for NAME being a list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
532 dirs.append(IndexEntry(direct_relname, direct_rev.meta))
483dfd7fc86a fix make_flat_index for NAME being a list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
533 else:
483dfd7fc86a fix make_flat_index for NAME being a list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1935
diff changeset
534 files.append(IndexEntry(relname, rev.meta))
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
535
1800
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1798
diff changeset
536 return dirs, files
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
537
1958
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
538 def build_index_query(self, startswith=None, selected_groups=None):
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
539 prefix = self.subitems_prefix
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
540 if startswith:
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
541 query = Prefix(NAME_EXACT, prefix + startswith) | Prefix(NAME_EXACT, prefix + startswith.swapcase())
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
542 else:
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
543 query = Prefix(NAME_EXACT, prefix)
1726
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
544
1958
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
545 if selected_groups:
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
546 selected_groups = set(selected_groups)
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
547 has_unknown = UNKNOWN_ITEM_GROUP in selected_groups
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
548 if has_unknown:
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
549 selected_groups.remove(UNKNOWN_ITEM_GROUP)
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
550 ct_query = _build_contenttype_query(selected_groups)
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
551 if has_unknown:
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
552 ct_query |= Not(_build_contenttype_query(content_registry.groups))
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
553 query &= ct_query
1726
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
554
1958
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
555 return query
1726
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
556
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
557 def get_index(self, startswith=None, selected_groups=None):
1958
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
558 query = Term(WIKINAME, app.cfg.interwikiname) & self.build_index_query(startswith, selected_groups)
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
559 revs = flaskg.storage.search(query, sortedby=NAME_EXACT, limit=None)
70c534eb5596 use whoosh for index filtering
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1918
diff changeset
560 return self.make_flat_index(revs)
1800
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1798
diff changeset
561
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1798
diff changeset
562 def get_mixed_index(self):
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1798
diff changeset
563 dirs, files = self.make_flat_index(self.get_subitem_revs())
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1798
diff changeset
564 dirs_dict = dict([(e.relname, MixedIndexEntry(*e, hassubitems=True)) for e in dirs])
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1798
diff changeset
565 index_dict = dict([(e.relname, MixedIndexEntry(*e, hassubitems=False)) for e in files])
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1798
diff changeset
566 index_dict.update(dirs_dict)
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1798
diff changeset
567 return sorted(index_dict.values())
1726
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1691
diff changeset
568
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
569 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
570
1938
b8cfcf3bb9aa fix initials computation for NAME being a list, move sort/upper/lower code to method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1937
diff changeset
571 def name_initial(self, subitems, uppercase=False, lowercase=False):
b8cfcf3bb9aa fix initials computation for NAME being a list, move sort/upper/lower code to method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1937
diff changeset
572 """
b8cfcf3bb9aa fix initials computation for NAME being a list, move sort/upper/lower code to method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1937
diff changeset
573 return a sorted list of first characters of subitem names,
b8cfcf3bb9aa fix initials computation for NAME being a list, move sort/upper/lower code to method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1937
diff changeset
574 optionally all uppercased or lowercased.
b8cfcf3bb9aa fix initials computation for NAME being a list, move sort/upper/lower code to method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1937
diff changeset
575 """
b8cfcf3bb9aa fix initials computation for NAME being a list, move sort/upper/lower code to method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1937
diff changeset
576 prefix = self.subitems_prefix
b8cfcf3bb9aa fix initials computation for NAME being a list, move sort/upper/lower code to method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1937
diff changeset
577 prefixlen = len(prefix)
b8cfcf3bb9aa fix initials computation for NAME being a list, move sort/upper/lower code to method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1937
diff changeset
578 initials = set()
b8cfcf3bb9aa fix initials computation for NAME being a list, move sort/upper/lower code to method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1937
diff changeset
579 for item in subitems:
b8cfcf3bb9aa fix initials computation for NAME being a list, move sort/upper/lower code to method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1937
diff changeset
580 for name in item.meta[NAME]:
b8cfcf3bb9aa fix initials computation for NAME being a list, move sort/upper/lower code to method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1937
diff changeset
581 if name.startswith(prefix):
b8cfcf3bb9aa fix initials computation for NAME being a list, move sort/upper/lower code to method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1937
diff changeset
582 initial = name[prefixlen]
b8cfcf3bb9aa fix initials computation for NAME being a list, move sort/upper/lower code to method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1937
diff changeset
583 if uppercase:
b8cfcf3bb9aa fix initials computation for NAME being a list, move sort/upper/lower code to method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1937
diff changeset
584 initial = initial.upper()
b8cfcf3bb9aa fix initials computation for NAME being a list, move sort/upper/lower code to method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1937
diff changeset
585 elif lowercase:
b8cfcf3bb9aa fix initials computation for NAME being a list, move sort/upper/lower code to method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1937
diff changeset
586 initial = initial.lower()
b8cfcf3bb9aa fix initials computation for NAME being a list, move sort/upper/lower code to method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1937
diff changeset
587 initials.add(initial)
b8cfcf3bb9aa fix initials computation for NAME being a list, move sort/upper/lower code to method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1937
diff changeset
588 return sorted(list(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
589
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
590 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
591 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
592 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
593 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
594 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
595
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
596
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
597 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
598 """
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
599 Base class for Item subclasses that have content.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
600 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
601 @property
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
602 def ModifyForm(self):
1653
57e864bb8852 Add the ability to create new Blog and Blog entry items.
Pavel Sviderski <pavel@psviderski.name>
parents: 1650
diff changeset
603 class C(self._ModifyForm):
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
604 content_form = self.content.ModifyForm
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
605 C.__name__ = 'ModifyForm'
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
606 return C
1420
100197cb69ab Convert Flatland forms to contain rendering hints.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1408
diff changeset
607
100197cb69ab Convert Flatland forms to contain rendering hints.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1408
diff changeset
608
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
609 @register
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
610 class Default(Contentful):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
611 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
612 A "conventional" wiki item.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
613 """
1910
78b7a1136984 use constants in MoinMoin.constans.{item,content}types more
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1815
diff changeset
614 itemtype = ITEMTYPE_DEFAULT
1815
a38ad19c9e7c Replace ITEMTYPES with information collected in item_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1801
diff changeset
615 display_name = L_('Default')
a38ad19c9e7c Replace ITEMTYPES with information collected in item_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1801
diff changeset
616 description = L_('Wiki item')
a38ad19c9e7c Replace ITEMTYPES with information collected in item_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1801
diff changeset
617 order = -10
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
618
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
619 def _do_modify_show_templates(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
620 # call this if the item is still empty
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
621 rev_ids = []
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
622 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
623 return render_template('modify_select_template.html',
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
624 item_name=self.name,
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
625 itemtype=self.itemtype,
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
626 rev=self.rev,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
627 contenttype=self.contenttype,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
628 templates=item_templates,
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
629 first_rev_id=rev_ids and rev_ids[0],
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
630 last_rev_id=rev_ids and rev_ids[-1],
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
631 meta_rendered='',
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
632 data_rendered='',
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
633 )
242
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 241
diff changeset
634
1662
465b22852fae Let Item subclasses handle +show.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1650
diff changeset
635 def do_show(self, revid):
465b22852fae Let Item subclasses handle +show.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1650
diff changeset
636 show_revision = revid != CURRENT
465b22852fae Let Item subclasses handle +show.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1650
diff changeset
637 show_navigation = False # TODO
465b22852fae Let Item subclasses handle +show.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1650
diff changeset
638 first_rev = last_rev = None # TODO
465b22852fae Let Item subclasses handle +show.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1650
diff changeset
639 return render_template(self.show_template,
465b22852fae Let Item subclasses handle +show.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1650
diff changeset
640 item=self, item_name=self.name,
465b22852fae Let Item subclasses handle +show.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1650
diff changeset
641 rev=self.rev,
465b22852fae Let Item subclasses handle +show.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1650
diff changeset
642 contenttype=self.contenttype,
465b22852fae Let Item subclasses handle +show.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1650
diff changeset
643 first_rev_id=first_rev,
465b22852fae Let Item subclasses handle +show.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1650
diff changeset
644 last_rev_id=last_rev,
465b22852fae Let Item subclasses handle +show.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1650
diff changeset
645 data_rendered=Markup(self.content._render_data()),
465b22852fae Let Item subclasses handle +show.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1650
diff changeset
646 show_revision=show_revision,
465b22852fae Let Item subclasses handle +show.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1650
diff changeset
647 show_navigation=show_navigation,
465b22852fae Let Item subclasses handle +show.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1650
diff changeset
648 )
465b22852fae Let Item subclasses handle +show.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1650
diff changeset
649
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
650 def do_modify(self):
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
651 method = request.method
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
652 if method == 'GET':
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
653 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
654 return render_template('modify_select_contenttype.html',
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
655 item_name=self.name,
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
656 itemtype=self.itemtype,
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1800
diff changeset
657 group_names=content_registry.group_names,
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1800
diff changeset
658 groups=content_registry.groups,
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
659 )
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
660 item = self
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
661 if isinstance(self.rev, DummyRev):
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
662 template_name = request.values.get('template')
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
663 if template_name is None:
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
664 return self._do_modify_show_templates()
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
665 elif template_name:
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
666 item = Item.create(template_name)
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
667 form = self.ModifyForm.from_item(item)
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
668 elif method == 'POST':
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
669 # XXX workaround for *Draw items
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
670 if isinstance(self.content, Draw):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
671 try:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
672 self.content.handle_post()
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
673 except AccessDenied:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
674 abort(403)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
675 else:
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
676 # *Draw Applets POSTs more than once, redirecting would
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
677 # break them
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
678 return "OK"
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
679 form = self.ModifyForm.from_request(request)
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
680 if form.validate():
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
681 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
682 contenttype_qs = request.values.get('contenttype')
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
683 try:
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
684 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
685 except AccessDenied:
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
686 abort(403)
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
687 else:
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
688 return redirect(url_for_item(self.name))
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
689 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
690 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
691 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
692 form=form,
1229
29301b8a2718 Hide search box in modify views.
Sam Toyer <samATqxcvDOTnet>
parents: 1214
diff changeset
693 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
694 )
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
695
1662
465b22852fae Let Item subclasses handle +show.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1650
diff changeset
696 show_template = 'show.html'
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
697 modify_template = 'modify.html'
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
698
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
699
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
700 @register
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
701 class Userprofile(Item):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
702 """
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
703 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
704 itemtype implementation of userprofile.
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
705 """
1910
78b7a1136984 use constants in MoinMoin.constans.{item,content}types more
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1815
diff changeset
706 itemtype = ITEMTYPE_USERPROFILE
1815
a38ad19c9e7c Replace ITEMTYPES with information collected in item_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1801
diff changeset
707 display_name = L_('User profile')
a38ad19c9e7c Replace ITEMTYPES with information collected in item_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1801
diff changeset
708 description = L_('User profile item (not implemented yet!)')
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
709
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
710
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
711 @register
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
712 class NonExistent(Item):
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
713 """
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
714 A dummy Item for nonexistent items (when modifying, a nonexistent item with
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
715 undetermined itemtype)
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
716 """
1910
78b7a1136984 use constants in MoinMoin.constans.{item,content}types more
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1815
diff changeset
717 itemtype = ITEMTYPE_NONEXISTENT
1815
a38ad19c9e7c Replace ITEMTYPES with information collected in item_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1801
diff changeset
718 shown = False
1649
5dc142ab43d2 Keep itemtype and contenttype in Item and Content subclasses.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1648
diff changeset
719
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
720 def _convert(self, doc):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
721 abort(404)
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
722
1662
465b22852fae Let Item subclasses handle +show.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1650
diff changeset
723 def do_show(self, revid):
465b22852fae Let Item subclasses handle +show.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1650
diff changeset
724 # First, check if the current user has the required privileges
1670
d3a1a3e7075f items.NonExistent.do_show should always return 404 status code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1667
diff changeset
725 if flaskg.user.may.create(self.name):
d3a1a3e7075f items.NonExistent.do_show should always return 404 status code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1667
diff changeset
726 content = self._select_itemtype()
d3a1a3e7075f items.NonExistent.do_show should always return 404 status code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1667
diff changeset
727 else:
d3a1a3e7075f items.NonExistent.do_show should always return 404 status code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1667
diff changeset
728 content = render_template('show_nonexistent.html',
d3a1a3e7075f items.NonExistent.do_show should always return 404 status code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1667
diff changeset
729 item_name=self.name,
d3a1a3e7075f items.NonExistent.do_show should always return 404 status code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1667
diff changeset
730 )
d3a1a3e7075f items.NonExistent.do_show should always return 404 status code.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1667
diff changeset
731 return Response(content, 404)
1662
465b22852fae Let Item subclasses handle +show.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1650
diff changeset
732
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
733 def do_modify(self):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
734 # First, check if the current user has the required privileges
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
735 if not flaskg.user.may.create(self.name):
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
736 abort(403)
1662
465b22852fae Let Item subclasses handle +show.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1650
diff changeset
737 return self._select_itemtype()
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
738
1662
465b22852fae Let Item subclasses handle +show.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1650
diff changeset
739 def _select_itemtype(self):
1460
157d41b326b1 Rename modify_show_*_selection.html templates to modify_select_*.html
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1456
diff changeset
740 return render_template('modify_select_itemtype.html',
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
741 item_name=self.name,
1815
a38ad19c9e7c Replace ITEMTYPES with information collected in item_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1801
diff changeset
742 itemtypes=item_registry.shown_entries,
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1421
diff changeset
743 )
1653
57e864bb8852 Add the ability to create new Blog and Blog entry items.
Pavel Sviderski <pavel@psviderski.name>
parents: 1650
diff changeset
744
1957
3e7fc8bab8b1 add some dummy methods for NonExistent item - calling base class methods would cause crashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
745 def rename(self, name, comment=u''):
3e7fc8bab8b1 add some dummy methods for NonExistent item - calling base class methods would cause crashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
746 # pointless for non-existing items
3e7fc8bab8b1 add some dummy methods for NonExistent item - calling base class methods would cause crashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
747 pass
3e7fc8bab8b1 add some dummy methods for NonExistent item - calling base class methods would cause crashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
748
3e7fc8bab8b1 add some dummy methods for NonExistent item - calling base class methods would cause crashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
749 def delete(self, comment=u''):
3e7fc8bab8b1 add some dummy methods for NonExistent item - calling base class methods would cause crashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
750 # pointless for non-existing items
3e7fc8bab8b1 add some dummy methods for NonExistent item - calling base class methods would cause crashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
751 pass
3e7fc8bab8b1 add some dummy methods for NonExistent item - calling base class methods would cause crashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
752
3e7fc8bab8b1 add some dummy methods for NonExistent item - calling base class methods would cause crashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
753 def revert(self, comment=u''):
3e7fc8bab8b1 add some dummy methods for NonExistent item - calling base class methods would cause crashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
754 # pointless for non-existing items
3e7fc8bab8b1 add some dummy methods for NonExistent item - calling base class methods would cause crashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
755 pass
3e7fc8bab8b1 add some dummy methods for NonExistent item - calling base class methods would cause crashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
756
3e7fc8bab8b1 add some dummy methods for NonExistent item - calling base class methods would cause crashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
757 def destroy(self, comment=u'', destroy_item=False):
3e7fc8bab8b1 add some dummy methods for NonExistent item - calling base class methods would cause crashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
758 # pointless for non-existing items
3e7fc8bab8b1 add some dummy methods for NonExistent item - calling base class methods would cause crashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
759 pass
3e7fc8bab8b1 add some dummy methods for NonExistent item - calling base class methods would cause crashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
760
1653
57e864bb8852 Add the ability to create new Blog and Blog entry items.
Pavel Sviderski <pavel@psviderski.name>
parents: 1650
diff changeset
761
1667
0104f76e30d0 items/__init__.py: Remove Ticket stub and call load_package_modules there.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1665
diff changeset
762 from ..util.pysupport import load_package_modules
0104f76e30d0 items/__init__.py: Remove Ticket stub and call load_package_modules there.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1665
diff changeset
763 load_package_modules(__name__, __path__)