def initialize_activity(self, request, new_activity): '''Called from the Administrator. Sets up the activity''' treeroot = datagate.create_item(creatorid=request.session.user.id, parentid=new_activity.id) treeroot.name = 'treeroot' treeroot.save() # set up the first item in the tree initialnode = datagate.create_item(creatorid=request.session.user.id, parentid=treeroot.id) initialnode.text = 'Root Item' initialnode.save() # set the rating information new_activity.ratingMultiplier = '1' new_activity.commentMultiplier = '1' new_activity.ratingsScoreMultiplier = '1' new_activity.ratingRefreshRate = '20' new_activity.ratingGoal = '100' new_activity.pacingDuration = '180' new_activity.pacingValues = '30 Fast\n15 Medium\n0 Slow' new_activity.pacingLogFile = '' new_activity.estimatedMeetingDuration = '0' new_activity.save() # set user rights BaseView.BaseView.initialize_activity(self, request, new_activity)
def initialize_activity(self, request, meeting): '''Called from the Administrator. Sets up the activity''' BaseView.BaseView.initialize_activity(self, request, meeting) activities = datagate.create_item(creatorid=request.session.user.id, parentid=meeting.id) activities.name='activities' activities.save() editor = datagate.create_item(creatorid=request.session.user.id, parentid=activities.id) editor.name = "Question Editor" editor.previousid = '' editor.view = 'questioneditor' editor.save() asker = datagate.create_item(creatorid=request.session.user.id, parentid=activities.id) asker.name = "Assessment" asker.previousid = '' asker.view = 'questionasker' asker.save() findings = datagate.create_item(creatorid=request.session.user.id, parentid=activities.id) findings.name = "Findings" findings.previousid = '' findings.view = 'reportfindings' findings.save() brainstorming = datagate.create_item(creatorid=request.session.user.id, parentid=activities.id) brainstorming.name = "Commenter" brainstorming.previousid = '' brainstorming.view = 'commenter' brainstorming.save() groups = meeting.search1(name='groups') pm = datagate.create_item(creatorid=request.session.user.id, parentid=groups.id) pm.name = "PM" pm.sets = '' pm.save() pmo = datagate.create_item(creatorid=request.session.user.id, parentid=groups.id) pmo.name = "PMO" pmo.sets = '' pmo.save() contractor = datagate.create_item(creatorid=request.session.user.id, parentid=groups.id) contractor.name = "Contractor" contractor.sets = '' contractor.save() stakeholder = datagate.create_item(creatorid=request.session.user.id, parentid=groups.id) stakeholder.name = "Senior Stakeholder" stakeholder.sets = '' stakeholder.save() user = datagate.create_item(creatorid=request.session.user.id, parentid=groups.id) user.name = "User" user.sets = '' user.save() # allow the activity view to initialize itself BaseView.views[editor.view.lower()].initialize_activity(request, editor) BaseView.views[asker.view.lower()].initialize_activity(request, asker) BaseView.views[findings.view.lower()].initialize_activity(request, findings) BaseView.views[brainstorming.view.lower()].initialize_activity(request, brainstorming)
def answer_question_action(self, request, id, ans, com): creator = request.session.user item = datagate.get_item(id) answers = item.search1(name="answers") #if this user has already answered this question, update it instead of creating it answer = None for each in answers: if each.who == creator.name: answer = each if not answer: answer = datagate.create_item(creatorid=creator.id, parentid=answers.id) answer.name = 'answer' answer.who = creator.name answer.when = time.strftime('%a, %d %b %Y %H:%M:%S') answer.answer = ans answer.comment = com answer.save() meeting = Directory.get_meeting(request.getvalue('global_rootid', '')) parent = meeting.get_parent() activities = parent.search1(view='questioneditor') userAnswer = activities.search1(name="userAnswers") userFound = False if userAnswer != None: for user in userAnswer: if user.name == creator.name: userFound = True answered = None for child in user: if child.questionId == id: answered = child if not answered: answered = datagate.create_item(creatorid=creator.id, parentid=user.id) answered.questionId = id answered.answer = ans answered.when = time.strftime('%a, %d %b %Y %H:%M:%S') answered.save() if userFound == False or userAnswer == None: userCreated = datagate.create_item(creatorid=creator.id, parentid=userAnswer.id) userCreated.name = creator.name answered = datagate.create_item(creatorid=creator.id, parentid=userCreated.id) answered.questionId = id answered.answer = ans answered.when = time.strftime('%a, %d %b %Y %H:%M:%S') answered.save() if id not in creator.answeredQuestions: creator.answeredQuestions.append(id) #creator.backtrack = 0 #resets the user to their first unanswered question if creator.backtrack < 0: creator.backtrack += 1 #moves the user forward one question creator.save() event = QuestionAsker.next_question(self,request,creator) return event
def ensure_enough_turns(self, request, turns): '''Ensure sthere are enough turn items in the tree for the total turns in the game''' # make sure we have enough children for the turns while len(turns.get_child_items()) <= turns.totalturns: turn = datagate.create_item(parentid=turns.id, creatorid=request.session.user.id) turn.committed = {} assetmoves = datagate.create_item(parentid=turn.id, creatorid=request.session.user.id) assetmoves.name = 'assetmoves' assetmoves.save() whiteboard = datagate.create_item(parentid=turn.id, creatorid=request.session.user.id) whiteboard.name = 'whiteboard' whiteboard.save() turn.save()
def initialize_activity(self, request, root, tree_links=None): """Called from the administrator. Initializes the tree given a tree root item and tree links item""" treeroot = datagate.create_item(creatorid=request.session.user.id, parentid=root.id) treeroot.name = "treeroot" treeroot.save() # set up the first item in the tree initialnode = datagate.create_item(creatorid=request.session.user.id, parentid=treeroot.id) initialnode.text = self.initial_text initialnode.save() if tree_links != None: self.initialize_item(request, initialnode, tree_links.id) # set user rights BaseView.BaseView.initialize_activity(self, request, root)
def addgroup_action(self, request): game = datagate.get_item(request.getvalue('itemid')) teams = game.search1(name='groups') chats = game.search1(name='chats') board = game.search1(name='board') name = request.getvalue('name', '') if name: group = datagate.create_item(creatorid=request.session.user.id, parentid=teams.id) group.name = name group.save() teamchat = datagate.create_item(creatorid=request.session.user.id, parentid=chats.id) teamchat.name = name teamchat.save() BaseView.get_view('strikecomcommenter').initialize_activity(request, teamchat)
def initialize_activity(self, request, game): '''Called from the Administrator when this game is created. Sets up the initial items in the tree.''' BaseView.BaseView.initialize_activity(self, request, game) # set up the first level objects for childname in [ 'chats', 'board', 'turns' ]: child = datagate.create_item(creatorid=request.session.user.id, parentid=game.id) child.name = childname child.save() # set up the playing board board = game.search1(name='board') board.gridrows = '3' board.gridcols = '3' for r in range(int(board.gridrows)): for c in range(int(board.gridcols)): cell = 'terrain' + str(r) + '-' + str(c) setattr(board, cell, 'Default') #setattr(board, cell, request.getvalue(cell, 'Default')) board.gridheight = '500' board.gridwidth = '500' board.filename = '' board.save() # set up the turns turns = game.search1(name="turns") turns.totalturns = 5 turns.currentturn = 0 turns.save() self.ensure_enough_turns(request, turns)
def newasset_action(self, request): '''Adds the new asset to the board''' if request.getvalue('assetid', ''): # editing asset = datagate.get_item(request.getvalue('assetid', '')) else: # new item game = datagate.get_item(request.getvalue('global_rootid')) turns = game.search1(name='turns') fileitem = request.form['_icon'] if not fileitem.filename: request.error = 'Assets must have an associated icon.' return zeroTurn = turns.get_child(turns.childids[0]).search1(name='assetmoves') asset = datagate.create_item(parentid=zeroTurn.id, creatorid=request.session.user.id) asset.filename = '' asset.assetid = GUID.generate() asset.name = request.getvalue('name', '') asset.width = request.getvalue('width', '') asset.height = request.getvalue('height', '') asset.row = request.getvalue('row', '') asset.col = request.getvalue('col', '') asset.striking = request.getvalue('_striking') asset.defensive = request.getvalue('_defensive') asset.sight = request.getvalue('_sight') asset.visibility = request.getvalue('_visibility') asset.terrains = request.getlist('_terrains') asset.visible_by=[] asset.move_by=[] fileitem = request.form['_icon'] if fileitem.filename: asset.filebytes = fileitem.file.read() asset.filetype = fileitem.type asset.filename = fileitem.filename asset.save()
def process_admin_actions(self, request, vote): action = request.getvalue('voteraction', '') if action == 'changetype': vote.type = request.getvalue('type', '') vote_classes[vote.type].initialize_vote(vote) vote.save() elif action == 'newvoteitem': voteitems = vote.search1(node='VoteItems') newitem = datagate.create_item(parentid=voteitems.id, creatorid=request.session.user.id) newitem.text = request.getvalue('text', '') newitem.save() elif action == 'deletevoteitem': datagate.del_item(request.getvalue('votechildid', '')) elif action == 'pasteclipboard': # get the data from the session object try: itemids = request.session.clipboarddata except AttributeError: # no clipboard data available return # paste to the current root id events = [] vote = datagate.get_item(request.getvalue('itemid', '')) parent = vote.search1(node='VoteItems') for itemid in itemids: if datagate.get_item(itemid): newitem = datagate.copy_deep(itemid, parent.id)
def create_meeting(name, view, creatorid): '''Creates a new meeting given the name''' meeting = datagate.create_item(creatorid=creatorid, previousid='last', parentid=meetings_item.id) meeting.name = name meeting.view = view meeting.save() return meeting
def send_comment(self, userid, prefix, comment): self.lock.acquire() # only send one comment at a time (since we're hitting multiple rootids) try: sent_to = {} for sessionid, rootid in self.sessions.items(): # get the session; if the session has expired, remove and move on session = Directory.get_session(sessionid) if not session: del self.sessions[sessionid] continue # if we've already sent to this rootid, skip and move on if sent_to.has_key(rootid): continue sent_to[rootid] = rootid # find the actual parent of this comment root = datagate.get_item(rootid) if not root: print "RatingProxy couldn't find rootid:", rootid continue parentid = self.find_parent(root, prefix) or rootid # create and send the event to the system (goes to all interested users) # I'm using a blank windowid so it goes to anyone looking at this rootid item = datagate.create_item(parentid=parentid, creatorid=userid) item.text = comment item.save() event = BaseView.views['rating']._create_event(item, 'processAdd') Events.send_event(rootid, event) finally: self.lock.release()
def initialize_activity(self, request, new_activity): '''Called from the Administrator. Sets up the activity''' BaseView.initialize_activity(self, request, new_activity) creator = request.session.user listitems = datagate.create_item(creatorid=creator.id, parentid=new_activity.id) listitems.name = 'listitems' listitems.save()
def initialize_activity(self, request, vote): '''Allows a view to customize a newly-created Activity. Called from the Administrator when the view is added to a meeting as an activity.''' # set the initial type of this view vote.type = vote_types[0][0] vote_classes[vote_types[0][0]].initialize_vote(vote) vote.save() # create the items (holds the voting item text) vote_items = datagate.create_item(parentid=vote.id, creatorid=request.session.user.id) vote_items.node = 'VoteItems' vote_items.save() # create the user votes items (holds one child for each user's vote) user_votes = datagate.create_item(parentid=vote.id, creatorid=request.session.user.id) user_votes.node = 'UserVotes' user_votes.save()
def add_listitem_action(self, request, listitemtext): root = datagate.get_item(request.getvalue('global_rootid', '')) creator = request.session.user listitems = root.search1(name="listitems") item = datagate.create_item(creatorid=creator.id, parentid=listitems.id) item.text = listitemtext item.save() return Event('receiveListItem', item.id, item.text)
def add_listitem2_action(self, request): root = datagate.get_item(request.getvalue('global_rootid', '')) creator = request.session.user listitems = root.search1(name="listitems") item = datagate.create_item(creatorid=creator.id, parentid=listitems.id) # since we are using a form, we have to get the form values in the normal way item.text = request.getvalue('listitemtext2', '') item.save() return Event('receiveListItem', item.text)
def addactivity_action(self, request): item = datagate.get_item(request.getvalue('itemid', '')) # create the activity activity = datagate.create_item(creatorid=request.session.user.id, parentid=item.id, previousid='last') activity.name = request.getvalue('name', '') activity.view = request.getvalue('viewtype', '') activity.linkitemid = activity.id # default the link to myself (an analyzer can override this) activity.save() BaseView.views[activity.view.lower()].initialize_activity(request, activity)
def create_user(creatorid): '''Creates a new user''' user = datagate.create_item(creatorid=creatorid, parentid=users_item.id) for key in USER_FIELDS: setattr(user, key, '') user.superuser = '******' user.active = '1' user.save() return user
def add_question_action(self, request): root = datagate.get_item(request.getvalue('global_rootid', '')) creator = request.session.user questions = root.search1(name="questions") item = datagate.create_item(creatorid=creator.id, parentid=questions.id) item.name = "question" item.text = "New Question" item.delete = False item.descrip = "" poet = datagate.create_item(creatorid=creator.id, parentid=item.id) poet.name = 'poet' poet.save() sets = datagate.create_item(creatorid=creator.id, parentid=item.id) sets.name = 'sets' sets.save() tagSets = root.search1(name="sets") tags = [] for tag in tagSets: tags.append(tag.name) meeting = datagate.get_item(request.getvalue('global_meetingid', '')) usergroups = meeting.search1(name='groups') groups = datagate.get_child_items(usergroups.id) users = [] for group in groups: users.append(group.name) item.users = users item.format = 'likert' item.comment = "" item.comOpt = "" item.na = "" item.save() options = datagate.create_item(creatorid=creator.id, parentid=item.id) options.name = 'options' options.num_selections = 0 options.save() answers = datagate.create_item(creatorid=creator.id, parentid=item.id) answers.name = 'answers' answers.save() events = [] events.append(Event('addToQuestionList', item.id, item.text, item.delete)) events.append(Event('addAllUsers', users)) events.append(Event('addSets', tags)) events.append(Event('populateForm', item.text, item.descrip, item.users, item.format, item.comment, item.comOpt, options.num_selections, [], '', item.na)) return events
def add_item_action(self, request): # perform the action rights = self.get_user_rights(request) creator = request.session.user item = datagate.create_item(creatorid=creator.id, parentid=request.getvalue('parentid'), previousid=request.getvalue('previousid')) item.text = request.getvalue('text', '') item.save() # send the event to the client return [ self._create_event(item, 'processAdd') ]
def getview(self, request, activity, row, col, default_view='blank'): '''Returns the view at the specified position, creating it if necessary''' index = 'row' + str(row) + 'col' + str(col) child = activity.search1(position=index) if child == None: child = datagate.create_item(creatorid=request.session.user.id, parentid=activity.id) child.position = index child.view = default_view child.save() BaseView.views[child.view].initialize_activity(request, child) return child
def add_item_action(self, request): # perform the action creator = request.session.user item = datagate.create_item( creatorid=creator.id, parentid=request.getvalue("parentid"), previousid=request.getvalue("previousid") ) item.text = request.getvalue("text", "") item.save() # if this tree is in an analyzer, add the tree links id tree_links_id = request.getvalue("treelinkid", "") if tree_links_id: linknode = datagate.create_item(creatorid=creator.id, parentid=tree_links_id) linknode.treenodeid = item.id item.linkid = linknode.id item.save() linknode.save() # send the event to the client return [self._create_add_event(item)]
def initialize_activity(self, request, new_activity, tabdefs=[ ('Comments:', 'Commenter') ]): '''Called from the Administrator. Sets up the activity. tabdefs is a list of tuples ( "tab name", "tab view" ) defining initial tabs for the view ''' # set up the initial tabs for name, view in tabdefs: tab = datagate.create_item(creatorid=request.session.user.id, parentid=new_activity.id) tab.name = name tab.view = view tab.linkitemid = tab.id # default the link to myself tab.save() BaseView.views[tab.view.lower()].initialize_activity(request, tab)
def initialize_activity(self, request, new_activity): '''Called from the Administrator. Sets up the activity''' # set up the tree root treeroot = datagate.create_item(creatorid=request.session.user.id, parentid=new_activity.id) treeroot.type = 'TreeRoot' treeroot.save() # set up the tree links node treelinks = datagate.create_item(creatorid=request.session.user.id, parentid=new_activity.id) treelinks.type = 'TreeLinks' treelinks.save() # let the tree initialize itself BaseView.views['tree'].initialize_activity(request, treeroot, treelinks) # set up the tabs for this activity tabdefs = datagate.create_item(creatorid=request.session.user.id, parentid=new_activity.id) tabdefs.type = 'TabDefs' tabdefs.name = 'Activity Tabs' tabdefs.save() BaseView.views['tabpane'].initialize_activity(request, tabdefs)
def record_vote(self, request, vote, voteitems, uservotes): '''Records a vote. Returns the new user vote item if the vote was recorded. If the vote was incomplete and cannot be recorded, it throws an exception.''' # record the vote uservote = datagate.create_item(parentid=uservotes.id, creatorid=request.session.user.id) uservote.userid = request.session.user.id votechildren = voteitems.get_child_items() for i in range(len(votechildren)): votechild = votechildren[i] setattr(uservote, votechild.id, request.getvalue('vote' + votechild.id, '')) uservote.save() return uservote
def add_comment_action(self, request): '''Responds to an add from the browser.''' # create the new item creator = request.session.user root = datagate.get_item(request.getvalue('global_rootid', '')) comments = root.search1(name="comments") item = datagate.create_item(creatorid=creator.id, parentid=comments.id) item.text = request.getvalue('text', '') item.save() # return a new event return [ self._create_add_event(item) ]
def add_option_action(self, request, id, option, formatType): creator = request.session.user item = datagate.get_item(id) options = item.search1(name="options") choice = datagate.create_item(creatorid=creator.id, parentid=options.id) choice.text = option choice.save() allChoices = options.get_child_items(self) allOptions = [] for choice in allChoices: allOptions.append(choice.text) return Event('populateOptions', formatType, allOptions)
def initialize_activity(self, request, new_activity): '''Called from the Administrator. Sets up the activity''' BaseView.initialize_activity(self, request, new_activity) creator = request.session.user questions = datagate.create_item(creatorid=creator.id, parentid=new_activity.id) questions.name = 'questions' questions.save() userAnswer = datagate.create_item(creatorid=creator.id, parentid=new_activity.id) userAnswer.name = 'userAnswers' userAnswer.save() sets = datagate.create_item(creatorid=creator.id, parentid=new_activity.id) sets.name = 'sets' sets.save() allTags = ['Mandatory','Commitment','Trust','Mindset','SA','Resources','Complexity','Agility','Teamwork','Demonstrability'] for t in allTags: tag = datagate.create_item(creatorid=creator.id, parentid=sets.id) tag.name = t tag.save() groupMapping = datagate.create_item(creatorid=creator.id, parentid=new_activity.id) groupMapping.name = 'groupMapping' groupMapping.save() activites = new_activity.get_parent() meeting = activites.get_parent() groups = meeting.search1(name='groups') for group in groups: newUserGroup = datagate.create_item(creatorid=creator.id, parentid=groupMapping.id) newUserGroup.name = group.name newUserGroup.save()
def add_set_action(self, request, tag): root = datagate.get_item(request.getvalue('global_rootid', '')) creator = request.session.user sets = root.search1(name="sets") s = datagate.create_item(creatorid=creator.id, parentid=sets.id) s.name = tag s.save() allTags = [] for t in sets: allTags.append(t.name) events = [] events.append(Event('addSets', allTags)) return events
def edit_question_action(self, request, id, text, descrip, users, ansFormat, comment, optional, num, categoryIdList, poetCategoryList, tags, na): creator = request.session.user item = datagate.get_item(id) item.text = text item.descrip = descrip poet = item.search1(name="poet") allPoet = poet.get_child_items(self) for p in allPoet: p.delete() for factor in poetCategoryList: f = datagate.create_item(creatorid=creator.id, parentid=poet.id) f.name = factor f.save() sets = item.search1(name="sets") allSets = sets.get_child_items(self) for s in allSets: s.delete() for tag in tags: t = datagate.create_item(creatorid=creator.id, parentid=sets.id) t.name = tag t.save() item.format = ansFormat item.users = users item.comment = comment item.comOpt = optional item.na = na item.save() options = item.search1(name="options") options.num_selections = num options.save() allChoices = options.get_child_items(self) allOptions = [] for choice in allChoices: allOptions.append(choice.text) root = datagate.get_item(request.getvalue('global_rootid', '')) events = [] events.append(Event('populateCategories', poetCategoryList)) events.append(Event('populateForm', item.text, item.descrip, item.users, item.format, item.comment, item.comOpt, options.num_selections, allOptions, tags, item.na)) return events
def add_sub_comment_action(self, request): '''Responds to an add sub idea from the browser.''' # create the new item text = request.getvalue('text', '') creator = request.session.user comment = datagate.get_item(request.getvalue('itemid')) item = datagate.create_item(creatorid=creator.id, parentid=comment.id) item.text = text item.time = time.time() log.info(str(item.time)) item.save() return self._create_add_event(comment)