Ejemplo n.º 1
0
  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)
Ejemplo n.º 2
0
 def get_initial_events(self, request, rootid):
   '''Retrieves a list of initial javascript calls that should be sent to the client
      when the view first loads.  Typically, this is a series of add_processor
      events.'''
   root = datagate.get_item(rootid) 
   events = []
   checkedPoet = ""
   events.append(Event('populateCategories', checkedPoet))
   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)
   tagSets = root.search1(name="sets")
   sets = []
   for tag in tagSets:
       sets.append(tag.name)
   
   # the questions list
   for child in root.search1(name="questions"):
     options = child.search1(name="options")     
     allChoices = options.get_child_items(self)
     allOptions = []
     for choice in allChoices:
       allOptions.append(choice.text)
     allSets = child.search1(name="sets")       
     tags = []
     for t in  allSets.get_child_items(self):
       tags.append(t.name)
     events.append(Event('addToQuestionList', child.id, child.text, child.delete))
     events.append(Event('addAllUsers', users))
     events.append(Event('addSets', sets))
     events.append(Event('populateForm', child.text, child.descrip, child.users, child.format, child.comment, child.comOpt, options.num_selections, allOptions, tags, child.na))
   return events  
Ejemplo n.º 3
0
  def remove_sets_action(self, request, setsToRemove):
    root = datagate.get_item(request.getvalue('global_rootid', ''))
    creator = request.session.user
    sets = root.search1(name="sets")

    meeting = datagate.get_item(request.getvalue('global_meetingid', ''))
    usergroups = meeting.search1(name='groups')
    unremovableSets = []
    for group in usergroups:
      if not group.sets == []: #don't bother iterating if there's nothing to compare it to
        for s in setsToRemove[:]: #the [:] makes a copy of the list, so we can safely delete items without messing up the iteration
          if s in group.sets: #if we find a set has been asked to a group...
            setsToRemove.remove(s) #...don't remove it.
            unremovableSets.append(s) #just for error-announcing
    #SHEP: create an error letting the user know why the unremoveableSets weren't removed
    
    setsThatRemain = []
    for child in sets:
      if child.name in setsToRemove:
        child.delete()
      else:
        setsThatRemain.append(child.name)

    # refresh the page
    sets.save()
    events = []
    events.append(Event('addSets', setsThatRemain))
    return events
Ejemplo n.º 4
0
 def moveactivity_action(self, request):
   item = datagate.get_item(request.getvalue('itemid', ''))
   activity = datagate.get_item(request.getvalue('activityid'))
   parent = activity.get_parent()
   parent.remove_child(activity)
   parent.insert_child(activity, request.getvalue('previousid'))
   parent.save()
Ejemplo n.º 5
0
  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()
Ejemplo n.º 6
0
 def _create_add_event(self, item):
   log.info(str(item));
   subitems = []
   creator = datagate.get_item(item.creatorid)
   for si in item.get_child_items():
     siCreator = datagate.get_item(si.creatorid)
     subitems.append([si.text, siCreator.name, siCreator.email]);
   log.info(str(subitems))
   return Event('processAdd', item.id, item.text, item.time, creator.id, creator.name, creator.email, subitems)
Ejemplo n.º 7
0
 def assetteam_action(self, request):
   game = datagate.get_item(request.getvalue('itemid'))
   teams = game.search1(name='groups')
   asset_id = request.getvalue('_assetid')
   asset = datagate.get_item(asset_id)
   asset.teamid = request.getvalue('_teamid')
   log.debug("assetteam"+asset.teamid)
   # remove all the user rights (those users are on the old team)
   asset.move_by = []
   asset.visible_by = []
   asset.save()
Ejemplo n.º 8
0
 def saverating_action(self, request):
   '''Saves a rating for the current user'''
   root = datagate.get_item(request.getvalue('global_rootid', ''))
   rating_names = self.get_rating_names(root)
   item = datagate.get_item(request.getvalue('itemid'))
   for name in rating_names:
     setattr(item, 'rating_' + name + '_' + request.session.user.id, request.getvalue('rating_' + name))
   item.save()
   
   # send the event back to the client
   return [ self._create_event(item, 'processEdit') ]
