Beispiel #1
0
 def handle_delete(self, action, data):
     session = Session()
     sitting = session.query(domain.GroupSitting).get(data["ids"])
     session.delete(sitting)
     session.commit()
     self.request.response.setHeader('Content-type', 'text/xml')
     return '<data><action type="deleted" sid="'+str(data["ids"])+'" tid="'+str(sitting.sitting_id)+'" /></data>'
Beispiel #2
0
 def handle_delete(self, action, data):
     session = Session()
     sitting_id = self.context.__parent__.sitting_id
     sch = session.query(domain.ItemSchedule).filter(sql.and_(model_schema.items_schedule.c.sitting_id == sitting_id, model_schema.items_schedule.c.item_id == data['item_id'])).all()        
     for i in sch:
         session.delete(i)
     self.request.response.redirect(self.next_url)
Beispiel #3
0
    def delete_subobjects(self):
        """Delete subobjects.

        1) For category maintenance, move the scheduling to the bottom
        of the container.

        2) Delete any discussion items that have been associated to
        this scheduling.
        """
        try:
            field = self.request.form['field']
        except:
            import pdb
            pdb.set_trace()
        reorder_form = ItemScheduleReorderForm(self.context, self.request)
        container = copy.copy(removeSecurityProxy(self.context.__parent__))
        subset_query = container.subset_query
        container.subset_query = sql.and_(
            subset_query,
            container.domain_model.planned_order > self.context.planned_order)
        for i in range(len(container) * 2):
            reorder_form.handle_move.success({'mode': 'down', 'field': field})
        container.subset_query = subset_query

        count = 0
        session = Session()
        unproxied = removeSecurityProxy(self.context)
        for key, discussion in unproxied.discussions.items():
            del unproxied.discussions[key]
            session.delete(discussion)
            count += 1
        #session.close()
        return count
Beispiel #4
0
    def delete_subobjects(self):
        """Delete subobjects.

        1) For category maintenance, move the scheduling to the bottom
        of the container.

        2) Delete any discussion items that have been associated to
        this scheduling.
        """
        try:
            field = self.request.form['field']
        except:
            import pdb; pdb.set_trace()
        reorder_form = ItemScheduleReorderForm(self.context, self.request)
        container = copy.copy(removeSecurityProxy(self.context.__parent__))
        subset_query = container.subset_query
        container.subset_query = sql.and_(
            subset_query,
            container.domain_model.planned_order > self.context.planned_order)
        for i in range(len(container) * 2):
            reorder_form.handle_move.success({'mode': 'down', 'field': field})
        container.subset_query = subset_query

        count = 0
        session = Session()
        unproxied = removeSecurityProxy(self.context)
        for key, discussion in unproxied.discussions.items():
            del unproxied.discussions[key]
            session.delete(discussion)
            count += 1
        #session.close()
        return count
Beispiel #5
0
    def handle_add_save(self, action, data):
        """After succesful creation of translation, redirect to the
        view."""
        for key in data.keys():
            if isinstance(data[key], str): 
                data[key] = unescape(data[key])
            
        #url = url.absoluteURL(self.context, self.request)
        
        #language = get_language_by_name(data["language"])["name"]

        
        session = Session()
        trusted = removeSecurityProxy(self.context)
        mapper = rdb.orm.object_mapper(trusted)
        pk = getattr(trusted, mapper.primary_key[0].name) 
        
        current_translation = get_translation_for(self.context, data["language"])
        if current_translation:
            for translation in current_translation:
                session.delete(translation)
                
        
        for form_field in data.keys():
            if form_field == "language":
                continue
            translation = domain.ObjectTranslation()
            translation.object_id = pk
            translation.object_type = trusted.__class__.__name__
            translation.field_name = form_field
            translation.lang = data["language"]
            translation.field_text = data[form_field]
            session.add(translation)
        session.flush()
        session.commit()
        session.close()
        
        #versions = IVersioned(self.context)
        #version = versions.create("'%s' translation added" % language)

        # reset workflow state
        #version.status = None
        #IWorkflowInfo(version).fireTransition("create-translation")
        # redefine form context and proceed with edit action
        #self.setUpAdapters(version)
        #handle_edit_action(self, action, data)

        # commit version such that it gets a version id
        #transaction.commit()
        
        #if not self._next_url:
        #    self._next_url = ( \
        #        '%s/versions/%s' % (url, stringKey(version)) + \
        #        '?portal_status_message=Translation added')

        self._finished_add = True
