Package mindmeister :: Module objects
[hide private]
[frames] | no frames]

Source Code for Module mindmeister.objects

  1  ''' 
  2  Copyright 2012 Alexey Kravets  <mr.kayrick@gmail.com> 
  3   
  4  This file is part of PythonMindmeister. 
  5   
  6  PythonMindmeister is free software: you can redistribute it and/or modify 
  7  it under the terms of the GNU General Public License as published by 
  8  the Free Software Foundation, either version 3 of the License, or 
  9  (at your option) any later version. 
 10   
 11  PythonMindmeister is distributed in the hope that it will be useful, 
 12  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 14  GNU General Public License for more details. 
 15   
 16  You should have received a copy of the GNU General Public License 
 17  along with PythonMindmeister.  If not, see <http://www.gnu.org/licenses/>. 
 18   
 19  This module represents entity classes, used within PythonMindmeister. 
 20   
 21  This product uses the MindMeister API but is not endorsed or certified 
 22  by MindMeister. 
 23  ''' 
 24   
 25   
 26  from lxml import etree 
 27  import dateutil.parser 
 28  import time 
 29   
30 -class Revision:
31 ''' 32 This class represents map revision. 33 '''
34 - def __init__(self, data):
35 ''' 36 Construct new revision from XML response. 37 Arguments: 38 data -- XML response. 39 Optional (keyword) Arguments: 40 ''' 41 self.__dict__.update (data.attrib)
42
43 - def __str__(self):
44 ''' 45 Convert object to string. 46 ''' 47 return "Revision: " + self.revision + " (" + self.created + ")"
48
49 -class Idea:
50 ''' 51 This class represents single map item (idea). 52 '''
53 - def __init__(self, data):
54 ''' 55 Construct new revision from XML response. 56 Arguments: 57 data -- XML response. 58 Optional (keyword) Arguments: 59 ''' 60 for field in data: 61 setattr (self, field.tag, field.text) 62 if hasattr (self, 'modifiedat'): 63 modifiedat = dateutil.parser.parse (self.modifiedat) 64 self.timestamp = int (time.mktime (modifiedat.timetuple())) 65 else: 66 self.timestamp = int (time.time ()) 67 self.ideas = [] 68 self.icons = [] 69 if hasattr (self, 'icon') and self.icon != None: 70 self.icons = self.icon.split(',') 71 self.icons.sort()
72 73
74 -class Map:
75 ''' 76 This class represents map header: 77 1. Title 78 2. Id 79 3. Creation date 80 4. Date of the last modification 81 82 See 83 http://www.mindmeister.com/developers/explore_method?method=mm.maps.getList 84 for more information. 85 '''
86 - def __init__(self, data):
87 ''' 88 Construct new map header from XML response. 89 Arguments: 90 data -- XML response. 91 Optional (keyword) Arguments: 92 ''' 93 self.__dict__.update (data.attrib)
94
95 -class FullMap:
96 ''' 97 This class represents map (as tree of Ideas). 98 99 See 100 http://www.mindmeister.com/developers/explore_method?method=mm.maps.getMap 101 for more information. 102 '''
103 - def __init__(self, data):
104 ''' 105 Construct new map from XML response. 106 Arguments: 107 data -- XML response. 108 Optional (keyword) Arguments: 109 ''' 110 self.map = None 111 self.ideas = [] 112 for item in data: 113 if item.tag == 'map': 114 self.map = Map (item) 115 elif item.tag == 'ideas': 116 ideas = map (lambda curr: Idea (curr), item) 117 mapping = {} 118 for idea in ideas: 119 if idea.parent: 120 parent = mapping[idea.parent] 121 else: 122 parent = self 123 idea.int_parent = parent 124 parent.ideas.append (idea) 125 mapping[idea.id] = idea
126
127 -class Folder:
128 ''' 129 This class represents folder: 130 1. Id 131 2. Parent id 132 3. Name 133 134 See 135 http://www.mindmeister.com/developers/explore_method?method=mm.folders.getList 136 for more information. 137 '''
138 - def __init__(self, data):
139 ''' 140 Construct new folder from XML response. 141 Arguments: 142 data -- XML response. 143 Optional (keyword) Arguments: 144 ''' 145 self.__dict__.update (data.attrib)
146