def generate_dates(self, data): trusted = removeSecurityProxy(ISchedulingContext(self.context)) recurrence_start_date = data["start_date"].replace(tzinfo=None) recurrence_end_date = data["end_date"].replace(tzinfo=None) group = trusted.get_group() # If group is none then there is a big problem assert group is not None year = timedelta(days=365) now = datetime.datetime.now() if ((group.end_date is not None) and ((now + year) < group.end_date)) or (group.end_date is None): end = now + year else: end = group.end_date if recurrence_end_date > end: recurrence_end_date = end return utils.generate_recurrence_dates(recurrence_start_date, recurrence_end_date, data["rec_type"])
def generate_dates(self, data): trusted = removeSecurityProxy(ISchedulingContext(self.context)) recurrence_start_date = data["start_date"].replace(tzinfo=None) recurrence_end_date = data["rec_end_date"].replace(tzinfo=None) group = trusted.get_group() # If group is none then there is a big problem assert group is not None year = timedelta(days=365) now = datetime.datetime.now() if (((group.end_date is not None) and ((now + year) < group.end_date)) or (group.end_date is None)): end = now + year else: end = group.end_date if recurrence_end_date > end: recurrence_end_date = end return utils.generate_recurrence_dates(recurrence_start_date, recurrence_end_date, data["rec_type"])
def handle_insert(self, action, data): session = Session() self.template_data = [] trusted = removeSecurityProxy(ISchedulingContext(self.context)) if ("rec_type" in data.keys()) and (data["rec_type"] is not None): # !+ DATETIME(miano, dec-2010) the datetime widget above returns # aware datetime objects while the current database setup only # supports naive objects. The lines below(and in subsequent actions) # convert them to naive datetimes recurrence_start_date = data["start_date"].replace(tzinfo=None) recurrence_end_date = data["end_date"].replace(tzinfo=None) length = data["event_length"] sitting_length = timedelta(seconds=int(length)) # # Check the end date of the recurrence # The end date is set to be the end date of the current group # or one year from the present date whichever is sooner. group = trusted.get_group() # If group is none then there is a big problem assert group is not None year = timedelta(days=365) now = datetime.datetime.now() if ((group.end_date is not None) and ((now + year) < group.end_date)) or (group.end_date is None): end = now + year else: end = group.end_date if recurrence_end_date > end: recurrence_end_date = end dates = utils.generate_recurrence_dates(recurrence_start_date, recurrence_end_date, data["rec_type"]) recurrent_sittings = [] for date in dates: sitting = domain.GroupSitting() sitting.group_id = trusted.group_id sitting.start_date = date sitting.end_date = date + sitting_length sitting.language = data["language"] sitting.venue_id = data["venue"] session.add(sitting) recurrent_sittings.append(sitting) session.flush() for s in recurrent_sittings: notify(ObjectCreatedEvent(s)) self.template_data.append({"group_sitting_id": s.group_sitting_id, "action": "inserted", "ids": data["ids"]}) self.request.response.setHeader('Content-type', 'text/xml') return self.xml_template() else: sitting = domain.GroupSitting() sitting.start_date = data["start_date"].replace(tzinfo=None) sitting.end_date = data["end_date"].replace(tzinfo=None) sitting.group_id = trusted.group_id sitting.language = data["language"] sitting.venue_id = data["venue"] session.add(sitting) session.flush() notify(ObjectCreatedEvent(sitting)) self.template_data.append({"group_sitting_id": sitting.group_sitting_id, "action": "inserted", "ids": data["ids"]}) self.request.response.setHeader('Content-type', 'text/xml') return self.xml_template()
def handle_insert(self, action, data): session = Session() self.template_data = [] trusted = removeSecurityProxy(ISchedulingContext(self.context)) if ("rec_type" in data.keys()) and (data["rec_type"] is not None): # !+ DATETIME(miano, dec-2010) the datetime widget above returns # aware datetime objects while the current database setup only # supports naive objects. The lines below(and in subsequent actions) # convert them to naive datetimes recurrence_start_date = data["start_date"].replace(tzinfo=None) recurrence_end_date = data["end_date"].replace(tzinfo=None) length = data["event_length"] sitting_length = timedelta(seconds=int(length)) # # Check the end date of the recurrence # The end date is set to be the end date of the current group # or one year from the present date whichever is sooner. group = trusted.get_group() # If group is none then there is a big problem assert group is not None year = timedelta(days=365) now = datetime.datetime.now() if ((group.end_date is not None) and ((now + year) < group.end_date)) or (group.end_date is None): end = now + year else: end = group.end_date if recurrence_end_date > end: recurrence_end_date = end dates = utils.generate_recurrence_dates(recurrence_start_date, recurrence_end_date, data["rec_type"]) recurrent_sittings = [] for date in dates: sitting = domain.GroupSitting() sitting.group_id = trusted.group_id sitting.start_date = date sitting.end_date = date + sitting_length sitting.language = data["language"] sitting.venue_id = data["venue"] session.add(sitting) recurrent_sittings.append(sitting) session.flush() for s in recurrent_sittings: notify(ObjectCreatedEvent(s)) self.template_data.append({ "group_sitting_id": s.group_sitting_id, "action": "inserted", "ids": data["ids"] }) self.request.response.setHeader('Content-type', 'text/xml') return self.xml_template() else: sitting = domain.GroupSitting() sitting.start_date = data["start_date"].replace(tzinfo=None) sitting.end_date = data["end_date"].replace(tzinfo=None) sitting.group_id = trusted.group_id sitting.language = data["language"] sitting.venue_id = data["venue"] session.add(sitting) session.flush() notify(ObjectCreatedEvent(sitting)) self.template_data.append({ "group_sitting_id": sitting.group_sitting_id, "action": "inserted", "ids": data["ids"] }) self.request.response.setHeader('Content-type', 'text/xml') return self.xml_template()
def handle_insert(self, action, data): self.template_data = [] session = Session() trusted = removeSecurityProxy(ISchedulingContext(self.context)) if ("rec_type" in data.keys()) and (data["rec_type"] is not None): try: recurrence_start_date = datetime.datetime \ .strptime(data["start_date"], '%Y-%m-%d %H:%M') except: log.error("The start date of the recurrence \ is not in the correct format") try: recurrence_end_date = datetime.datetime.strptime( data["end_date"], '%Y-%m-%d %H:%M') except: log.error("The start date of the recurrence is not in \ the correct format") length = data["event_length"] sitting_length = timedelta(seconds=int(length)) # Check the end date of the recurrence # The end date is set to be the end date of the current group # or one year from the present date whichever is sooner. group = trusted.get_group() # If group is none then there is a big problem assert group is not None year = timedelta(days=365) now = datetime.datetime.now() if ((group.end_date is not None) and ((now + year) < group.end_date)) or (group.end_date is None): end = now + year else: end = group.end_date if recurrence_end_date > end: recurrence_end_date = end dates = utils.generate_recurrence_dates(recurrence_start_date, recurrence_end_date, data["rec_type"]) for date in dates: sitting = domain.GroupSitting() sitting.group_id = trusted.group_id sitting.start_date = date sitting.end_date = date + sitting_length sitting.status = None if "language" in data.keys(): sitting.language = data["language"] if "venue" in data.keys(): sitting.venue_id = data["venue"] # set extra data needed by template sitting.ids = data["ids"] sitting.action = 'inserted' session.add(sitting) # commiting after adding a sitting is incredibly inefficient # but thats the only way to get the sitting id. # Adding recurrring sittings is not a recurrent activity (see, # what I did there :)) so we can live with it. session.commit(sitting) notify(ObjectCreatedEvent(sitting)) self.template_data.append({"sitting_id": sitting.sitting_id, "action": "inserted", "ids": data["ids"]}) self.request.response.setHeader('Content-type', 'text/xml') return self.template() else: sitting = domain.GroupSitting() try: sitting.start_date = datetime.datetime.strptime( data["start_date"], '%Y-%m-%d %H:%M') except: log.error("The start date of the sitting \ is not in the correct format") try: sitting.end_date = datetime.datetime.strptime(data["end_date"], '%Y-%m-%d %H:%M') except: log.error("The end date of the sitting is not in the correct format") sitting.group_id = trusted.group_id if "language" in data.keys(): sitting.language = data["language"] if "venue" in data.keys(): sitting.venue_id = data["venue"] # set extra data needed by template sitting.ids = data["ids"] sitting.action = 'inserted' session.add(sitting) session.commit() notify(ObjectCreatedEvent(sitting)) self.template_data.append({"sitting_id": sitting.sitting_id, "action": "inserted", "ids": data["ids"]}) self.request.response.setHeader('Content-type', 'text/xml') return self.template()