Ejemplo n.º 9
0
 def get_initial_events(self, request, rootid):
   '''Retrieves a list of initial javascript calls that should be sent to the client
      when the view first loads.  Typically, this is a series of add_processor
      events.'''
   events = []
   root = datagate.get_item(rootid)
   comments = root.search1(name="comments")
   for item in comments.get_child_items():
     creator = datagate.get_item(item.creatorid)
     events.append('processAdd("%s","%s","%s","%s")' % (item.id, item.text, creator.name, creator.email))
   return events
Ejemplo n.º 10
0
def get_meeting_users(global_meetingid):
  '''Returns all users in the given meeting as a list of items.  The list is sorted by username.
  '''
  meeting = datagate.get_item(global_meetingid)
  groups_item = meeting.search1(name='groups')
  # using a dict ensures we don't get duplicate users (in more than one group, which is allowed)
  users = {}
  for group in groups_item.get_child_items():
    for user_link in group.get_child_items():
      users[user_link.user_id] = datagate.get_item(user_link.user_id)
  # sort and return
  user_list = users.values()
  user_list.sort(lambda a,b: cmp(a.username, b.username))
  return user_list
Ejemplo n.º 11
0
 def get_initial_events(self, request, rootid):
     """Retrieves a list of initial javascript calls that should be sent to the client
    when the view first loads.  Typically, this is a series of add_processor
    events."""
     root = datagate.get_item(rootid)
     treeroot = root.search1(name="treeroot")
     return [self._create_add_event(item) for item in treeroot.get_child_items(deep=1)]
Ejemplo n.º 12
0
 def delgroup_action(self, request):
   game = datagate.get_item(request.getvalue('itemid'))
   turns = game.search1(name='turns')
   groupid = request.getvalue('groupid')
   group = datagate.get_item(groupid)
   # go through the assets for this group and delete any assets who were in this group
   for turn in turns:
     for asset in turn.search1(name='assetmoves'):
       if asset.teamid == groupid:
         asset.delete()
   datagate.del_item(request.getvalue('groupid', ''))
   game = datagate.get_item(request.getvalue('itemid'))
   chats = game.search1(name='chats')
   group_name = request.getvalue('groupname','')
   group_chat = chats.search1(name=group_name)
   datagate.del_item(group_chat.id)
Ejemplo n.º 13
0
 def send_main_frames(self, request):
   # get the game objects
   game = datagate.get_item(request.getvalue('global_rootid'))
   teams = game.search1(name='groups')
   team = Directory.get_group(game.id, request.session.user.id)
   if not team:
     raise 'You have not been added to a team in this game.'
   try: 
     chats = game.search1(name='chats') # just use first team's chat for now -- eventually we want to see what team the user is on and link to the chat parent for that team
   except IndexError:
     raise 'You cannot play a StrikeCom game without any teams.  Please add at least one team and try again.'
   chat = chats.search1(name=team.name)
   board = game.search1(name='board')
   turns = game.search1(name='turns')
   
   # send the html
   request.writeln(HTML_HEAD_NO_CLOSE)
   request.writeln('''
     </head>
     <frameset border="0" rows="45,*">
       <frame marginheight="0" marginwidth="0" scrolling="no" name="navigation" src="''' + request.cgi_href(subview='navigation') + '''">
       <frame marginheight="0" marginwidth="0" scrolling="no" name="game" src="''' + request.cgi_href(subview='game') + '''">
     </frameset>
     </html>
   ''')
Ejemplo n.º 14
0
  def send_upload_form(self, request):
    '''An example form to upload files.'''
    root = datagate.get_item(request.getvalue('global_rootid', ''))
    request.writeln(HTML_HEAD + HTML_BODY)

    # show the existing graphic (we assume it is a graphic for example purposes, but it could be anything)
    if hasattr(root, 'filebytes'):
      request.writeln('''
        <div align="center">&nbsp;</div>
        <div align="center">
          <img src="''' + request.cgi_href(view="Filer", gm_contenttype=encode(root.filetype), subview=None, file=None) + '''" border=0>
        </div>
        <div align="center">&nbsp;</div>
      ''')

    # upload form
    # I use an _ for the name of the control so it doesn't get passed around to other forms
    request.writeln(request.cgi_multipart_form(gm_action="uploadfile", file=None) + '''
      <div align="center">
      Upload new image:
      <input type="file" name="_file">
      <input type="submit" value="Upload">
      </form>
      </div>
    ''')
    request.writeln("</body></html>")
