|
a/Allura/allura/model/artifact.py |
|
b/Allura/allura/model/artifact.py |
|
... |
|
... |
315 |
tool_version = FieldProperty(
|
315 |
tool_version = FieldProperty(
|
316 |
S.Object,
|
316 |
S.Object,
|
317 |
{ str: str },
|
317 |
{ str: str },
|
318 |
if_missing=lambda:{c.app.config.tool_name:c.app.__version__})
|
318 |
if_missing=lambda:{c.app.config.tool_name:c.app.__version__})
|
319 |
acl = FieldProperty({str:[S.ObjectId]})
|
319 |
acl = FieldProperty({str:[S.ObjectId]})
|
320 |
tags = FieldProperty([dict(tag=str, count=int)])
|
320 |
tags = FieldProperty(S.Deprecated)
|
321 |
labels = FieldProperty([str])
|
321 |
labels = FieldProperty([str])
|
322 |
references = FieldProperty([ArtifactReferenceType])
|
322 |
references = FieldProperty([ArtifactReferenceType])
|
323 |
backreferences = FieldProperty({str:ArtifactReferenceType}) # keyed by solr id to emulate a set
|
323 |
backreferences = FieldProperty({str:ArtifactReferenceType}) # keyed by solr id to emulate a set
|
324 |
app_config = RelationProperty('AppConfig')
|
324 |
app_config = RelationProperty('AppConfig')
|
325 |
|
325 |
|
|
... |
|
... |
358 |
def primary(self, primary_class):
|
358 |
def primary(self, primary_class):
|
359 |
'''If an artifact is a "secondary" artifact (discussion of a ticket, for
|
359 |
'''If an artifact is a "secondary" artifact (discussion of a ticket, for
|
360 |
instance), return the artifact that is the "primary".
|
360 |
instance), return the artifact that is the "primary".
|
361 |
'''
|
361 |
'''
|
362 |
return self
|
362 |
return self
|
363 |
|
|
|
364 |
@classmethod
|
|
|
365 |
def artifacts_tagged_with(cls, tag):
|
|
|
366 |
return cls.query.find({'tags.tag':tag})
|
|
|
367 |
|
363 |
|
368 |
@classmethod
|
364 |
@classmethod
|
369 |
def artifacts_labeled_with(cls, label):
|
365 |
def artifacts_labeled_with(cls, label):
|
370 |
return cls.query.find({'labels':label})
|
366 |
return cls.query.find({'labels':label})
|
371 |
|
367 |
|
|
... |
|
... |
389 |
artifact_type=bson.Binary(pickle.dumps(self.__class__)),
|
385 |
artifact_type=bson.Binary(pickle.dumps(self.__class__)),
|
390 |
artifact_id=self._id))
|
386 |
artifact_id=self._id))
|
391 |
return d
|
387 |
return d
|
392 |
except AttributeError:
|
388 |
except AttributeError:
|
393 |
return None
|
389 |
return None
|
394 |
|
|
|
395 |
def add_tags(self, tags):
|
|
|
396 |
'Update the tags collection to reflect new tags added'
|
|
|
397 |
cur_tags = dict((t['tag'], t['count']) for t in self.tags)
|
|
|
398 |
for t in tags:
|
|
|
399 |
c = cur_tags.get(t, 0)
|
|
|
400 |
c += 1
|
|
|
401 |
cur_tags[t] = c
|
|
|
402 |
self.tags = [ dict(tag=k, count=v) for k,v in cur_tags.iteritems() ]
|
|
|
403 |
|
|
|
404 |
def remove_tags(self, tags):
|
|
|
405 |
'Update the tags collection to reflect tags removed'
|
|
|
406 |
cur_tags = dict((t['tag'], t['count']) for t in self.tags)
|
|
|
407 |
for t in tags:
|
|
|
408 |
c = cur_tags.get(t, 1)
|
|
|
409 |
c -= 1
|
|
|
410 |
if c:
|
|
|
411 |
cur_tags[t] = c
|
|
|
412 |
else:
|
|
|
413 |
cur_tags.pop(t, None)
|
|
|
414 |
self.tags = [ dict(tag=k, count=v) for k,v in cur_tags.iteritems() ]
|
|
|
415 |
|
390 |
|
416 |
@property
|
391 |
@property
|
417 |
def project(self):
|
392 |
def project(self):
|
418 |
return self.app_config.project
|
393 |
return self.app_config.project
|
419 |
|
394 |
|
|
... |
|
... |
478 |
tool_name_s=self.app_config.tool_name,
|
453 |
tool_name_s=self.app_config.tool_name,
|
479 |
mount_point_s=self.app_config.options.mount_point,
|
454 |
mount_point_s=self.app_config.options.mount_point,
|
480 |
is_history_b=False,
|
455 |
is_history_b=False,
|
481 |
url_s=self.url(),
|
456 |
url_s=self.url(),
|
482 |
type_s=self.type_s,
|
457 |
type_s=self.type_s,
|
483 |
tags_t=' '.join(t['tag'] for t in self.tags),
|
|
|
484 |
labels_t=' '.join(l for l in self.labels),
|
458 |
labels_t=' '.join(l for l in self.labels),
|
485 |
snippet_s='')
|
459 |
snippet_s='')
|
486 |
|
460 |
|
487 |
def url(self):
|
461 |
def url(self):
|
488 |
"""
|
462 |
"""
|