allura
修訂 | ef3f77899dbb8e4940340c628d4018eb2fe40815 (tree) |
---|---|
時間 | 2012-03-07 05:49:45 |
作者 | Jenny Steele <jsteele@geek...> |
Commiter | Jenny Steele |
[#3614] Fixed related artifacts test error
Signed-off-by: Jenny Steele <jsteele@geek.net>
@@ -129,44 +129,47 @@ class Shortlink(object): | ||
129 | 129 | @classmethod |
130 | 130 | def from_links(cls, *links): |
131 | 131 | '''Convert a sequence of shortlinks to the matching Shortlink objects''' |
132 | - # Parse all the links | |
133 | - parsed_links = dict((link, cls._parse_link(link)) for link in links) | |
134 | - links_by_artifact = defaultdict(list) | |
135 | - project_ids = set() | |
136 | - for link, d in parsed_links.iteritems(): | |
137 | - project_ids.add(d['project_id']) | |
138 | - links_by_artifact[d['artifact']].append(d) | |
139 | - q = cls.query.find(dict( | |
140 | - link={'$in': links_by_artifact.keys()}, | |
141 | - project_id={'$in': list(project_ids)} | |
142 | - ), validate=False) | |
143 | - result = {} | |
144 | - matches_by_artifact = dict( | |
145 | - (link, list(matches)) | |
146 | - for link, matches in groupby(q, key=lambda s:s.link)) | |
147 | - result = {} | |
148 | - for link, d in parsed_links.iteritems(): | |
149 | - matches = matches_by_artifact.get(d['artifact'], []) | |
150 | - matches = ( | |
151 | - m for m in matches | |
152 | - if m.project.shortname == d['project'] and | |
153 | - m.project.neighborhood_id == d['nbhd'] and | |
154 | - m.app_config is not None and | |
155 | - m.project.app_instance(m.app_config.options.mount_point)) | |
156 | - if d['app']: | |
132 | + if len(links): | |
133 | + # Parse all the links | |
134 | + parsed_links = dict((link, cls._parse_link(link)) for link in links) | |
135 | + links_by_artifact = defaultdict(list) | |
136 | + project_ids = set() | |
137 | + for link, d in parsed_links.iteritems(): | |
138 | + project_ids.add(d['project_id']) | |
139 | + links_by_artifact[d['artifact']].append(d) | |
140 | + q = cls.query.find(dict( | |
141 | + link={'$in': links_by_artifact.keys()}, | |
142 | + project_id={'$in': list(project_ids)} | |
143 | + ), validate=False) | |
144 | + result = {} | |
145 | + matches_by_artifact = dict( | |
146 | + (link, list(matches)) | |
147 | + for link, matches in groupby(q, key=lambda s:s.link)) | |
148 | + result = {} | |
149 | + for link, d in parsed_links.iteritems(): | |
150 | + matches = matches_by_artifact.get(d['artifact'], []) | |
157 | 151 | matches = ( |
158 | 152 | m for m in matches |
159 | - if m.app_config.options.mount_point == d['app']) | |
160 | - matches = list(matches) | |
161 | - if matches: | |
162 | - result[link] = matches[0] | |
163 | - else: | |
164 | - result[link] = None | |
165 | - if len(matches) > 1: | |
166 | - log.warn('Ambiguous link to %s', link) | |
167 | - for m in matches: | |
168 | - log.warn('... %r', m) | |
169 | - return result | |
153 | + if m.project.shortname == d['project'] and | |
154 | + m.project.neighborhood_id == d['nbhd'] and | |
155 | + m.app_config is not None and | |
156 | + m.project.app_instance(m.app_config.options.mount_point)) | |
157 | + if d['app']: | |
158 | + matches = ( | |
159 | + m for m in matches | |
160 | + if m.app_config.options.mount_point == d['app']) | |
161 | + matches = list(matches) | |
162 | + if matches: | |
163 | + result[link] = matches[0] | |
164 | + else: | |
165 | + result[link] = None | |
166 | + if len(matches) > 1: | |
167 | + log.warn('Ambiguous link to %s', link) | |
168 | + for m in matches: | |
169 | + log.warn('... %r', m) | |
170 | + return result | |
171 | + else: | |
172 | + return {} | |
170 | 173 | |
171 | 174 | @classmethod |
172 | 175 | def _parse_link(cls, s): |
@@ -185,7 +188,9 @@ class Shortlink(object): | ||
185 | 188 | p_id = getattr(c.project, '_id', None) |
186 | 189 | p_nbhd = c.project.neighborhood_id |
187 | 190 | if len(parts) == 3: |
188 | - p_id = Project.query.get(shortname=parts[0], neighborhood_id=p_nbhd)._id | |
191 | + p = Project.query.get(shortname=parts[0], neighborhood_id=p_nbhd) | |
192 | + if p: | |
193 | + p_id = p._id | |
189 | 194 | return dict( |
190 | 195 | nbhd=p_nbhd, |
191 | 196 | project=parts[0], |