Exemple #1
0
    def create_protocol_parts(self, delete_existing=False, mks=None, mk_names=None):
        """ Create protocol parts from this instance's protocol_text
            Optionally, delete existing parts.
            If the meeting already has parts, and you don't ask to
            delete them, a ValidationError will be thrown, because
            it doesn't make sense to create the parts again.
        """
        if delete_existing:
            ppct = ContentType.objects.get_for_model(ProtocolPart)
            annotations = Annotation.objects.filter(content_type=ppct, object_id__in=self.parts.all)
            logger.debug(
                "deleting %d annotations, because I was asked to delete the relevant protocol parts on cm.id=%d"
                % (annotations.count(), self.id)
            )
            annotations.delete()
            self.parts.all().delete()
        else:
            if self.parts.count():
                raise ValidationError(
                    "CommitteeMeeting already has parts. delete them if you want to run create_protocol_parts again."
                )
        if not self.protocol_text:  # sometimes there are empty protocols
            return  # then we don't need to do anything here.

        if self.committee.type == "plenum":
            create_plenum_protocol_parts(self, mks=mks, mk_names=mk_names)
            return

        # break the protocol to its parts
        # first, fix places where the colon is in the begining of next line
        # (move it to the end of the correct line)
        protocol_text = []
        for line in re.sub("[ ]+", " ", self.protocol_text).split("\n"):
            # if re.match(r'^\<.*\>\W*$',line): # this line start and ends with
            #                                  # <...>. need to remove it.
            #    line = line[1:-1]
            if line.startswith(":"):
                protocol_text[-1] += ":"
                protocol_text.append(line[1:])
            else:
                protocol_text.append(line)

        i = 1
        section = []
        header = ""

        # now create the sections
        for line in protocol_text:
            if legitimate_header(line):
                if (i > 1) or (section):
                    ProtocolPart(meeting=self, order=i, header=header, body="\n".join(section)).save()
                i += 1
                header = re.sub("[\>:]+$", "", re.sub("^[\< ]+", "", line))
                section = []
            else:
                section.append(line)

        # don't forget the last section
        ProtocolPart(meeting=self, order=i, header=header, body="\n".join(section)).save()
Exemple #2
0
    def create_protocol_parts(self, delete_existing=False, mks=None, mk_names=None):
        """ Create protocol parts from this instance's protocol_text
            Optionally, delete existing parts.
            If the meeting already has parts, and you don't ask to
            delete them, a ValidationError will be thrown, because
            it doesn't make sense to create the parts again.
        """
        if delete_existing:
            ppct = ContentType.objects.get_for_model(ProtocolPart)
            annotations = Annotation.objects.filter(content_type=ppct, object_id__in=self.parts.all)
            logger.debug('deleting %d annotations, because I was asked to delete the relevant protocol parts on cm.id=%d' % (annotations.count(), self.id))
            annotations.delete()
            self.parts.all().delete()
        else:
            if self.parts.count():
                raise ValidationError('CommitteeMeeting already has parts. delete them if you want to run create_protocol_parts again.')
        if not self.protocol_text: # sometimes there are empty protocols
            return # then we don't need to do anything here.

        if self.committee.type=='plenum':
            create_plenum_protocol_parts(self,mks=mks,mk_names=mk_names)
            return

        # break the protocol to its parts
        # first, fix places where the colon is in the begining of next line
        # (move it to the end of the correct line)
        protocol_text = []
        for line in re.sub("[ ]+"," ", self.protocol_text).split('\n'):
            #if re.match(r'^\<.*\>\W*$',line): # this line start and ends with
            #                                  # <...>. need to remove it.
            #    line = line[1:-1]
            if line.startswith(':'):
                protocol_text[-1] += ':'
                protocol_text.append(line[1:])
            else:
                protocol_text.append(line)

        i = 1
        section = []
        header = ''

        # now create the sections
        for line in protocol_text:
            if legitimate_header(line):
                if (i>1)or(section):
                    ProtocolPart(meeting=self, order=i,
                        header=header, body='\n'.join(section)).save()
                i += 1
                header = re.sub('[\>:]+$','',re.sub('^[\< ]+','',line))
                section = []
            else:
                section.append (line)

        # don't forget the last section
        ProtocolPart(meeting=self, order=i,
            header=header, body='\n'.join(section)).save()
