from Products.Archetypes.public import BaseSchema, Schema
from Products.Archetypes.public import StringField, LinesField
from Products.Archetypes.public import LinesWidget, TextAreaWidget, IdWidget, StringWidget
from Products.Archetypes.public import OrderedBaseFolder, registerType
from Products.CMFCore import CMFCorePermissions
from config import VIEW_CONTENTS_PERMISSION
from Products.CMFPlone.interfaces.OrderedContainer import IOrderedContainer
from UpDownMixin import UpDownMixin
schema = BaseSchema + Schema((
StringField('id',
required=0, ## Still actually required, but
## the widget will supply the missing value
## on non-submits
mode="rw",
accessor="getId",
mutator="setId",
isMetadata=1,
default=None,
widget=IdWidget(
label="ID",
label_msgid='chapter_label_id',
description="Should not contain spaces, underscores or mixed case. ID is part of the item's web address.",
description_msgid='chapter_desc_id',
visible={'view' : 'visible'},
i18n_domain="curriculum"),
),
StringField('title',
required=1,
searchable=1,
isMetadata=1,
default='',
accessor='Title',
widget=StringWidget(
label='Title',
label_msgid="chapter_label_title",
description='Enter a value for Title',
description_msgid="chapter_desc_title",
i18n_domain="curriculum"),
),
StringField('body',
isMetadata=1,
accessor='Body',
widget=TextAreaWidget(
label='Body',
label_msgid='chapter_label_body',
description='Body for this Chapter.',
description_msgid='chapter_desc_body',
i18n_domain="curriculum"),
),
))
class Chapter(OrderedBaseFolder, UpDownMixin):
"""
A folder object to store CurriculumEntries in
"""
allowed_content_types=('Chapter', 'Link', 'Image', 'File', 'Portlet')
filter_content_types=1
global_allow=0
allow_discussion = 1 # or 1
meta_type = 'Chapter'
__implements__ = (OrderedBaseFolder.__implements__, IOrderedContainer)
schema=schema
content_icon='chapter_icon.gif'
actions = ({
'id': 'view',
'name': 'View',
'action': 'string:${object_url}/chapter_view',
'permissions': (VIEW_CONTENTS_PERMISSION,)
},
{'id': 'Contents',
'name': 'Contents',
'action': 'string:${object_url}/folder_contents',
'permissions': (VIEW_CONTENTS_PERMISSION,)
},
)
def j2rglane2(self, chap, result, nr):
""" Sisukorra loomiseks """
i = 1
for chapt in chap.objectValues('Chapter'):
number =nr + str(i) + "."
result.append(number)
result.append(chapt)
number = " " + number
self.j2rglane2(chapt, result, number)
i = i + 1
return result
def getJ2rglane(self, enr):
""" Sisukorra loomiseks """
result = []
i = 1
for chap in self.objectValues('Chapter'):
number =enr + str(i) + "."
result.append(number)
result.append(chap)
number = " " + number
self.j2rglane2(chap, result, number)
i = i + 1
return result
def tagasiRiba(self, request):
""" Riba mis võldab liikuda Peatykkides tagasi """
kord = 0
cu = "/curriculum_view"
ch = "/chapter_view"
html = ""
for vanem in request.PARENTS[-3::-1]:
html = html + "<<"
if (kord == 0):
html = html + "" + vanem.title_or_id() + ""
else:
html = html + "" + vanem.title_or_id() + ""
kord = kord + 1
return html
registerType(Chapter)