Beispiel #6
0
    def handle_add_save(self, action, data):
        """After succesful creation of translation, redirect to the
        view."""
        for key in data.keys():
            if isinstance(data[key], str): 
                data[key] = unescape(data[key])
            
        #url = url.absoluteURL(self.context, self.request)
        
        #language = get_language_by_name(data["language"])["name"]

        
        session = Session()
        trusted = removeSecurityProxy(self.context)
        mapper = rdb.orm.object_mapper(trusted)
        pk = getattr(trusted, mapper.primary_key[0].name) 
        
        current_translation = get_translation_for(self.context, data["language"])
        if current_translation:
            for translation in current_translation:
                session.delete(translation)
                
        
        for form_field in data.keys():
            if form_field == "language":
                continue
            translation = domain.ObjectTranslation()
            translation.object_id = pk
            translation.object_type = trusted.__class__.__name__
            translation.field_name = form_field
            translation.lang = data["language"]
            translation.field_text = data[form_field]
            session.add(translation)
        session.flush()
        session.commit()
        session.close()
        
        #versions = IVersioned(self.context)
        #version = versions.create("'%s' translation added" % language)

        # reset workflow state
        #version.status = None
        #IWorkflowInfo(version).fireTransition("create-translation")
        # redefine form context and proceed with edit action
        #self.setUpAdapters(version)
        #handle_edit_action(self, action, data)

        # commit version such that it gets a version id
        #transaction.commit()
        
        #if not self._next_url:
        #    self._next_url = ( \
        #        '%s/versions/%s' % (url, stringKey(version)) + \
        #        '?portal_status_message=Translation added')

        self._finished_add = True
Beispiel #7
0
 def handle_delete(self, action, data):
     session = Session()
     sitting_id = self.context.__parent__.sitting_id
     sch = session.query(domain.ItemSchedule).filter(
         sql.and_(model_schema.items_schedule.c.sitting_id == sitting_id,
                  model_schema.items_schedule.c.item_id ==
                  data['item_id'])).all()
     for i in sch:
         session.delete(i)
     self.request.response.redirect(self.next_url)
Beispiel #8
0
    def handle_generate_takes(self, action, data):
        session = Session()
        trusted = removeSecurityProxy(self.context)
        takes = session.query(
            domain.Take).filter(domain.Take.sitting_id == trusted.sitting_id)
        for t in takes:
            session.delete(t)

        #import pdb; pdb.set_trace()
        sitting = trusted
        current_start_time = sitting.start_date
        sitting_duration = sitting.end_date - sitting.start_date
        take_duration = timedelta(minutes=int(data["duration"]))
        assigned_reporters = get_assigned_staff(self.context, "Reporter")
        assigned_readers = get_assigned_staff(self.context, "Reader")
        assigned_editors = get_assigned_staff(self.context, "Editor")
        c_reporter = 0
        c_reader = 0
        c_editor = 0

        while sitting_duration > timedelta(minutes=0):
            take = domain.Take()
            take.sitting_id = sitting.sitting_id
            if (sitting_duration - take_duration) > timedelta(minutes=0):
                sitting_duration = sitting_duration - take_duration
                take.start_date = current_start_time
                take.end_date = take.start_date + take_duration
                current_start_time = take.end_date
            else:
                take.start_date = current_start_time
                take.end_date = take.start_date + sitting_duration
                sitting_duration = timedelta(minutes=0)
            if c_reporter > len(assigned_reporters) - 1:
                c_reporter = 0
                take.reporter_id = assigned_reporters[c_reporter]
            else:
                take.reporter_id = assigned_reporters[c_reporter]
            c_reporter = c_reporter + 1

            if c_reader > len(assigned_readers) - 1:
                c_reader = 0
                take.reader_id = assigned_readers[c_reader]
            else:
                take.reader_id = assigned_readers[c_reader]
            c_reader = c_reader + 1

            if c_editor > len(assigned_editors) - 1:
                c_editor = 0
                take.editor_id = assigned_editors[c_editor]
            else:
                take.editor_id = assigned_editors[c_editor]
            c_editor = c_editor + 1
            session.add(take)
        session.commit()
        self.request.response.redirect('./takes')