Ejemplo n.º 15
0
  def send_game(self, request):
    '''Shows the game window'''
    # get the game objects
    game = datagate.get_item(request.getvalue('global_rootid'))
    teams = game.search1(name='groups')
    team = Directory.get_group(game.id, request.session.user.id)
    if not team:
      raise 'You have not been added to a team in this game.'
    try: 
      chats = game.search1(name='chats') # just use first team's chat for now -- eventually we want to see what team the user is on and link to the chat parent for that team
    except IndexError:
      raise 'You cannot play a StrikeCom game without any teams.  Please add at least one team and try again.'
    chat = chats.search1(name=team.name)
    board = game.search1(name='board')
    turns = game.search1(name='turns')

    request.writeln(HTML_HEAD)
    request.writeln('''
      <frameset border="0" cols="*,200">  
        <frameset border="0" rows="*,50">
          <frame marginheight="0" marginwidth="0" name="playingboard" src="''' + request.cgi_href(global_rootid=turns.id, view='StrikeComPlayingBoard', frame=None) + '''">
          <frame scrolling="no" marginheight="0" marginwidth="0" name="legend" src="''' + request.cgi_href(view='StrikeComLegend', frame=None) + '''">
        </frameset>
        <frame scrolling="no" marginheight="0" marginwidth="0" name="chat" src="''' + request.cgi_href(global_rootid=chat.id, view='StrikeComCommenter', frame=None) + '''">
      </frameset>
    ''')    
Ejemplo n.º 16
0
 def editname_action(self, request):
   item = datagate.get_item(request.getvalue('itemid', ''))
   itemname = request.getvalue('activityname', '')
   if itemname != '':
     child = item.get_child(request.getvalue('activityid'))
     child.name = itemname
     child.save()
Ejemplo n.º 17
0
 def newrating_action(self, request):
   activity = datagate.get_item(request.getvalue('itemid', ''))
   name = request.getvalue('name', '')
   setattr(activity, 'rating_' + name, name)
   setattr(activity, 'ratinginfo_' + name + '_adjustment', request.getvalue('adjustment', ''))
   setattr(activity, 'ratinginfo_' + name + '_options', request.getvalue('options', ''))
   activity.save()
Ejemplo n.º 18
0
 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()
Ejemplo n.º 19
0
 def delrating_action(self, request):
   activity = datagate.get_item(request.getvalue('itemid', ''))
   name = request.getvalue('name', '')
   delattr(activity, 'rating_' + name)
   delattr(activity, 'ratinginfo_' + name + '_adjustment')
   delattr(activity, 'ratinginfo_' + name + '_options')
   activity.save()
Ejemplo n.º 20
0
  def send_frames(self, request):
    '''Sends the main frames'''
    # start the automatic comments, if needed
    item = datagate.get_item(request.getvalue('global_rootid', ''))
    
    # save rootids
    self.lock.acquire()
    try:
      self.sessions[request.session.id] = item.id
    finally:
      self.lock.release()

    if request.session.user.superuser == '1':
      request.writeln(HTML_HEAD)
      request.writeln("<frameset border='1' cols='40%,*'>")
      request.writeln("<frame marginheight='0' marginwidth='0' name='control' src='" + request.cgi_href(_frame='control') + "'>")
      request.writeln("<frame marginheight='0' marginwidth='0' name='component' src='" + request.cgi_href(view='rating') + "'>")
      request.writeln("</frameset>")
      request.writeln("</html>")   

    else:
      request.writeln(HTML_HEAD)
      request.writeln("<frameset border='0' cols='*'>")
      request.writeln("<frame marginheight='0' marginwidth='0' name='component' src='" + request.cgi_href(view='rating') + "'>")
      request.writeln("</frameset>")
      request.writeln("</html>")   
