def assetimporter_action(self, request): game = datagate.get_item(request.getvalue('itemid')) turns = game.search1(name='turns') target = turns.get_child(turns.childids[0]).search1(name='assetmoves') asset_library = request.form['_assetlibrary'] if asset_library.filename == '': return gz = gzip.GzipFile(asset_library.filename, 'r', fileobj=asset_library.file) doc = xml.dom.minidom.parse(gz) items = datagate.import_xml(doc.getElementsByTagName("GroupMind")[0]) for item in items: item.creatorid = request.session.user.id target.insert_child(item) item.save() target.save()
def importfile_action(self,request): importfile = request.form['filepath'] request.writeln(''' Import file: ''' + str(importfile) + ''' /n''') gz = gzip.GzipFile(importfile.filename, 'r', fileobj=importfile.file) doc = xml.dom.minidom.parse(gz) meetingnode = None usersnode = None for child in doc.documentElement.childNodes: if child.nodeName == 'MeetingData': meetingnode = child elif child.nodeName == 'UserData': usersnode = child assert meetingnode != usersnode != None, 'Error importing data.' data = datagate.import_xml(meetingnode) data.parentid = '' data.rewrite_ids() data.save(deep=1) item = datagate.get_item(request.getvalue('rootid', '')) item.insert_child(data) item.save()
def import_meeting(doc, creatorid): '''Creates a meeting by importing an exported xml document. The document should be created before this method is called.''' # get the meetingdata and userdata nodes meetingnode = None usersnode = None old_root_guid='' for child in doc.documentElement.childNodes: if child.nodeName == 'MeetingData': meetingnode = child elif child.nodeName == 'UserData': usersnode = child assert meetingnode != usersnode != None, 'Error importing meeting. Cannot find the meeting and/or users nodes.' # import the meeting subtree and add to the meetings list meeting = datagate.import_xml(meetingnode) meeting.parentid = '' meeting.rewrite_ids() meeting.save(deep=1) meetings_item.insert_child(meeting) meetings_item.save() # importing is a little more complex than copying a meeting because # the import might come from a different machine. Since it does, some users # may not be available on this machine. We have to recreate these users here. # step through the nodes and compile a list of users who created objects but are # not in this system # import the users into a set of items #PROBLEM: What happens when the users are assigned to a strikeCom team? That we can fix, but now we have 2 superusers, both named root. users = datagate.import_xml(usersnode) for user in users: if user.username=='root': old_root_guid = user.id def check_for_lost_users(item): # check for this user sc_user_id='' try: sc_user_id = item.user_id # check to see if the item is a strikecom team member except AttributeError: pass if users_item.get_child(item.creatorid) == None: # creator is not in the current users list importeduser = users.get_child(item.creatorid) if importeduser != None and importeduser.username!='root': importeduser.creatorid = creatorid users_item.insert_child(importeduser) importeduser.save() users_item.save() if users_item.get_child(sc_user_id) == None and sc_user_id != '': # the strikecom member user_id is not in the current users list importeduser = users.search1(id=sc_user_id) if importeduser != None and importeduser.username!='root': # check for root here also incase he has been assigned to a team importeduser.creatorid = creatorid users_item.insert_child(importeduser) importeduser.save() users_item.save() # recurse to children for child in item.get_child_items(): check_for_lost_users(child) check_for_lost_users(meeting) meeting.get_parent().replace_root_ids(old_root_guid, creatorid) #start from the root item and replace all meeting.get_parent().save(deep=1) # return a reference to the new meeting return meeting