Exemple #3
0
    def create_protocol_parts(self,
                              delete_existing=False,
                              mks=None,
                              mk_names=None):
        """ Create protocol parts from this instance's protocol_text
            Optionally, delete existing parts.
            If the meeting already has parts, and you don't ask to
            delete them, a ValidationError will be thrown, because
            it doesn't make sense to create the parts again.
        """
        logger.debug('create_protocol_parts %s' % delete_existing)
        if delete_existing:
            ppct = ContentType.objects.get_for_model(ProtocolPart)
            annotations = Annotation.objects.filter(
                content_type=ppct, object_id__in=self.parts.all)
            logger.debug(
                'deleting %d annotations, because I was asked to delete the relevant protocol parts on cm.id=%d'
                % (annotations.count(), self.id))
            annotations.delete()
            self.parts.all().delete()
        else:
            if self.parts.count():
                raise ValidationError(
                    'CommitteeMeeting already has parts. delete them if you want to run create_protocol_parts again.'
                )
        if not self.protocol_text:  # sometimes there are empty protocols
            return  # then we don't need to do anything here.
        if self.committee.type == 'plenum':
            create_plenum_protocol_parts(self, mks=mks, mk_names=mk_names)
            return
        else:

            def get_protocol_part(i, part):
                logger.debug('creating protocol part %s' % i)
                return ProtocolPart(meeting=self,
                                    order=i,
                                    header=part.header,
                                    body=part.body)

            with KnessetDataCommitteeMeetingProtocol.get_from_text(
                    self.protocol_text) as protocol:
                # TODO: use bulk_create (I had a strange error when using it)
                # ProtocolPart.objects.bulk_create(
                # for testing, you could just save one part:
                # get_protocol_part(1, protocol.parts[0]).save()
                list([
                    get_protocol_part(i, part).save()
                    for i, part in zip(range(1,
                                             len(protocol.parts) +
                                             1), protocol.parts)
                ])
            self.protocol_parts_update_date = datetime.now()
            self.save()
Exemple #4
0
    def create_protocol_parts(self, delete_existing=False, mks=None,
                              mk_names=None):
        """ Create protocol parts from this instance's protocol_text
            Optionally, delete existing parts.
            If the meeting already has parts, and you don't ask to
            delete them, a ValidationError will be thrown, because
            it doesn't make sense to create the parts again.
        """
        logger.debug('create_protocol_parts %s' % delete_existing)
        if delete_existing:
            ppct = ContentType.objects.get_for_model(ProtocolPart)
            annotations = Annotation.objects.filter(content_type=ppct,
                                                    object_id__in=self.parts.all)
            logger.debug(
                'deleting %d annotations, because I was asked to delete the relevant protocol parts on cm.id=%d' % (
                    annotations.count(), self.id))
            annotations.delete()
            self.parts.all().delete()
        else:
            if self.parts.count():
                raise ValidationError(
                    'CommitteeMeeting already has parts. delete them if you want to run create_protocol_parts again.')
        if not self.protocol_text:  # sometimes there are empty protocols
            return  # then we don't need to do anything here.
        if self.committee.type == 'plenum':
            create_plenum_protocol_parts(self, mks=mks, mk_names=mk_names)
            return
        else:
            def get_protocol_part(i, part):
                logger.debug('creating protocol part %s' % i)
                return ProtocolPart(meeting=self, order=i, header=part.header,
                                    body=part.body)

            with KnessetDataCommitteeMeetingProtocol.get_from_text(
                    self.protocol_text) as protocol:
                # TODO: use bulk_create (I had a strange error when using it)
                # ProtocolPart.objects.bulk_create(
                # for testing, you could just save one part:
                # get_protocol_part(1, protocol.parts[0]).save()
                list([
                         get_protocol_part(i, part).save()
                         for i, part
                         in
                         zip(range(1, len(protocol.parts) + 1), protocol.parts)
                         ])
            self.protocol_parts_update_date = datetime.now()
            self.save()