Switch to unified view

a/Allura/allura/model/index.py b/Allura/allura/model/index.py
...
...
15
from ming.orm import ForeignIdProperty, RelationProperty
15
from ming.orm import ForeignIdProperty, RelationProperty
16
16
17
from allura.lib import helpers as h
17
from allura.lib import helpers as h
18
18
19
from .session import main_doc_session, main_orm_session
19
from .session import main_doc_session, main_orm_session
20
from .project import Project
20
21
21
log = logging.getLogger(__name__)
22
log = logging.getLogger(__name__)
22
23
23
# Collection definitions
24
# Collection definitions
24
ArtifactReferenceDoc = collection(
25
ArtifactReferenceDoc = collection(
...
...
129
    def from_links(cls, *links):
130
    def from_links(cls, *links):
130
        '''Convert a sequence of shortlinks to the matching Shortlink objects'''
131
        '''Convert a sequence of shortlinks to the matching Shortlink objects'''
131
        # Parse all the links
132
        # Parse all the links
132
        parsed_links = dict((link, cls._parse_link(link)) for link in links)
133
        parsed_links = dict((link, cls._parse_link(link)) for link in links)
133
        links_by_artifact = defaultdict(list)
134
        links_by_artifact = defaultdict(list)
135
        project_ids = set()
134
        for link, d in parsed_links.iteritems():
136
        for link, d in parsed_links.iteritems():
137
            project_ids.add(d['project_id'])
135
            links_by_artifact[d['artifact']].append(d)
138
            links_by_artifact[d['artifact']].append(d)
136
137
        q = cls.query.find(dict(
139
        q = cls.query.find(dict(
138
                link={'$in': links_by_artifact.keys()}), validate=False)
140
                link={'$in': links_by_artifact.keys()},
141
                project_id={'$in': list(project_ids)}
142
            ), validate=False)
139
        result = {}
143
        result = {}
140
        matches_by_artifact = dict(
144
        matches_by_artifact = dict(
141
            (link, list(matches))
145
            (link, list(matches))
142
            for link, matches in groupby(q, key=lambda s:s.link))
146
            for link, matches in groupby(q, key=lambda s:s.link))
143
        result = {}
147
        result = {}
...
...
169
            s = s[1:]
173
            s = s[1:]
170
        if s.endswith(']'):
174
        if s.endswith(']'):
171
            s = s[:-1]
175
            s = s[:-1]
172
        parts = s.split(':')
176
        parts = s.split(':')
173
        p_shortname = None
177
        p_shortname = None
178
        p_id = None
174
        p_nbhd = None
179
        p_nbhd = None
175
        if hasattr(c, 'project'):
180
        if hasattr(c, 'project'):
176
            p_shortname = getattr(c.project, 'shortname', None)
181
            p_shortname = getattr(c.project, 'shortname', None)
182
            p_id = getattr(c.project, '_id', None)
177
            p_nbhd = c.project.neighborhood_id
183
            p_nbhd = c.project.neighborhood_id
178
        if len(parts) == 3:
184
        if len(parts) == 3:
185
            p_id = Project.query.get(shortname=parts[0])
179
            return dict(
186
            return dict(
180
                nbhd=p_nbhd,
187
                nbhd=p_nbhd,
181
                project=parts[0],
188
                project=parts[0],
189
                project_id=p_id,
182
                app=parts[1],
190
                app=parts[1],
183
                artifact=parts[2])
191
                artifact=parts[2])
184
        elif len(parts) == 2:
192
        elif len(parts) == 2:
185
            return dict(
193
            return dict(
186
                nbhd=p_nbhd,
194
                nbhd=p_nbhd,
187
                project=p_shortname,
195
                project=p_shortname,
196
                project_id=p_id,
188
                app=parts[0],
197
                app=parts[0],
189
                artifact=parts[1])
198
                artifact=parts[1])
190
        elif len(parts) == 1:
199
        elif len(parts) == 1:
191
            return dict(
200
            return dict(
192
                nbhd=p_nbhd,
201
                nbhd=p_nbhd,
193
                project=p_shortname,
202
                project=p_shortname,
203
                project_id=p_id,
194
                app=None,
204
                app=None,
195
                artifact=parts[0])
205
                artifact=parts[0])
196
        else:
206
        else:
197
            return None
207
            return None
198
208