Ejemplo n.º 1
0
 def handle_update(self, action, data):
     session = Session()
     self.template_data = []
     sitting = domain.GroupSitting()
     sitting = session.query(domain.GroupSitting).get(data["ids"])
     sitting.start_date = data["start_date"].replace(tzinfo=None)
     sitting.end_date = data["end_date"].replace(tzinfo=None)
     if "language" in data.keys():
         sitting.language = data["language"]
     if "venue" in data.keys():
         sitting.venue_id = data["venue"]
     sitting.short_name = data.get("short_name", None)
     sitting.activity_type = data.get("activity_type", None)
     sitting.meeting_type = data.get("meeting_type", None)
     sitting.convocation_type = data.get("convocation_type", None)
     # set extra data needed by template
     session.flush()
     notify(ObjectModifiedEvent(sitting))
     self.template_data.append({"group_sitting_id": sitting.group_sitting_id, 
                                 "action": "inserted",
                                 "ids": data["ids"]})
     session.flush()
     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_update(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):
         # updating recurring events - we assume existing events fall
         # at the beginning of the sequence and offer in place update.
         parent_sitting_id = int(data["ids"]) or data["event_pid"]
         length = data["event_length"]
         sitting_length = timedelta(seconds=length)
         base_sitting_length = sitting_length + timedelta(hours=1)
         siblings = (
             session.query(domain.Sitting)
             .filter(
                 or_(
                     domain.Sitting.recurring_id == parent_sitting_id, domain.Sitting.sitting_id == parent_sitting_id
                 )
             )
             .order_by(domain.Sitting.sitting_id)
             .all()
         )
         dates = self.generate_dates(data)
         current_count = len(siblings)
         for count, date in enumerate(dates):
             is_new = not count < current_count
             if is_new:
                 sitting = domain.Sitting()
             else:
                 sitting = siblings[count]
             sitting.start_date = date
             if not count:
                 sitting.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:
                 end_date = date + sitting_length
                 sitting.end_date = end_date
                 sitting.sitting_length = int(time.mktime(date.timetuple()))
             # apply changes to parent and siblings new or existing
             sitting.short_name = data.get("short_name", None)
             sitting.venue_id = data["venue"]
             sitting.language = data["language"]
             sitting.activity_type = data.get("activity_type", None)
             sitting.meeting_type = data.get("meeting_type", None)
             sitting.convocation_type = data.get("convocation_type", None)
             if is_new:
                 sitting.group_id = trusted.group_id
                 sitting.recurring_id = parent_sitting_id
                 session.add(sitting)
                 session.flush()
                 notify(ObjectCreatedEvent(sitting))
             else:
                 session.flush()
                 notify(ObjectModifiedEvent(sitting))
             self.template_data.append(
                 {
                     "sitting_id": sitting.sitting_id,
                     "action": (is_new and "inserted" or "updated"),
                     "ids": sitting.sitting_id,
                 }
             )
         # delete any sittings outside recurring bounds
         for del_sibling in siblings[len(dates) :]:
             session.delete(del_sibling)
             del_id = del_sibling.sitting_id
             notify(ObjectRemovedEvent(del_sibling))
             self.template_data.append({"sitting_id": del_id, "action": "deleted", "ids": del_id})
     else:
         sitting_id = int(data["ids"])
         parent_id = data["event_pid"]
         sitting = session.query(domain.Sitting).get(sitting_id)
         if sitting is None:
             sitting = session.query(domain.Sitting).get(parent_id)
         sitting.start_date = data["start_date"].replace(tzinfo=None)
         sitting.end_date = data["end_date"].replace(tzinfo=None)
         sitting.sitting_length = data.get("event_length")
         if "language" in data.keys():
             sitting.language = data["language"]
         if "venue" in data.keys():
             sitting.venue_id = data["venue"]
         sitting.short_name = data.get("short_name", None)
         sitting.activity_type = data.get("activity_type", None)
         sitting.meeting_type = data.get("meeting_type", None)
         sitting.convocation_type = data.get("convocation_type", None)
         session.flush()
         notify(ObjectModifiedEvent(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.º 5
0
 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"] not in [None, "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
         length = data["event_length"]
         sitting_length = timedelta(seconds=length)
         base_sitting_length = sitting_length + timedelta(hours=1)
         initial_sitting = None
         recurrent_sittings = []
         dates = self.generate_dates(data)
         for count, date in enumerate(dates):
             sitting = domain.Sitting()
             sitting.group_id = trusted.group_id
             sitting.short_name = data.get("short_name", None)
             sitting.start_date = date
             sitting.language = data["language"]
             sitting.venue_id = data["venue"]
             sitting.activity_type = data.get("activity_type", None)
             sitting.meeting_type = data.get("meeting_type", None)
             sitting.convocation_type = data.get("convocation_type", None)
             if not count:
                 sitting.end_date = dates[len(dates) - 1] + base_sitting_length
                 sitting.recurring_type = data.get("rec_type")
                 sitting.recurring_id = 0
                 sitting.sitting_length = length
                 session.add(sitting)
                 session.flush()
                 initial_sitting = sitting
             else:
                 end_date = date + sitting_length
                 sitting.end_date = end_date
                 sitting.sitting_length = int(time.mktime(date.timetuple()))
                 sitting.recurring_id = initial_sitting.sitting_id
                 session.add(sitting)
                 recurrent_sittings.append(sitting)
         session.flush()
         for s in [initial_sitting] + recurrent_sittings:
             notify(ObjectCreatedEvent(s))
             self.template_data.append({"sitting_id": s.sitting_id, "action": "inserted", "ids": data["ids"]})
         self.request.response.setHeader("Content-type", "text/xml")
         return self.xml_template()
     else:
         sitting = domain.Sitting()
         sitting.short_name = data.get("short_name", None)
         sitting.start_date = data["start_date"].replace(tzinfo=None)
         sitting.end_date = data["end_date"].replace(tzinfo=None)
         sitting.recurring_type = data["rec_type"]
         sitting.sitting_length = data.get("event_length")
         sitting.recurring_id = data.get("event_pid")
         sitting.group_id = trusted.group_id
         sitting.language = data["language"]
         sitting.venue_id = data["venue"]
         sitting.activity_type = data.get("activity_type", None)
         sitting.meeting_type = data.get("meeting_type", None)
         sitting.convocation_type = data.get("convocation_type", None)
         session.add(sitting)
         session.flush()
         notify(ObjectCreatedEvent(sitting))
         sitting_action = "inserted"
         if data["rec_type"] == "none":
             sitting_action = "deleted"
         self.template_data.append({"sitting_id": sitting.sitting_id, "action": sitting_action, "ids": data["ids"]})
         self.request.response.setHeader("Content-type", "text/xml")
         return self.xml_template()
Ejemplo n.º 6
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.º 7
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.º 8
0
 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.short_name = data.get("short_name", None)
             sitting.start_date = date
             sitting.end_date = date + sitting_length
             sitting.language = data["language"]
             sitting.venue_id = data["venue"]
             sitting.activity_type = data.get("activity_type", None)
             sitting.meeting_type = data.get("meeting_type", None)
             sitting.convocation_type = data.get("convocation_type", None)
             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.short_name = data.get("short_name", None)
         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"]
         sitting.activity_type = data.get("activity_type", None)
         sitting.meeting_type = data.get("meeting_type", None)
         sitting.convocation_type = data.get("convocation_type", None)
         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()