Ejemplo n.º 1
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()
Ejemplo n.º 2
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()
Ejemplo n.º 3
0
 def handle_insert(self, action, data):
     session = Session()
     data["rec_end_date"] = data["end_date"]
     self.template_data = []
     initial_sitting = None
     length = data["event_length"]
     venue_id = unicode(data["venue"]) if data['venue'] else None
     if data.get("rec_type") not in [None, "none"]:
         data["end_date"] = data["start_date"] + timedelta(seconds=length)
         self.request.form["end_date"] = data["end_date"].strftime(DT_FORMAT)
     data["headless"] = "true"
     self.request.form["venue_id"] = data["venue_id"] = venue_id
     self.request.form["headless"] = "true"
     add_form = AddForm(self.sittings_container, self.request)
     add_form.update()
     if not add_form.errors:
         initial_sitting = removeSecurityProxy(add_form.created_object)
     else:
         return self.insert_sitting_failure_handler(action, data,
             add_form.errors
         )
     if ("rec_type" in data.keys()) and (data["rec_type"] not in [None, "none"]):
         # create recurring sittings
         #base_sitting_length = sitting_length + timedelta(hours=1)
         sitting_length = timedelta(seconds=length)
         base_sitting_length = timedelta(seconds=length) + timedelta(hours=1)
         dates = self.generate_dates(data)
         initial_sitting.recurring_type = data.get("rec_type")
         initial_sitting.recurring_id = 0
         initial_sitting.sitting_length = length
         for count, date in enumerate(dates):
             if not count:
                 #we've already added the initial sitting
                 initial_sitting.recurring_end_date = (
                     dates[len(dates)-1] + base_sitting_length)
                 session.merge(initial_sitting)
                 continue
             
             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
             add_form = AddForm(self.sittings_container, request_copy)
             add_form.update()
             if not add_form.errors:
                 # use finishConstruction API here
                 obj = add_form.created_object                    
                 obj.sitting_length = int(time.mktime(date.timetuple()))
                 obj.recurring_id = initial_sitting.sitting_id
                 session.merge(obj)
     else:
         initial_sitting.recurring_type = data.get("rec_type")
         initial_sitting.recurring_id = data.get("event_pid", 0)
         if data.get("event_length"):
             initial_sitting.sitting_length = data.get("event_length")
         session.merge(initial_sitting)
         wfc = IWorkflowController(initial_sitting)
         wfc.fireAutomatic()
     sitting_action = "inserted"
     if data["rec_type"] == "none":
         sitting_action = "deleted"
         session.merge(initial_sitting)
     self.template_data.append({
             "sitting_id": initial_sitting.sitting_id, 
             "action": sitting_action,
             "ids": data["ids"],
         })
     self.request.response.setHeader("Content-type", "text/xml")
     return self.xml_template()
Ejemplo n.º 4
0
    def handle_insert(self, action, data):
        session = Session()
        data["rec_end_date"] = data["end_date"]
        self.template_data = []
        initial_sitting = None
        length = data["event_length"]
        venue_id = unicode(data["venue"]) if data['venue'] else None
        if data.get("rec_type") not in [None, "none"]:
            data["end_date"] = data["start_date"] + timedelta(seconds=length)
            self.request.form["end_date"] = data["end_date"].strftime(
                DT_FORMAT)
        data["headless"] = "true"
        self.request.form["venue_id"] = data["venue_id"] = venue_id
        self.request.form["headless"] = "true"
        add_form = AddForm(self.sittings_container, self.request)
        add_form.update()
        if not add_form.errors:
            initial_sitting = removeSecurityProxy(add_form.created_object)
        else:
            return self.insert_sitting_failure_handler(action, data,
                                                       add_form.errors)
        if ("rec_type" in data.keys()) and (data["rec_type"]
                                            not in [None, "none"]):
            # create recurring sittings
            #base_sitting_length = sitting_length + timedelta(hours=1)
            sitting_length = timedelta(seconds=length)
            base_sitting_length = timedelta(seconds=length) + timedelta(
                hours=1)
            dates = self.generate_dates(data)
            initial_sitting.recurring_type = data.get("rec_type")
            initial_sitting.recurring_id = 0
            initial_sitting.sitting_length = length
            for count, date in enumerate(dates):
                if not count:
                    #we've already added the initial sitting
                    initial_sitting.recurring_end_date = (
                        dates[len(dates) - 1] + base_sitting_length)
                    session.merge(initial_sitting)
                    continue

                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
                add_form = AddForm(self.sittings_container, request_copy)
                add_form.update()
                if not add_form.errors:
                    # use finishConstruction API here
                    obj = add_form.created_object
                    obj.sitting_length = int(time.mktime(date.timetuple()))
                    obj.recurring_id = initial_sitting.sitting_id
                    session.merge(obj)
        else:
            initial_sitting.recurring_type = data.get("rec_type")
            initial_sitting.recurring_id = data.get("event_pid", 0)
            if data.get("event_length"):
                initial_sitting.sitting_length = data.get("event_length")
            session.merge(initial_sitting)
            wfc = IWorkflowController(initial_sitting)
            wfc.fireAutomatic()
        sitting_action = "inserted"
        if data["rec_type"] == "none":
            sitting_action = "deleted"
            session.merge(initial_sitting)
        self.template_data.append({
            "sitting_id": initial_sitting.sitting_id,
            "action": sitting_action,
            "ids": data["ids"],
        })
        self.request.response.setHeader("Content-type", "text/xml")
        return self.xml_template()