Ejemplo n.º 21
0
 def formula_action(self, request):
   activity = datagate.get_item(request.getvalue('itemid', ''))
   activity.ratingMultiplier = request.getvalue('ratingMultiplier', '0')
   activity.commentMultiplier = request.getvalue('commentMultiplier', '0')
   activity.ratingsScoreMultiplier = request.getvalue('ratingsScoreMultiplier', '0')
   activity.ratingRefreshRate = request.getvalue('ratingRefreshRate', '20')
   activity.save()
Ejemplo n.º 22
0
  def export_action(self, request):
    root = datagate.get_item(request.getvalue('global_rootid', ''))
    questions = root.search1(name="questions")
    doc = xml.dom.minidom.Document()
    docRoot = doc.appendChild(doc.createElement("QuestionSystem"))
    questionRoot = questions.export().documentElement
    questionRoot.tagName = 'Questions'
    docRoot.appendChild(questionRoot)
    #this returns four "Data" (all internal metadata of the "Question" node; discardable)...
    #...and some "Child" nodes (these are the questions: parse these!)
    f = open('qaDoc.xml','w')
    print >>f, doc.toxml()
    f.close()

    events = []
    
    f = open("../webroot/GroupMind/exportedMeeting.xml", 'w')
    print >> f, doc.toxml()
    f.close()
    
    #fileName = tkFileDialog.asksaveasfilename(initialfile="exportedMeeting.xml", title="Save Questions As...")
    
    #print filename
    
    events.append(Event('redirectXML'))
    return events
Ejemplo n.º 23
0
 def reviseoptions_action(self, request):
   activity = datagate.get_item(request.getvalue('itemid', ''))
   activity.num_comment_revisions = int(request.getvalue('num_comment_revisions', '3'))
   activity.min_unrevised = int(request.getvalue('min_unrevised', '2'))
   activity.save()
   
     
Ejemplo n.º 24
0
  def send_navigation(self, request):
    game = datagate.get_item(request.getvalue('global_rootid'))
    turns = game.search1(name='turns')

    request.writeln(HTML_HEAD_NO_CLOSE)
    request.writeln('''
      <script language='JavaScript' type='text/javascript'>
        function changeturn(turnnum) {
          window.parent.game.location.href = "''' + request.cgi_href(subview='game', turnnum=None) + '''&turnnum=" + turnnum;
        }

      </script>
    ''')
    request.writeln('</head>')
    request.writeln('<body bgcolor="#12255D" bottommargin="4" topmargin="4" leftmargin="4" rightmargin="4">')
    request.writeln('<table border=0 cellspacing=0 cellpadding=0 width="100%"><tr>')
    request.writeln('<td valign="middle" style="color:#CCC" align="left" width="20%"><img src="/strikecom/bullseye.png" border="0"></td>')
    request.writeln('<td valign="middle" style="color:#CCC" align="center" width="60%">')
    request.writeln('Turn:')
    request.writeln('<select name="currentturn" onchange="changeturn(this.value)">')
    request.writeln('<option value="0">Pregame</option>')
    allturns = turns.get_child_items()
    for i in range(1, turns.totalturns+1):
      request.writeln('<option value="' + str(i) + '">' + str(i) + '</option>')
    request.writeln('</select>')
    request.writeln('/')
    request.writeln(str(turns.totalturns))
    request.writeln('<td valign="middle" style="color:#CCC" align="right" width="20%"><a href="http://www.cmi.arizona.edu"><img src="/strikecom/cmi.jpg" border=0></a></td>')
    request.writeln('</tr></table>')
    request.writeln('</body></html>')
