Home | Trees | Indices | Help |
|
---|
|
1 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Rickard Lindberg, Roger Lindberg 2 # 3 # This file is part of Timeline. 4 # 5 # Timeline is free software: you can redistribute it and/or modify 6 # it under the terms of the GNU General Public License as published by 7 # the Free Software Foundation, either version 3 of the License, or 8 # (at your option) any later version. 9 # 10 # Timeline is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with Timeline. If not, see <http://www.gnu.org/licenses/>. 17 18 19 from timelinelib.canvas.drawing.drawers import get_progress_color 20 from timelinelib.general.immutable import Field 21 from timelinelib.general.immutable import ImmutableDict 22 from timelinelib.general.immutable import ImmutableRecord 23 2426 27 text = Field(None) 28 time_period = Field(None) 29 category_id = Field(None) 30 fuzzy = Field(False) 31 locked = Field(False) 32 ends_today = Field(False) 33 description = Field(None) 34 icon = Field(None) 35 hyperlink = Field(None) 36 alert = Field(None) 37 progress = Field(None) 38 default_color = Field(None) 39 container_id = Field(None) 40 sort_order = Field(None)41 4244 45 text = Field(None) 46 category_id = Field(None) 47 time_period = Field(None) 48 description = Field(None) 49 default_color = Field((255, 255, 128)) 50 sort_order = Field(None)51 5254 55 name = Field(None) 56 time_period = Field(None) 57 color = Field((200, 200, 200)) 58 ends_today = Field(False)59 6062 63 name = Field("") 64 color = Field((255, 0, 0)) 65 progress_color = Field(get_progress_color((255, 0, 0))) 66 done_color = Field(get_progress_color((255, 0, 0))) 67 font_color = Field((0, 0, 0)) 68 parent_id = Field(None)69 7072 73 text = Field(None) 74 category_id = Field(None) 75 time_period = Field(None) 76 description = Field(None)77 7880 81 categories = Field(ImmutableDict()) 82 containers = Field(ImmutableDict()) 83 events = Field(ImmutableDict()) 84 milestones = Field(ImmutableDict()) 85 eras = Field(ImmutableDict()) 86152 return self.update( 153 categories=self.categories.remove(delete_id).map(update_parent_id), 154 events=self.events.map(update_category_id), 155 milestones=self.milestones.map(update_category_id), 156 containers=self.containers.map(update_category_id) 157 ) 15888 self._ensure_non_none_category_exists(event.category_id) 89 self._ensure_non_none_container_exists(event.container_id) 90 return self.update( 91 events=self.events.update({ 92 id_: event, 93 }) 94 )95 101103 self._ensure_non_none_category_exists(milestone.category_id) 104 return self.update( 105 milestones=self.milestones.update({ 106 id_: milestone 107 }) 108 )109111 self._ensure_milestone_exists(id_) 112 return self.update( 113 milestones=self.milestones.remove(id_) 114 )115 122 128130 self._ensure_category_name_is_unique(id_, category.name) 131 self._ensure_non_none_category_exists(category.parent_id) 132 self._ensure_no_category_circular(id_, category.parent_id) 133 return self.update( 134 categories=self.categories.update({id_: category}) 135 )136138 self._ensure_category_exists(delete_id) 139 new_parent_id = self.categories.get(delete_id).parent_id 140 141 def update_parent_id(category): 142 if category.parent_id == delete_id: 143 return category.update(parent_id=new_parent_id) 144 else: 145 return category146 147 def update_category_id(thing): 148 if thing.category_id == delete_id: 149 return thing.update(category_id=new_parent_id) 150 else: 151 return thing160 self._ensure_non_none_category_exists(container.category_id) 161 return self.update( 162 containers=self.containers.update({id_: container}) 163 )164166 self._ensure_container_exists(delete_id) 167 168 def update_container_id(event): 169 if event.container_id == delete_id: 170 return event.update(container_id=None) 171 else: 172 return event173 return self.update( 174 containers=self.containers.remove(delete_id), 175 events=self.events.map(update_container_id), 176 ) 177179 if id_ not in self.events: 180 raise InvalidOperationError( 181 "Event with id {0!r} does not exist".format(id_) 182 )183185 if id_ not in self.milestones: 186 raise InvalidOperationError( 187 "Milestone with id {0!r} does not exist".format(id_) 188 )189191 if id_ not in self.eras: 192 raise InvalidOperationError( 193 "Era with id {0!r} does not exist".format(id_) 194 )195197 for id_, category in self.categories: 198 if id_ != save_id and category.name == save_name: 199 raise InvalidOperationError( 200 "Category name {0!r} is not unique".format(save_name) 201 )202 206208 if id_ not in self.categories: 209 raise InvalidOperationError( 210 "Category with id {0!r} does not exist".format(id_) 211 )212214 while parent_id is not None: 215 if parent_id == save_id: 216 raise InvalidOperationError( 217 "Circular category parent" 218 ) 219 else: 220 parent_id = self.categories.get(parent_id).parent_id221 225227 if id_ not in self.containers: 228 raise InvalidOperationError( 229 "Container with id {0!r} does not exist".format(id_) 230 )231 232 235
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Wed Dec 19 02:55:28 2018 | http://epydoc.sourceforge.net |