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 category_ids = Field(ImmutableDict()) 31 fuzzy = Field(False) 32 locked = Field(False) 33 ends_today = Field(False) 34 description = Field(None) 35 icon = Field(None) 36 hyperlink = Field(None) 37 alert = Field(None) 38 progress = Field(None) 39 default_color = Field(None) 40 container_id = Field(None) 41 sort_order = Field(None)42 4345 46 text = Field(None) 47 category_id = Field(None) 48 category_ids = Field(ImmutableDict()) 49 time_period = Field(None) 50 description = Field(None) 51 default_color = Field((255, 255, 128)) 52 sort_order = Field(None)53 5456 57 name = Field(None) 58 time_period = Field(None) 59 color = Field((200, 200, 200)) 60 ends_today = Field(False)61 6264 65 name = Field("") 66 color = Field((255, 0, 0)) 67 progress_color = Field(get_progress_color((255, 0, 0))) 68 done_color = Field(get_progress_color((255, 0, 0))) 69 font_color = Field((0, 0, 0)) 70 parent_id = Field(None)71 7274 75 text = Field(None) 76 category_id = Field(None) 77 category_ids = Field(ImmutableDict()) 78 time_period = Field(None) 79 description = Field(None)80 8183 84 categories = Field(ImmutableDict()) 85 containers = Field(ImmutableDict()) 86 events = Field(ImmutableDict()) 87 milestones = Field(ImmutableDict()) 88 eras = Field(ImmutableDict()) 89155 return self.update( 156 categories=self.categories.remove(delete_id).map(update_parent_id), 157 events=self.events.map(update_category_id), 158 milestones=self.milestones.map(update_category_id), 159 containers=self.containers.map(update_category_id) 160 ) 16191 self._ensure_non_none_category_exists(event.category_id) 92 self._ensure_non_none_container_exists(event.container_id) 93 return self.update( 94 events=self.events.update({ 95 id_: event, 96 }) 97 )98 104106 self._ensure_non_none_category_exists(milestone.category_id) 107 return self.update( 108 milestones=self.milestones.update({ 109 id_: milestone 110 }) 111 )112114 self._ensure_milestone_exists(id_) 115 return self.update( 116 milestones=self.milestones.remove(id_) 117 )118 125 131133 self._ensure_category_name_is_unique(id_, category.name) 134 self._ensure_non_none_category_exists(category.parent_id) 135 self._ensure_no_category_circular(id_, category.parent_id) 136 return self.update( 137 categories=self.categories.update({id_: category}) 138 )139141 self._ensure_category_exists(delete_id) 142 new_parent_id = self.categories.get(delete_id).parent_id 143 144 def update_parent_id(category): 145 if category.parent_id == delete_id: 146 return category.update(parent_id=new_parent_id) 147 else: 148 return category149 150 def update_category_id(thing): 151 if thing.category_id == delete_id: 152 return thing.update(category_id=new_parent_id) 153 else: 154 return thing163 self._ensure_non_none_category_exists(container.category_id) 164 return self.update( 165 containers=self.containers.update({id_: container}) 166 )167169 self._ensure_container_exists(delete_id) 170 171 def update_container_id(event): 172 if event.container_id == delete_id: 173 return event.update(container_id=None) 174 else: 175 return event176 return self.update( 177 containers=self.containers.remove(delete_id), 178 events=self.events.map(update_container_id), 179 ) 180182 if id_ not in self.events: 183 raise InvalidOperationError( 184 "Event with id {0!r} does not exist".format(id_) 185 )186188 if id_ not in self.milestones: 189 raise InvalidOperationError( 190 "Milestone with id {0!r} does not exist".format(id_) 191 )192194 if id_ not in self.eras: 195 raise InvalidOperationError( 196 "Era with id {0!r} does not exist".format(id_) 197 )198200 for id_, category in self.categories: 201 if id_ != save_id and category.name == save_name: 202 raise InvalidOperationError( 203 "Category name {0!r} is not unique".format(save_name) 204 )205 209211 if id_ not in self.categories: 212 raise InvalidOperationError( 213 "Category with id {0!r} does not exist".format(id_) 214 )215217 while parent_id is not None: 218 if parent_id == save_id: 219 raise InvalidOperationError( 220 "Circular category parent" 221 ) 222 else: 223 parent_id = self.categories.get(parent_id).parent_id224 228230 if id_ not in self.containers: 231 raise InvalidOperationError( 232 "Container with id {0!r} does not exist".format(id_) 233 )234 235 238
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Wed Mar 25 02:55:27 2020 | http://epydoc.sourceforge.net |