# -*- coding: utf-8 # Copyright 2006 by Meelis Mets from Products.Archetypes.public import BaseSchema, Schema from Products.Archetypes.public import TextField, FileField, BooleanField, StringField from Products.Archetypes.public import TextAreaWidget, FileWidget, RichWidget, BooleanWidget, StringWidget, SelectionWidget from Products.Archetypes.public import BaseContent, OrderedBaseFolder, registerType from Globals import InitializeClass from Products.CMFCore.utils import getToolByName from BaseFunctions import BaseFunctions from AccessControl import ClassSecurityInfo, Unauthorized from config import PROJECT_NAME, GAMES_LIST schema = BaseSchema + Schema(( TextField('description', accessor='getDescription', #primary=True, validators = ('isTidyHtmlWithCleanup',), default_output_type = 'text/x-html-safe', allowable_content_types = ('text/html',), widget = RichWidget( label="Description", description="", label_msgid='label_description', description_msgid='description_description', visible={'view':'visible','edit':'visible'}, i18n_domain="psyhvel", rows = 10 ), ), BooleanField('descriptionIsTop', accessor = 'getDescriptionIsTop', default = True, widget = BooleanWidget( label = 'Description is top side', label_msgid='label_description_is_top', description = 'Check if you want to see description text in top, other way it is in bottom side', description_msgid = 'desc_description_is_top', i18n_domain="psyhvel", visible = {'view': 'invisible', 'edit':'visible'}, ), ), StringField('bestscore', accessor='getBestScore', default = '0', widget = StringWidget( label="Best score", description="", label_msgid='label_best_score', description_msgid='description_best_score', i18n_domain="psyhvel", ), ), TextField('additionalinfo', accessor='getAdditionalInfo', isMetadata = 1, schemata = 'metadata', widget = TextAreaWidget( label="Info", description="", label_msgid='label_info', description_msgid='description_info', i18n_domain="psyhvel", ), ), )) #XXX hide unneccessary metadata fields schema['language'].schemata='default' schema['language'].widget.visible = {'edit' : 'invisible', 'view' : 'invisible' } schema['subject'].schemata='default' schema['subject'].widget.visible = {'edit' : 'invisible', 'view' : 'invisible' } schema['allowDiscussion'].schemata='default' schema['allowDiscussion'].widget.visible = {'edit' : 'invisible', 'view' : 'invisible' } schema['effectiveDate'].schemata='default' schema['effectiveDate'].widget.visible = {'edit' : 'invisible', 'view' : 'invisible' } schema['expirationDate'].schemata='default' schema['expirationDate'].widget.visible = {'edit' : 'invisible', 'view' : 'invisible' } schema['contributors'].schemata='default' schema['contributors'].widget.visible = {'edit' : 'invisible', 'view' : 'invisible' } schema_game_folder = schema.copy() + Schema(( StringField('tableWidth', accessor = 'getTableWidth', vocabulary = 'getNumbers', default = '4', widget = SelectionWidget( format = 'select', label = 'Table width', label_msgid='label_table_width', description = 'How many games are in row', description_msgid = 'desc_table_width_game', i18n_domain="psyhvel", visible = {'view': 'invisible', 'edit':'visible'}, ), ), StringField('tableHeight', accessor = 'getTableHeight', vocabulary = 'getNumbers', default = '4', widget = SelectionWidget( format = 'select', label = 'Table height', label_msgid='label_table_height', description = 'How many games are in column', description_msgid = 'desc_table_height_game', i18n_domain="psyhvel", visible = {'view': 'invisible', 'edit':'visible'}, ), ), )) schema_game_collection = schema.copy() + Schema(( )) #schema_.delField('descriptionIsTop') #schema_sheet = schema.copy() + Schema(( # StringField('time', # accessor = 'getTime', # default = '0', # widget = StringWidget( # label = 'Time', # label_msgid='label_time', # description = 'Answering time, if set, form will be submitted automatically when running out of time, default is 0 - submit is manual', # description_msgid = 'desc_time', # i18n_domain="psyhvel", # visible = {'view': 'invisible', 'edit':'visible'}, # ), # ), #)) schema_game = schema.copy() + Schema(( BooleanField('showGameTime', accessor = 'getShowGameTime', default = False, widget = BooleanWidget( label = 'Show game time', label_msgid='label_show_game_time', description = 'Check if you want to show game time while playing', description_msgid = 'desc_show_game_time', i18n_domain="psyhvel", visible = {'view': 'invisible', 'edit':'visible'}, ), ), )) class GameFolder(OrderedBaseFolder, BaseFunctions): """ Psyhvel game folder""" meta_type = "GameFolder" archetype_name = "Game" global_allow = 0 exclude_from_nav = True filter_content_types = True allowed_content_types = GAMES_LIST security = ClassSecurityInfo() schema = schema_game_folder actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/games_view', 'permissions': ('View',), }, { 'id':'edit', 'name':'Edit', 'action':'string:${object_url}/base_edit', 'permissions': ('Modify portal content',), }, { 'id':'metadata', 'name':'Info', 'action':'string:${object_url}/base_metadata', 'permissions': ('Modify portal content',), }, ) #XXX this is kahtlene asi #def getCurrentSheet(self): # """return current sheet""" # return self.getFolderContents()[0].getObject() registerType(GameFolder, PROJECT_NAME) #class GameCollection(OrderedBaseFolder, BaseFunctions): # """ Psyhvel game collection""" # meta_type = "GameCollection" # archetype_name = "Game Collection" # global_allow = 0 # exclude_from_nav = True # filter_content_types = True # allowed_content_types = ('GameFolder',) # security = ClassSecurityInfo() # schema = schema_game_collection # actions = ( # { # 'id':'view', # 'name':'View', # 'action':'string:${object_url}/library_view', # 'permissions': ('View',), # }, # { # 'id':'edit', # 'name':'Edit', # 'action':'string:${object_url}/base_edit', # 'permissions': ('Modify portal content',), # }, # { # 'id':'metadata', # 'name':'Info', # 'action':'string:${object_url}/base_metadata', # 'permissions': ('Modify portal content',), # }, # ) # #registerType(GameCollection, PROJECT_NAME) class BaseGame(BaseContent): """ Psyhvel base game""" meta_type = "BaseGame" archetype_name = "Base Game" global_allow = 0 exclude_from_nav = True filter_content_types = True allowed_content_types = () security = ClassSecurityInfo() schema = schema_game def getGameMessages(self): """game messages""" if not hasattr(self, 'gameMessages'): self.gameMessages = [] return self.gameMessages def addGameMessage(self): """game message""" action = int(self.REQUEST.get('message_action')) message = self.REQUEST.get('message_text') time = int(self.REQUEST.get('message_time')) if action>=0 and action<3 and message and time>=0: self.gameMessages.append([time,message,action]) self.p_changed = 1 return self.REQUEST.RESPONSE.redirect(self.absolute_url()+"/game_messages") def delGameMessages(self): """remove selected rows""" for_remove = self.REQUEST.get("rows_for_remove") if for_remove: if isinstance(for_remove, type('')): for_remove = [for_remove] for_remove.reverse() for fr in for_remove: self.gameMessages.pop(int(fr)) self.p_changed = 1 return self.REQUEST.RESPONSE.redirect(self.absolute_url()+"/game_messages") def setGameInfo(self): """game info""" pass registerType(BaseGame, PROJECT_NAME)