Beispiel #1
0
 def _create_container_wrapper(self, id_):
     immutable_container = self._immutable_db.containers.get(id_)
     wrapper = Container(
         db=self._db,
         id_=id_,
         immutable_value=immutable_container,
     )
     wrapper.category = self._get_maybe_category(
         immutable_container.category_id)
     return wrapper
Beispiel #2
0
 def _parse_event(self, text, tmp_dict):
     start = self._parse_time(tmp_dict.pop("tmp_start"))
     end = self._parse_time(tmp_dict.pop("tmp_end"))
     text = tmp_dict.pop("tmp_text")
     progress = self._parse_optional_int(tmp_dict, "tmp_progress")
     fuzzy = self._parse_optional_bool(tmp_dict, "tmp_fuzzy")
     locked = self._parse_optional_bool(tmp_dict, "tmp_locked")
     ends_today = self._parse_optional_bool(tmp_dict, "tmp_ends_today")
     category_text = tmp_dict.pop("tmp_category", None)
     if category_text is None:
         category = None
     else:
         category = tmp_dict["category_map"].get(category_text, None)
         if category is None:
             raise ParseException("Category '%s' not found." %
                                  category_text)
     description = tmp_dict.pop("tmp_description", None)
     alert_string = tmp_dict.pop("tmp_alert", None)
     alert = parse_alert_string(self.db.get_time_type(), alert_string)
     icon_text = tmp_dict.pop("tmp_icon", None)
     if icon_text is None:
         icon = None
     else:
         icon = parse_icon(icon_text)
     hyperlink = tmp_dict.pop("tmp_hyperlink", None)
     milestone = self._parse_optional_bool(tmp_dict, "tmp_milestone")
     if self._is_container_event(text):
         cid, text = self._extract_container_id(text)
         event = Container().update(start, end, text, category)
         self._containers_by_cid[cid] = event
     elif self._is_subevent(text):
         cid, text = self._extract_subid(text)
         event = Subevent().update(start,
                                   end,
                                   text,
                                   category,
                                   locked=locked,
                                   ends_today=ends_today)
         event.container = self._containers_by_cid[cid]
     elif milestone:
         event = Milestone().update(start, start, text)
         event.set_category(category)
     else:
         if self._text_starts_with_added_space(text):
             text = self._remove_added_space(text)
         event = Event().update(start, end, text, category, fuzzy, locked,
                                ends_today)
     default_color = tmp_dict.pop("tmp_default_color", "200,200,200")
     event.set_data("description", description)
     event.set_data("icon", icon)
     event.set_data("alert", alert)
     event.set_data("hyperlink", hyperlink)
     event.set_data("progress", int(progress))
     event.set_data("default_color", parse_color(default_color))
     self.db.save_event(event)
Beispiel #3
0
def a_container(name, category, sub_events):
    """Create a :doc:`Container <timelinelib_canvas_data_container>` object."""
    start = human_time_to_gregorian(ANY_TIME)
    end = human_time_to_gregorian(ANY_TIME)
    container = Container().update(start, end, name, category=category)
    all_events = []
    all_events.append(container)
    for (name, category) in sub_events:
        event = Subevent().update(start, end, name, category=category)
        event.container = container
        all_events.append(event)
    return all_events
Beispiel #4
0
 def _create_container_wrapper(self, id_):
     immutable_container = self._immutable_db.containers.get(id_)
     wrapper = Container(
         db=self._db,
         id_=id_,
         immutable_value=immutable_container,
     )
     wrapper.category = self._get_maybe_category(
         immutable_container.category_id)
     lst = []
     for key in immutable_container.category_ids:
         lst.append(self._get_maybe_category(key))
     wrapper.set_categories(lst)
     return wrapper
Beispiel #5
0
def a_container_with(text="container", category=None):
    """Create a :doc:`Container <timelinelib_canvas_data_container>` object."""
    start = human_time_to_gregorian(ANY_TIME)
    end = human_time_to_gregorian(ANY_TIME)
    container = Container().update(start, end, text, category=category)
    return container
Beispiel #6
0
 def _parse_event(self, text, tmp_dict):
     start = self._parse_time(tmp_dict.pop("tmp_start"))
     end = self._parse_time(tmp_dict.pop("tmp_end"))
     text = tmp_dict.pop("tmp_text")
     progress = self._parse_optional_int(tmp_dict, "tmp_progress")
     fuzzy = self._parse_optional_bool(tmp_dict, "tmp_fuzzy")
     locked = self._parse_optional_bool(tmp_dict, "tmp_locked")
     ends_today = self._parse_optional_bool(tmp_dict, "tmp_ends_today")
     category_text = tmp_dict.pop("tmp_category", None)
     if category_text is None:
         category = None
     else:
         category = self.get_category(tmp_dict, category_text)
     categories = []
     if "tmp_categories" in tmp_dict:
         # Remove duplicates but preserve order
         dic = {k: 0 for k in tmp_dict.pop("tmp_categories", None)}
         for category_text in dic:
             if category_text is not None:
                 cat = self.get_category(tmp_dict, category_text)
                 if category is None:
                     category = cat
                 else:
                     categories.append(cat)
     description = tmp_dict.pop("tmp_description", None)
     alert_string = tmp_dict.pop("tmp_alert", None)
     alert = parse_alert_string(self.db.get_time_type(), alert_string)
     icon_text = tmp_dict.pop("tmp_icon", None)
     if icon_text is None:
         icon = None
     else:
         icon = parse_icon(icon_text)
     hyperlink = tmp_dict.pop("tmp_hyperlink", None)
     milestone = self._parse_optional_bool(tmp_dict, "tmp_milestone")
     if self._is_container_event(text):
         cid, text = self._extract_container_id(text)
         event = Container().update(start, end, text, category)
         self._containers_by_cid[cid] = event
     elif self._is_subevent(text):
         cid, text = self._extract_subid(text)
         event = Subevent().update(start,
                                   end,
                                   text,
                                   category,
                                   locked=locked,
                                   ends_today=ends_today)
         event.container = self._containers_by_cid[cid]
     elif milestone:
         event = Milestone().update(start, start, text)
         event.set_category(category)
     else:
         if self._text_starts_with_added_space(text):
             text = self._remove_added_space(text)
         event = Event().update(start, end, text, category, fuzzy, locked,
                                ends_today)
     if categories:
         event.set_categories(categories)
     default_color = tmp_dict.pop("tmp_default_color", "200,200,200")
     event.set_data("description", description)
     event.set_data("icon", icon)
     event.set_data("alert", alert)
     event.set_data("hyperlink", hyperlink)
     event.set_data("progress", int(progress))
     event.set_data("default_color", parse_color(default_color))
     self.db.save_event(event)