Beispiel #9
0
 def handle_generate_takes(self, action, data):
     session = Session()
     trusted = removeSecurityProxy(self.context)
     takes = session.query(domain.Take).filter(
         domain.Take.sitting_id == trusted.sitting_id)
     for t in takes:
         session.delete(t)
     
     #import pdb; pdb.set_trace()
     sitting = trusted
     current_start_time = sitting.start_date
     sitting_duration = sitting.end_date - sitting.start_date
     take_duration = timedelta(minutes=int(data["duration"]))
     assigned_reporters = get_assigned_staff(self.context, "Reporter")
     assigned_readers = get_assigned_staff(self.context, "Reader")
     assigned_editors = get_assigned_staff(self.context, "Editor")
     c_reporter = 0 
     c_reader = 0
     c_editor = 0
     
     while sitting_duration > timedelta(minutes=0):
         take = domain.Take()
         take.sitting_id = sitting.sitting_id
         if (sitting_duration - take_duration) > timedelta(minutes=0):
             sitting_duration = sitting_duration - take_duration
             take.start_date = current_start_time
             take.end_date = take.start_date + take_duration
             current_start_time = take.end_date
         else:
             take.start_date = current_start_time
             take.end_date = take.start_date + sitting_duration
             sitting_duration = timedelta(minutes=0)
         if c_reporter > len(assigned_reporters)-1:
             c_reporter = 0
             take.reporter_id = assigned_reporters[c_reporter]
         else:
             take.reporter_id = assigned_reporters[c_reporter]
         c_reporter = c_reporter + 1
         
         if c_reader > len(assigned_readers)-1:
             c_reader = 0
             take.reader_id = assigned_readers[c_reader]
         else:
             take.reader_id = assigned_readers[c_reader]
         c_reader = c_reader + 1
         
         if c_editor > len(assigned_editors)-1:
             c_editor = 0
             take.editor_id = assigned_editors[c_editor]
         else:
             take.editor_id = assigned_editors[c_editor]
         c_editor = c_editor + 1
         session.add(take)
     session.commit()
     self.request.response.redirect('./takes')
 def _deleteAnnotation(self):
     """Deletes an Annotation."""
     params = {}
     params.update(parse_qsl(self.request['QUERY_STRING']))
     annotation_id = params.get('id', None)
     annotation = self.getAnnotation(annotation_id)
     if annotation and annotation.quote_author == self.getAuthenticatedUser():
         session = Session()
         session.delete(annotation)
         self.request.response.setStatus('NoContent')
         return
     self.request.response.setStatus('BadRequest') # No id
Beispiel #11
0
 def _deleteAnnotation(self):
     """Deletes an Annotation."""
     params = {}
     params.update(parse_qsl(self.request['QUERY_STRING']))
     annotation_id = params.get('id', None)
     annotation = self.getAnnotation(annotation_id)
     if annotation and annotation.quote_author == self.getAuthenticatedUser(
     ):
         session = Session()
         session.delete(annotation)
         self.request.response.setStatus('NoContent')
         return
     self.request.response.setStatus('BadRequest')  # No id
Beispiel #12
0
def unbook_resource(sitting, resource):
    """
    remove a resource from a sitting
    """
    assert (type(sitting) == domain.GroupSitting)
    assert (type(resource) == domain.Resource)
    session = Session()
    cq = session.query(domain.ResourceBooking).filter(
        sql.and_(domain.ResourceBooking.resource_id == resource.resource_id,
                 domain.ResourceBooking.sitting_id == sitting.sitting_id))
    results = cq.all()
    for result in results:
        session.delete(result)
        session.flush()
