Пример #1
0
 def handle_delete(self, action, data):
     self.template_data = []
     if ISchedulingContext.providedBy(self.context):
         container = removeSecurityProxy(self.context.__parent__).sittings
     else:
         container = self.context.publishTraverse(self.request, "sittings")
     sitting = (container.get(get_real_id(data["ids"])) or
         container.get(get_real_id(self.request.form["event_pid"])))
     self.template_data = []
     if sitting is not None:
         self.request.form["headless"] = "true"
         delete_form = DeleteForm(sitting, self.request)
         delete_form.update()
         if not delete_form.errors:
             self.template_data.append({
                     "sitting_id": sitting.sitting_id, 
                     "action": "deleted",
                     "ids": data["ids"],
                 })
         else:
             return self.delete_sitting_failure_handler(action, data,
                 delete_form.errors
             )
     self.request.response.setHeader("Content-type", "text/xml")
     return self.xml_template()
Пример #2
0
 def handle_delete(self, action, data):
     self.template_data = []
     if ISchedulingContext.providedBy(self.context):
         container = removeSecurityProxy(self.context.__parent__).sittings
     else:
         container = self.context.publishTraverse(self.request, "sittings")
     sitting = (container.get(get_real_id(data["ids"])) or container.get(
         get_real_id(self.request.form["event_pid"])))
     self.template_data = []
     if sitting is not None:
         self.request.form["headless"] = "true"
         delete_form = DeleteForm(sitting, self.request)
         delete_form.update()
         if not delete_form.errors:
             self.template_data.append({
                 "sitting_id": sitting.sitting_id,
                 "action": "deleted",
                 "ids": data["ids"],
             })
         else:
             return self.delete_sitting_failure_handler(
                 action, data, delete_form.errors)
     self.request.response.setHeader("Content-type", "text/xml")
     return self.xml_template()
Пример #3
0
 def handle_update(self, action, data):
     session = Session()
     self.template_data = []
     venue_id = unicode(data["venue"]) if data['venue'] else None
     data["rec_end_date"] = data["end_date"]
     data["headless"] = 'true'
     self.request.form["venue_id"] = data["venue_id"] = venue_id
     self.request.form["headless"] = "true"
     if ("rec_type" in data.keys()) and (data["rec_type"] is not None):
         # updating recurring events - we assume existing events fall
         # at the beginning of the sequence and offer in place update.
         parent_sitting_id = get_real_id(data["ids"] or data["event_pid"])
         length = data["event_length"]
         sitting_length = timedelta(seconds=length)
         base_sitting_length = sitting_length + timedelta(hours=1)
         siblings_filter = or_(
             domain.Sitting.recurring_id==parent_sitting_id,
             domain.Sitting.sitting_id==parent_sitting_id
         )
         siblings = [ sitting for sitting in
             self.sittings_container.batch(order_by=(domain.Sitting.sitting_id),
                 limit=None, filter=siblings_filter
             )
         ] 
         dates = self.generate_dates(data)
         current_count = len(siblings)
         for count, date in enumerate(dates):
             is_new = not count < current_count
             sitting_data = copy(data)
             sitting_data["start_date"] = date.strftime(DT_FORMAT)
             sitting_data["end_date"] = (date + sitting_length).strftime(DT_FORMAT)
             request_copy = copy(self.request)
             request_copy.form = sitting_data
             if is_new:
                 add_form = AddForm(self.sittings_container, request_copy)
                 add_form.update()
                 if add_form.errors:
                     log.error("Could not add sitting in sequence: %s",
                         sitting_data
                     )
                     continue
                 else:
                     sitting = add_form.created_object
                     sitting.recurring_id = parent_sitting_id
             else:
                 sitting = siblings[count]
             if not count:
                 sitting.recurring_end_date = dates[len(dates)-1] + base_sitting_length
                 sitting.recurring_type = data.get("rec_type")
                 sitting.recurring_id = 0
                 sitting.sitting_length = length
             else:
                 sitting.sitting_length = int(time.mktime(date.timetuple()))
                 sitting.recurring_type = None
             if not is_new:
                 edit_form = EditForm(sitting, request_copy)
                 edit_form.update()
                 if edit_form.errors:
                     continue
                 else:
                     session.merge(edit_form.context)
             else:
                 session.merge(sitting)
             self.template_data.append({
                     "sitting_id": sitting.sitting_id, 
                     "action": (is_new and "inserted" or "updated"),
                     "ids": create_id(sitting)
             })
         #delete any sittings outside recurring bounds
         for del_sibling in siblings[len(dates):]:
             delete_form = DeleteForm(del_sibling, self.request)
             delete_form.update()
             if delete_form.errors:
                 continue
             else:
                 self.template_data.append({
                     "sitting_id": del_sibling.sitting_id,
                     "action": "deleted",
                     "ids": create_id(del_sibling)
                 })
     else:
         sitting_id = get_real_id(data["ids"])
         parent_id = get_real_id(data["event_pid"])
         sitting = self.sittings_container.get(sitting_id)
         if sitting is None:
             sitting = self.sittings_container.get(int(parent_id))
         edit_form = EditForm(sitting, self.request)
         edit_form.update()
         if edit_form.errors:
             return self.update_sitting_failure_handler(action, data,
                 edit_form.errors
             )
         else:
             sitting.sitting_length = data.get("event_length")
             session.merge(sitting)
             self.template_data.append({
                     "sitting_id": sitting.sitting_id, 
                     "action": "updated",
                     "ids": data["ids"],
                 })
     self.request.response.setHeader("Content-type", "text/xml")
     return self.xml_template()
