Switch to unified view

a/Allura/allura/model/discuss.py b/Allura/allura/model/discuss.py
...
...
86
86
87
    def delete(self):
87
    def delete(self):
88
        # Delete all the threads, posts, and artifacts
88
        # Delete all the threads, posts, and artifacts
89
        self.thread_class().query.remove(dict(discussion_id=self._id))
89
        self.thread_class().query.remove(dict(discussion_id=self._id))
90
        self.post_class().query.remove(dict(discussion_id=self._id))
90
        self.post_class().query.remove(dict(discussion_id=self._id))
91
        for att in self.attachment_class().by_metadata(discussion_id=self._id):
91
        self.attachment_class().remove(dict(discussion_id=self._id))
92
            att.delete()
93
        super(Discussion, self).delete()
92
        super(Discussion, self).delete()
94
93
95
    def find_posts(self, **kw):
94
    def find_posts(self, **kw):
96
        q = dict(kw, discussion_id=self._id)
95
        q = dict(kw, discussion_id=self._id)
97
        return self.post_class().query.find(q)
96
        return self.post_class().query.find(q)
...
...
264
            self.subscriptions.pop(str(c.user._id), None)
263
            self.subscriptions.pop(str(c.user._id), None)
265
    subscription=property(_get_subscription, _set_subscription)
264
    subscription=property(_get_subscription, _set_subscription)
266
265
267
    def delete(self):
266
    def delete(self):
268
        self.post_class().query.remove(dict(thread_id=self._id))
267
        self.post_class().query.remove(dict(thread_id=self._id))
269
        for att in self.attachment_class().by_metadata(thread_id=self._id):
268
        self.attachment_class().remove(dict(thread_id=self._id))
270
            att.delete()
271
        super(Thread, self).delete()
269
        super(Thread, self).delete()
272
270
273
class PostHistory(Snapshot):
271
class PostHistory(Snapshot):
274
    class __mongometa__:
272
    class __mongometa__:
275
        name='post_history'
273
        name='post_history'
...
...
363
                subject = getattr(artifact, 'email_subject', '')
361
                subject = getattr(artifact, 'email_subject', '')
364
        return subject or '(no subject)'
362
        return subject or '(no subject)'
365
363
366
    @property
364
    @property
367
    def attachments(self):
365
    def attachments(self):
368
        return self.attachment_class().by_metadata(
366
        return self.attachment_class().query.find(dict(
369
            post_id=self._id, type='attachment')
367
            post_id=self._id, type='attachment'))
370
368
371
    def primary(self, primary_class=None):
369
    def primary(self, primary_class=None):
372
        return self.thread.primary(primary_class)
370
        return self.thread.primary(primary_class)
373
371
374
    def summary(self):
372
    def summary(self):
...
...
393
            return self.subject
391
            return self.subject
394
        else:
392
        else:
395
            return 'Re: ' +(self.subject or '(no subject)')
393
            return 'Re: ' +(self.subject or '(no subject)')
396
394
397
    def delete(self):
395
    def delete(self):
398
        for att in self.attachment_class().by_metadata(post_id=self._id):
396
        self.attachment_class().remove(dict(post_id=self._id))
399
            att.delete()
400
        super(Post, self).delete()
397
        super(Post, self).delete()
401
398
402
    def approve(self):
399
    def approve(self):
403
        from allura.model.notification import Notification
400
        from allura.model.notification import Notification
404
        if self.status == 'ok': return
401
        if self.status == 'ok': return
...
...
426
423
427
class DiscussionAttachment(BaseAttachment):
424
class DiscussionAttachment(BaseAttachment):
428
    DiscussionClass=Discussion
425
    DiscussionClass=Discussion
429
    ThreadClass=Thread
426
    ThreadClass=Thread
430
    PostClass=Post
427
    PostClass=Post
428
    ArtifactClass=Post
431
    thumbnail_size = (100, 100)
429
    thumbnail_size = (100, 100)
432
    class __mongometa__:
430
    class __mongometa__:
433
        name = 'attachment.files'
431
        indexes = [ 'filename', 'discussion_id', 'thread_id', 'post_id' ]
434
        indexes = [
435
            'metadata.filename',
436
            'metadata.discussion_id',
437
            'metadata.thread_id',
438
            'metadata.post_id' ]
439
432
440
    # Override the metadata schema here
433
    discussion_id=FieldProperty(schema.ObjectId)
441
    metadata=FieldProperty(dict(
434
    thread_id=FieldProperty(str)
442
            discussion_id=schema.ObjectId,
435
    post_id=FieldProperty(str)
443
            thread_id=str,
436
    artifact_id=FieldProperty(str)
444
            post_id=str,
445
            filename=str,
446
            app_config_id=schema.ObjectId,
447
            type=str))
448
449
    @property
450
    def artifact(self):
451
        return self.post
452
437
453
    @property
438
    @property
454
    def discussion(self):
439
    def discussion(self):
455
        return self.DiscussionClass.query.get(_id=self.metadata.discussion_id)
440
        return self.DiscussionClass.query.get(_id=self.discussion_id)
456
441
457
    @property
442
    @property
458
    def thread(self):
443
    def thread(self):
459
        return self.ThreadClass.query.get(_id=self.metadata.thread_id)
444
        return self.ThreadClass.query.get(_id=self.thread_id)
460
445
461
    @property
446
    @property
462
    def post(self):
447
    def post(self):
463
        return self.PostClass.query.get(_id=self.metadata.post_id)
448
        return self.PostClass.query.get(_id=self.post_id)
464
449
465
    @classmethod
450
    @classmethod
466
    def metadata_for(cls, post):
451
    def metadata_for(cls, post):
467
        return dict(
452
        return dict(
468
            post_id=post._id,
453
            post_id=post._id,
469
            thread_id=post.thread_id,
454
            thread_id=post.thread_id,
470
            discussion_id=post.discussion_id,
455
            discussion_id=post.discussion_id,
471
            app_config_id=post.app_config_id)
456
            app_config_id=post.app_config_id)
472
457
473
    def url(self):
458
    def url(self):
474
        if self.metadata.post_id:
459
        if self.post_id:
475
            return self.post.url() + 'attachment/' + self.filename
460
            return self.post.url() + 'attachment/' + self.filename
476
        elif self.metadata.thread_id:
461
        elif self.thread_id:
477
            return self.thread.url() + 'attachment/' + self.filename
462
            return self.thread.url() + 'attachment/' + self.filename
478
        else:
463
        else:
479
            return self.discussion.url() + 'attachment/' + self.filename
464
            return self.discussion.url() + 'attachment/' + self.filename
480
465
481
466