def occurrences_between(self, start, end): """ Returns all Occurrences with a start_date/time between two datetimes, sorted. This function is placed here because OccurrenceGenerators know the name of the Occurrence model, not currently vice-versa. However, we really want to hide this model, so lets make a convenience method in EventBaseManager. Get all OccurrenceGenerators that have the potential to produce occurrences between these dates. Run 'em all, and grab the ones that are in range. TODO - make this a queryset function too! """ start = datetimeify(start, "start") end = datetimeify(end, 'end') # relevant generators have # the first_start_date before the requested end date AND # the end date is NULL or after the requested start date potential_occurrence_generators = self.filter(first_start_date__lte=end) & (self.filter(repeat_until__isnull=True) | self.filter(repeat_until__gte=start)) occurrences = [] for generator in potential_occurrence_generators: occurrences += generator.get_occurrences(start, end) #In case you are pondering returning a queryset, remember that potentially occurrences are not in the database, so no such QS exists. return sorted(occurrences)
def get_occurrences(self, start, end, hide_hidden=True): """ returns a list of occurrences between the datetimes ``start`` and ``end``. Includes all of the exceptional Occurrences. """ start = datetimeify(start) end = datetimeify(end) exceptional_occurrences = self.occurrences.all() occ_replacer = OccurrenceReplacer(exceptional_occurrences) occurrences = self._get_occurrence_list(start, end) final_occurrences = [] for occ in occurrences: # replace occurrences with their exceptional counterparts if occ_replacer.has_occurrence(occ): p_occ = occ_replacer.get_occurrence(occ) # ...but only if they're not hidden and you want to see them if not (hide_hidden and p_occ.hide_from_lists): # ...but only if they are within this period if p_occ.start < end and p_occ.end >= start: final_occurrences.append(p_occ) else: final_occurrences.append(occ) # then add exceptional occurrences which originated outside of this period but now # fall within it final_occurrences += occ_replacer.get_additional_occurrences(start, end) return final_occurrences
def occurrences_between(self, start, end): """ Returns all Occurrences with a start_date/time between two datetimes, sorted. This function is placed here because OccurrenceGenerators know the name of the Occurrence model, not currently vice-versa. However, we really want to hide this model, so lets make a convenience method in EventBaseManager. Get all OccurrenceGenerators that have the potential to produce occurrences between these dates. Run 'em all, and grab the ones that are in range. TODO - make this a queryset function too! """ start = datetimeify(start, "start") end = datetimeify(end, 'end') # relevant generators have # the first_start_date before the requested end date AND # the end date is NULL or after the requested start date potential_occurrence_generators = self.filter( first_start_date__lte=end) & ( self.filter(repeat_until__isnull=True) | self.filter(repeat_until__gte=start)) occurrences = [] for generator in potential_occurrence_generators: occurrences += generator.get_occurrences(start, end) #In case you are pondering returning a queryset, remember that potentially occurrences are not in the database, so no such QS exists. return sorted(occurrences)
def get_occurrences(self, start, end, hide_hidden=True): """ returns a list of occurrences between the datetimes ``start`` and ``end``. Includes all of the exceptional Occurrences. """ start = datetimeify(start) end = datetimeify(end) exceptional_occurrences = self.occurrences.all() occ_replacer = OccurrenceReplacer(exceptional_occurrences) occurrences = self._get_occurrence_list(start, end) final_occurrences = [] for occ in occurrences: # replace occurrences with their exceptional counterparts if occ_replacer.has_occurrence(occ): p_occ = occ_replacer.get_occurrence(occ) # ...but only if they're not hidden and you want to see them if not (hide_hidden and p_occ.hide_from_lists): # ...but only if they are within this period if p_occ.start < end and p_occ.end >= start: final_occurrences.append(p_occ) else: final_occurrences.append(occ) # then add exceptional occurrences which originated outside of this period but now # fall within it final_occurrences += occ_replacer.get_additional_occurrences( start, end) return final_occurrences
def from_dupid(dupid): """Given the id of a duplicate bug, create and return a delta from the perspective of the original (duplicated) bug, reflecting the addition of a new duplicate. """ duppage = bs.BugPage(dupid) res = Delta() res.what = 'Duplicates' res.removed = None res.added = dupid res.date = utils.datify(duppage.att_resolved()) res.datetime = utils.datetimeify(duppage.att_resolved()) res.who = None return res
def from_html(cls, session, bugid, frag): vcard = frag.find("span", class_="bz_comment_user").span email = vcard.a["href"] assert email.startswith("mailto:") email = email[7:] name = vcard.a.span.string().strip() when = frag.find("span", class_="bz_comment_time").string().strip() when = utils.datetimeify(when) debugger = Debugger.get_or_create(session, name=name, email=email) comm = cls(bugid=bugid, when=when) comm.debugger = debugger return comm