Switch to unified view

a/Allura/allura/model/artifact.py b/Allura/allura/model/artifact.py
...
...
6
from collections import defaultdict
6
from collections import defaultdict
7
from time import sleep
7
from time import sleep
8
from datetime import datetime
8
from datetime import datetime
9
import Image
9
import Image
10
10
11
import bson
11
import pymongo
12
import pymongo
12
from pylons import c, g
13
from pylons import c, g
13
from ming import Document, Session, Field
14
from ming import Document, Session, Field
14
from ming import schema as S
15
from ming import schema as S
15
from ming import orm
16
from ming import orm
...
...
298
    labels = FieldProperty([str])
299
    labels = FieldProperty([str])
299
    references = FieldProperty([ArtifactReferenceType])
300
    references = FieldProperty([ArtifactReferenceType])
300
    backreferences = FieldProperty({str:ArtifactReferenceType})
301
    backreferences = FieldProperty({str:ArtifactReferenceType})
301
    app_config = RelationProperty('AppConfig')
302
    app_config = RelationProperty('AppConfig')
302
303
304
    @classmethod
305
    def attachment_class(cls):
306
        raise NotImplementedError, 'attachment_class'
307
303
    def subscribe(self, user=None, topic=None, type='direct', n=1, unit='day'):
308
    def subscribe(self, user=None, topic=None, type='direct', n=1, unit='day'):
304
        from allura.model import Mailbox
309
        from allura.model import Mailbox
305
        if user is None: user = c.user
310
        if user is None: user = c.user
306
        Mailbox.subscribe(
311
        Mailbox.subscribe(
307
            user_id=user._id,
312
            user_id=user._id,
...
...
348
        '''Return a pickle-serializable reference to an artifact'''
353
        '''Return a pickle-serializable reference to an artifact'''
349
        try:
354
        try:
350
            d = ArtifactReference(dict(
355
            d = ArtifactReference(dict(
351
                    project_id=self.app_config.project._id,
356
                    project_id=self.app_config.project._id,
352
                    mount_point=self.app_config.options.mount_point,
357
                    mount_point=self.app_config.options.mount_point,
353
                    artifact_type=pymongo.bson.Binary(pickle.dumps(self.__class__)),
358
                    artifact_type=bson.Binary(pickle.dumps(self.__class__)),
354
                    artifact_id=self._id))
359
                    artifact_id=self._id))
355
            return d
360
            return d
356
        except AttributeError:
361
        except AttributeError:
357
            return None
362
            return None
358
363
...
...
458
463
459
    @LazyProperty
464
    @LazyProperty
460
    def discussion_thread(self):
465
    def discussion_thread(self):
461
        return self.get_discussion_thread()
466
        return self.get_discussion_thread()
462
467
468
    def attach(self, filename, fp, **kw):
469
        att = self.attachment_class().save_attachment(
470
            filename=filename,
471
            fp=fp, artifact_id=self._id, **kw)
472
        return att
473
463
class Snapshot(Artifact):
474
class Snapshot(Artifact):
464
    class __mongometa__:
475
    class __mongometa__:
465
        session = artifact_orm_session
476
        session = artifact_orm_session
466
        name='artifact_snapshot'
477
        name='artifact_snapshot'
467
        unique_indexes = [ ('artifact_class', 'artifact_id', 'version') ]
478
        unique_indexes = [ ('artifact_class', 'artifact_id', 'version') ]
...
...
634
        return self.slug
645
        return self.slug
635
646
636
class AwardFile(File):
647
class AwardFile(File):
637
    class __mongometa__:
648
    class __mongometa__:
638
        session = main_orm_session
649
        session = main_orm_session
639
        name = 'award_file.files'
650
        name = 'award_file'
640
651
    award_id=FieldProperty(S.ObjectId)
641
    # Override the metadata schema here
642
    metadata=FieldProperty(dict(
643
            award_id=S.ObjectId,
644
            filename=str))
645
652
646
class Award(Artifact):
653
class Award(Artifact):
647
    class __mongometa__:
654
    class __mongometa__:
648
        session = main_orm_session
655
        session = main_orm_session
649
        name='award'
656
        name='award'
...
...
669
            result['created_by_s'] = self.created_by.name
676
            result['created_by_s'] = self.created_by.name
670
        return result
677
        return result
671
678
672
    @property
679
    @property
673
    def icon(self):
680
    def icon(self):
674
        return AwardFile.query.find({'metadata.award_id':self._id}).first()
681
        return AwardFile.query.get(award_id=self._id)
675
682
676
    def url(self):
683
    def url(self):
677
        return urllib.unquote_plus(str(self.short))
684
        return urllib.unquote_plus(str(self.short))
678
685
679
    def longurl(self):
686
    def longurl(self):
...
...
710
            result['award_s'] = self.award.short
717
            result['award_s'] = self.award.short
711
        return result
718
        return result
712
719
713
    @property
720
    @property
714
    def icon(self):
721
    def icon(self):
715
        return AwardFile.query.find({'metadata.award_id':self.award_id}).first()
722
        return AwardFile.query.get(award_id=self.award_id)
716
723
717
    def url(self):
724
    def url(self):
718
        slug = str(self.granted_to_project.shortname).replace('/','_')
725
        slug = str(self.granted_to_project.shortname).replace('/','_')
719
        return urllib.unquote_plus(slug)
726
        return urllib.unquote_plus(slug)
720
727