<commit_before>from time import sleep
from datetime import datetime

from pylons import g #g is a namespace for globally accessable app helpers
from pylons import c as context

from pymongo.errors import OperationFailure

from ming import schema
from ming.orm.base import state, session
from ming.orm.mapped_class import MappedClass
from ming.orm.property import FieldProperty

from pyforge.model import VersionedArtifact, Snapshot, Message, File

class PageHistory(Snapshot):
    class __mongometa__:
        name='page_history'

    def original(self):
        return Page.query.get(_id=self.artifact_id)
        
    def shorthand_id(self):
        return '%s#%s' % (self.original().shorthand_id(), self.version)

    def url(self):
        return self.original().url() + '?version=%d' % self.version

    def index(self):
        result = Snapshot.index(self)
        result.update(
            title_s='Version %d of %s' % (
                self.version,self.original().title),
            type_s='WikiPage Snapshot',
            text=self.data.text)
        return result

    @property
    def html_text(self):
        """A markdown processed version of the page text"""
        return g.markdown_wiki.convert(self.data.text)

    def root_comments(self):
        if '_id' in self:
            return Comment.query.find(dict(page_id=self.artifact_id, parent_id=None))<commit_msg>FORGE-302: Add a property method to return all attachments for wiki artifacts<commit_after>from time import sleep
from datetime import datetime

from pylons import g #g is a namespace for globally accessable app helpers
from pylons import c as context

from pymongo.errors import OperationFailure

from ming import schema
from ming.orm.base import state, session
from ming.orm.mapped_class import MappedClass
from ming.orm.property import FieldProperty

from pyforge.model import VersionedArtifact, Snapshot, Message, File

class PageHistory(Snapshot):
    class __mongometa__:
        name='page_history'

    def original(self):
        return Page.query.get(_id=self.artifact_id)
        
    def shorthand_id(self):
        return '%s#%s' % (self.original().shorthand_id(), self.version)

    def url(self):
        return self.original().url() + '?version=%d' % self.version

    def index(self):
        result = Snapshot.index(self)
        result.update(
            title_s='Version %d of %s' % (
                self.version,self.original().title),
            type_s='WikiPage Snapshot',
            text=self.data.text)
        return result

    @property
    def html_text(self):
        """A markdown processed version of the page text"""
        return g.markdown_wiki.convert(self.data.text)

    @property
    def attachments(self):
        return self.original().attachments

    def root_comments(self):
        if '_id' in self:
            return Comment.query.find(dict(page_id=self.artifact_id, parent_id=None))
{'fraction_non_alphanumeric': 0.09380349195481, 'fraction_numerical': 0.0010270455323519343, 'mean_word_length': 3.030344827586207, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3082545', 'n_tokens_mistral': 865, 'n_tokens_neox': 821, 'n_words': 241}