Ejemplo n.º 25
0
 def send_pickbestform(self, request, itemid):
   '''Sends the revise comment form'''
   item = datagate.get_item(itemid)
   request.writeln(
     HTML_HEAD + self.BODY_TAG_NO_CLOSE + ''' topmargin="8">
     ''' + request.cgi_form(subview='send_input', reload='yes', gm_action="pickbestrevision", itemid=item.id) + '''
     <center>
     
     <table border=0 cellspacing=5 cellpadding=0>
       <tr>
         <td valign="top">Please pick the best version of this comment:</td>
         <td valign="top">
           <table border=0 cellspacing=2 cellpadding=0>
   ''')
   for i, version in enumerate(item.versions):
     request.writeln('<tr>')
     request.writeln('<td><input type="radio" name="bestone" value="' + str(i) + '"></td>')
     request.writeln('<td>' + str(i+1) + '. ' + version + '</td>')
     request.writeln('</tr>')
   request.writeln('''
           </table>
         </td>
         <td valign="top"><input type="submit" value="Submit"></td>
       </tr>
     </table>
     </center>
     </form>
   ''')
   self.send_queue_info(request)
   if request.getvalue('reload', '') == 'yes': # this comes from send_editform below
     request.writeln("<script language='JavaScript' type='text/javascript'>parent.refreshEvents();</script>")
   request.writeln('</body></html>')
Ejemplo n.º 26
0
 def send_reviseform(self, request, itemid):
   '''Sends the revise comment form'''
   item = datagate.get_item(itemid)
   request.writeln(
     HTML_HEAD + self.BODY_TAG_NO_CLOSE + ''' topmargin="8">
     ''' + request.cgi_form(subview='send_input', reload='yes', gm_action="revise_comment", itemid=item.id) + '''
     <center>
     <table border=0 cellspacing=0 cellpadding=2>
       <tr>
         <td valign="top">Please revise this comment:</td>
         <td valign="top"><b>''' + item.text + '''</b>
         <td valign="top">&nbsp;</td>
       </tr><tr>
         <td valign="top">&nbsp;</td>
         <td valign="top"><textarea name="text" cols="70" rows="2"></textarea>
         <td valign="top"><input type="submit" value="Submit"></td>
       </tr>
     </table>
     </center>
     </form>
   ''')
   self.send_queue_info(request)
   if request.getvalue('reload', '') == 'yes': # this comes from send_editform below
     request.writeln("<script language='JavaScript' type='text/javascript'>parent.refreshEvents();</script>")
   request.writeln('</body></html>')
Ejemplo n.º 27
0
 def send_admin_page(self, request):
   '''Sends an administrator page for this view.'''
   activity = datagate.get_item(request.getvalue('itemid', ''))
   
   # send the rights
   request.writeln('<center>')
   self.send_admin_rights(request, activity)
   request.writeln('</center><p>&nbsp;<p>')
   
   # send the html      
   request.writeln(request.cgi_form(gm_action='CustomField.savechanges', title=None, fields=None) + '''
     <center>
     <b>View Title:</b>
     <input type=text size=40 name=title value="''' + activity.getvalue('title', '') + '''">
     <p>
     <b>Field Definitions:</b>
     <p>
     Provide one row per field.  Each row should be formatted as follows: <tt>type name</tt> (separated by spaces).
     <p>
     <textarea name="fields" cols=50 rows=15>''' + activity.getvalue('customfields', '') + '''</textarea>
     <p>
     <input type=submit value="Save">
     </form>
     <p>
     (Valid types are <tt>TEXT(rows,cols)</tt>, <tt>CHECKBOX</tt>, <tt>DATE</tt>, and <tt>SELECT(rows,id1,value1,id2,value2,...)</tt>)
     </center>
  ''')
Ejemplo n.º 28
0
  def send_initial_content(self, request):
    '''Sends the initial content frame to the browser'''
    root = datagate.get_item(request.getvalue('global_rootid', ''))
    item = root.search1(name="comments")

    request.writeln(HTML_HEAD + '<body bgcolor="#C3C191" id="outputBody" bottommargin="4" topmargin="4" leftmargin="4" rightmargin="4" onload="getEvents().refreshEvents()" style="background-image:url(/strikecom/blue-right.png); background-repeat: no-repeat;">')
    request.writeln('<div>&nbsp;</div>')
    request.writeln('</body></html>')
Ejemplo n.º 29
0
 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)
Ejemplo n.º 30
0
def get_group(global_meetingid, userid):
  '''Returns the group item the given user is in for the given meeting, or None if the user has no rights in the meeting'''
  meeting = datagate.get_item(global_meetingid)
  groups_item = meeting.search1(name='groups')
  for group in groups_item.get_child_items():
    if group.search1(user_id=userid) != None:
      return group
  return None