Пример #4
0
 def handle_update(self, action, data):
     session = Session()
     self.template_data = []
     venue_id = unicode(data["venue"]) if data['venue'] else None
     data["rec_end_date"] = data["end_date"]
     data["headless"] = 'true'
     self.request.form["venue_id"] = data["venue_id"] = venue_id
     self.request.form["headless"] = "true"
     if ("rec_type" in data.keys()) and (data["rec_type"] is not None):
         # updating recurring events - we assume existing events fall
         # at the beginning of the sequence and offer in place update.
         parent_sitting_id = get_real_id(data["ids"] or data["event_pid"])
         length = data["event_length"]
         sitting_length = timedelta(seconds=length)
         base_sitting_length = sitting_length + timedelta(hours=1)
         siblings_filter = or_(
             domain.Sitting.recurring_id == parent_sitting_id,
             domain.Sitting.sitting_id == parent_sitting_id)
         siblings = [
             sitting for sitting in self.sittings_container.batch(
                 order_by=(domain.Sitting.sitting_id),
                 limit=None,
                 filter=siblings_filter)
         ]
         dates = self.generate_dates(data)
         current_count = len(siblings)
         for count, date in enumerate(dates):
             is_new = not count < current_count
             sitting_data = copy(data)
             sitting_data["start_date"] = date.strftime(DT_FORMAT)
             sitting_data["end_date"] = (date +
                                         sitting_length).strftime(DT_FORMAT)
             request_copy = copy(self.request)
             request_copy.form = sitting_data
             if is_new:
                 add_form = AddForm(self.sittings_container, request_copy)
                 add_form.update()
                 if add_form.errors:
                     log.error("Could not add sitting in sequence: %s",
                               sitting_data)
                     continue
                 else:
                     sitting = add_form.created_object
                     sitting.recurring_id = parent_sitting_id
             else:
                 sitting = siblings[count]
             if not count:
                 sitting.recurring_end_date = dates[len(dates) -
                                                    1] + base_sitting_length
                 sitting.recurring_type = data.get("rec_type")
                 sitting.recurring_id = 0
                 sitting.sitting_length = length
             else:
                 sitting.sitting_length = int(time.mktime(date.timetuple()))
                 sitting.recurring_type = None
             if not is_new:
                 edit_form = EditForm(sitting, request_copy)
                 edit_form.update()
                 if edit_form.errors:
                     continue
                 else:
                     session.merge(edit_form.context)
             else:
                 session.merge(sitting)
             self.template_data.append({
                 "sitting_id":
                 sitting.sitting_id,
                 "action": (is_new and "inserted" or "updated"),
                 "ids":
                 create_id(sitting)
             })
         #delete any sittings outside recurring bounds
         for del_sibling in siblings[len(dates):]:
             delete_form = DeleteForm(del_sibling, self.request)
             delete_form.update()
             if delete_form.errors:
                 continue
             else:
                 self.template_data.append({
                     "sitting_id": del_sibling.sitting_id,
                     "action": "deleted",
                     "ids": create_id(del_sibling)
                 })
     else:
         sitting_id = get_real_id(data["ids"])
         parent_id = get_real_id(data["event_pid"])
         sitting = self.sittings_container.get(sitting_id)
         if sitting is None:
             sitting = self.sittings_container.get(int(parent_id))
         edit_form = EditForm(sitting, self.request)
         edit_form.update()
         if edit_form.errors:
             return self.update_sitting_failure_handler(
                 action, data, edit_form.errors)
         else:
             sitting.sitting_length = data.get("event_length")
             session.merge(sitting)
             self.template_data.append({
                 "sitting_id": sitting.sitting_id,
                 "action": "updated",
                 "ids": data["ids"],
             })
     self.request.response.setHeader("Content-type", "text/xml")
     return self.xml_template()