<commit_before>'''
    This application implements a wiki-like interface to write up documents
    about the grok web framework.  It packs in as many concepts as it can to
    demonstrate how to use Grok.
'''
import grok
from interfaces import IArticle, IArticleSorter, ISiteRoot
from permissions import Editing
from users import IUsers
from layout import ILayout, Navigation, Content
from menu import MenuItem
from urllib import quote_plus
import forms

class ArticleContainer(grok.Container):
    '''  An article container is a generic container (a dict-like object) which
        also provides a sorter for the articles it contains    '''
    prev = None
    next = None
    attachments = None

    grok.traversable('attachments')
    grok.traversable('sorter')

    def sorter(self):
        '''  Find an adapter which adapts self to an IArticleSorter, and return an instance
        '''
        return IArticleSorter(self)

class NoobsArticle(ArticleContainer):
    ''' Contains the detail for a navigable article in the site
    '''
    grok.implements(IArticle, ILayout)
    title = u''
    navTitle = u''
    text = u''

class Grok4Noobs(grok.Application, ArticleContainer):
    ''' The Grok4Noobs application is a content wiki-like application which contains examples
        explaining how to use the Grok framework for trivial and non-trivial applications.
    '''
    grok.implements(IArticle, ILayout, ISiteRoot)
    title = u'A gentle introduction to using the Grok web framework'
    navTitle = u'Introduction'
    text = u''

    grok.traversable('attachments')
    grok.traversable('sorter')
    grok.traversable('users')

    def users(self):
        sm = self.getSiteManager()
        if 'users' in sm:
            return IUsers(sm['users'])


class TextViewlet(grok.Viewlet):
    ''' Render the article content
    '''
    grok.context(IArticle)
    grok.viewletmanager(Content)


class PreviousLevelMenuEntry(MenuItem):
    '''  A menu item for articles with parent articles. IOW NoobsArticle
    '''
    grok.context(NoobsArticle)
    grok.order(-4)
    title = u'Up a level'
    link = u'..'
    mclass = 'nav buttons'
    def condition(self):
        self.mtitle = self.context.__parent__.navTitle
        return True

class PrevMenuEntry(MenuItem):
    '''  A menu item for previous articles in the list
    '''
    grok.context(NoobsArticle)
    grok.order(-3)
    title = u'Prev Page'
    mclass = 'nav buttons'
    @property
    def link(self):
        title = quote_plus(self.context.prev)
        return self.context.__parent__[title]
    def condition(self):
        if getattr(self.context, 'prev', None) is not None:
            self.mtitle = self.context.prev
            return True

class NextMenuEntry(MenuItem):
    '''  A menu item for articles next in the list
    '''
    grok.context(NoobsArticle)
    grok.order(-2)
    title = u'Next Page'
    mclass = 'nav buttons'
    @property
    def link(self):
        title = quote_plus(self.context.next)
        return self.context.__parent__[title]
    def condition(self):
        if getattr(self.context, 'next', None) is not None:
            self.mtitle = self.context.next
            return True

class SorterLink(MenuItem):
    ''' A conditional menu item which shows for articles with more than one child
    '''
    grok.context(IArticle)
    grok.require(Editing)
    grok.order(-1)<commit_msg>Changed buttons to contain page titles<commit_after>'''
    This application implements a wiki-like interface to write up documents
    about the grok web framework.  It packs in as many concepts as it can to
    demonstrate how to use Grok.
'''
import grok
from interfaces import IArticle, IArticleSorter, ISiteRoot
from permissions import Editing
from users import IUsers
from layout import ILayout, Navigation, Content
from menu import MenuItem
from urllib import quote_plus
import forms

class ArticleContainer(grok.Container):
    '''  An article container is a generic container (a dict-like object) which
        also provides a sorter for the articles it contains    '''
    prev = None
    next = None
    attachments = None

    grok.traversable('attachments')
    grok.traversable('sorter')

    def sorter(self):
        '''  Find an adapter which adapts self to an IArticleSorter, and return an instance
        '''
        return IArticleSorter(self)

class NoobsArticle(ArticleContainer):
    ''' Contains the detail for a navigable article in the site
    '''
    grok.implements(IArticle, ILayout)
    title = u''
    navTitle = u''
    text = u''

class Grok4Noobs(grok.Application, ArticleContainer):
    ''' The Grok4Noobs application is a content wiki-like application which contains examples
        explaining how to use the Grok framework for trivial and non-trivial applications.
    '''
    grok.implements(IArticle, ILayout, ISiteRoot)
    title = u'A gentle introduction to using the Grok web framework'
    navTitle = u'Introduction'
    text = u''

    grok.traversable('attachments')
    grok.traversable('sorter')
    grok.traversable('users')

    def users(self):
        sm = self.getSiteManager()
        if 'users' in sm:
            return IUsers(sm['users'])


class TextViewlet(grok.Viewlet):
    ''' Render the article content
    '''
    grok.context(IArticle)
    grok.viewletmanager(Content)


class PreviousLevelMenuEntry(MenuItem):
    '''  A menu item for articles with parent articles. IOW NoobsArticle
    '''
    grok.context(NoobsArticle)
    grok.order(-4)
    title = mtitle = u'Up a level'
    link = u'..'
    mclass = 'nav buttons'
    def condition(self):
        self.title = self.context.__parent__.navTitle
        return True

class PrevMenuEntry(MenuItem):
    '''  A menu item for previous articles in the list
    '''
    grok.context(NoobsArticle)
    grok.order(-3)
    title = mtitle = u'Prev Page'
    mclass = 'nav buttons'
    @property
    def link(self):
        title = quote_plus(self.context.prev)
        return self.context.__parent__[title]
    def condition(self):
        if getattr(self.context, 'prev', None) is not None:
            self.title = self.context.prev
            return True

class NextMenuEntry(MenuItem):
    '''  A menu item for articles next in the list
    '''
    grok.context(NoobsArticle)
    grok.order(-2)
    title = mtitle = u'Next Page'
    mclass = 'nav buttons'
    @property
    def link(self):
        title = quote_plus(self.context.next)
        return self.context.__parent__[title]
    def condition(self):
        if getattr(self.context, 'next', None) is not None:
            self.title = self.context.next
            return True

class SorterLink(MenuItem):
    ''' A conditional menu item which shows for articles with more than one child
    '''
    grok.context(IArticle)
    grok.require(Editing)
    grok.order(-1)
{'fraction_non_alphanumeric': 0.09000439045807113, 'fraction_numerical': 0.0017561832284501682, 'mean_word_length': 2.936635944700461, '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': '4173865', 'n_tokens_mistral': 2010, 'n_tokens_neox': 1964, 'n_words': 645}