Beispiel #13
0
 def _deleteAnnotation(self):
     """Deletes an Annotation."""
     params = {}
     params.update(parse_qsl(self.request['QUERY_STRING']))
     if self.request.environment.has_key('wsgi.input'):
         params.update(parse_qsl(self.request.environment['wsgi.input'].read()))
     
     annotation_id = params.get('id', None)
     annotation = self.getAnnotation(annotation_id)
     if annotation and annotation.quote_authorid == self.getAuthenticatedUserId():
         session = Session()
         session.delete(annotation)
         self.request.response.setStatus('NoContent')
         return
     self.request.response.setStatus('BadRequest') # No id
def unbook_resource( sitting, resource ):
    """
    remove a resource from a sitting
    """
    assert( type(sitting) == domain.GroupSitting)
    assert( type(resource) == domain.Resource )
    session = Session()
    cq = session.query( domain.ResourceBooking).filter( 
                sql.and_( domain.ResourceBooking.resource_id == 
                            resource.resource_id,
                        domain.ResourceBooking.sitting_id == 
                        sitting.sitting_id ))
    results = cq.all()
    for result in results:
        session.delete(result)
        session.flush()
Beispiel #15
0
    def handle_delete(self, action, data):
        count = self.delete_subobjects()
        container = self.context.__parent__
        trusted = removeSecurityProxy(self.context)
        session = Session()
        session.delete(trusted)
        count += 1

        try:
            session.commit()
        except IntegrityError, e:
            # this should not happen in production; it's a critical
            # error, because the transaction might have failed in the
            # second phase of the commit
            session.rollback()
            logging.critical(e)

            self.status = _(u"Could not delete item due to "
                            "database integrity error")

            return self.render()
Beispiel #16
0
    def handle_delete(self, action, data):
        count = self.delete_subobjects()
        container = self.context.__parent__
        trusted = removeSecurityProxy(self.context)
        session = Session()
        session.delete(trusted)
        count += 1

        try:
            session.commit()
        except IntegrityError, e:
            # this should not happen in production; it's a critical
            # error, because the transaction might have failed in the
            # second phase of the commit
            session.rollback()
            logging.critical(e)

            self.status = _(u"Could not delete item due to "
                            "database integrity error")

            return self.render()
Beispiel #17
0
 def __call__(self):
     ids = self.request.form['ids']
     action = self.request.form[ids + "_!nativeeditor_status"]
     session = Session()
     sitting = domain.GroupSitting()
     trusted = removeSecurityProxy(self.context)
     sitting.group_id = trusted.group_id
     if action == "inserted":
         sitting.start_date = self.request.form[ids + "_start_date"]
         sitting.end_date = self.request.form[ids + "_end_date"]
         sitting.sitting_type_id = self.request.form[ids + "_type"]
         sitting.status = None
         if ids + "_type" in self.request.form.keys():
             sitting.sitting_type_id = self.request.form[ids + "_type"]
         if ids + "_language" in self.request.form.keys():
             sitting.language = self.request.form[ids + "_language"]
         if ids + "_venue" in self.request.form.keys():
             sitting.venue_id = self.request.form[ids + "_venue"]
         session.add(sitting)
         notify(ObjectCreatedEvent(sitting))
         session.commit()
     elif action == "updated":
         sitting = session.query(domain.GroupSitting).get(ids)
         sitting.start_date = self.request.form[ids + "_start_date"]
         sitting.end_date = self.request.form[ids + "_end_date"]
         if ids + "_type" in self.request.form.keys():
             sitting.sitting_type_id = self.request.form[ids + "_type"]
         if ids + "_language" in self.request.form.keys():
             sitting.language = self.request.form[ids + "_language"]
         if ids + "_venue" in self.request.form.keys():
             sitting.venue_id = self.request.form[ids + "_venue"]
         session.update(sitting)
         session.commit()
     elif action == "deleted":
         sitting = session.query(domain.GroupSitting).get(ids)
         session.delete(sitting)
         session.commit()
     self.request.response.setHeader('Content-type', 'text/xml')
     return '<data><action type="' + action + '" sid="' + str(
         ids) + '" tid="' + str(sitting.sitting_id) + '" /></data>'
 def __delitem__( self, name ):
     instance = self[ name ]
     session = Session()
     session.delete( instance )