Exemple #1
0
    def aggiungi_allegato(self, nome, descrizione, fopen, tipo='Allegato'):
        """
        nome: deve essere con l'estenzione esempio: .pdf altrimenti errore xml -201!
        il fopen popola la lista degli allegati.
        """
        if len(nome.split('.')) == 1:
            raise Exception(("'nome' deve essere con l'estensione "
                             "esempio: .pdf altrimenti errore xml -201!"))
        self.assure_connection()

        allegato_idsum = 2
        # recheck id seq
        for al in self.allegati:
            al['allegato_id'] = self.allegati.index(al) + allegato_idsum
        # +2 because it starts from 0 and id=1 is docPrinc

        allegato_dict = self._get_allegato_dict()
        allegato_dict['allegato_id'] = len(self.allegati) + allegato_idsum
        allegato_dict['nome'] = clean_string(nome, save_extension=True)
        allegato_dict['descrizione'] = clean_string(descrizione)
        allegato_dict['tipo'] = clean_string(tipo)

        allegato = self.client.wsdl.types.get_type(qname='ns0:attach')()
        allegato.id = len(self.allegati) + allegato_idsum
        allegato.fileName = clean_string(nome, save_extension=True)

        allegato.fileContent = self._encode_filestream(fopen)
        allegato_dict['ns0:attach'] = allegato

        self.allegati.append(allegato_dict)
        return self.render_AllegatoXML(allegato_dict)
Exemple #2
0
    def __init__(self,
                 wsdl_url,
                 username,
                 password,
                 template_xml_flusso=open(
                     PROT_TEMPLATE_FLUSSO_ENTRATA_DIPENDENTE_PATH).read(),
                 required_attributes=REQUIRED_ATTRIBUTES,
                 strictly_required=False,
                 **kwargs):
        """
        il codice titolario in WSArchiPRO corrisponde alla PRIMARYKEY dello schema SQL
        """

        for attr in required_attributes:
            if strictly_required:
                if not kwargs.get(attr):
                    raise Exception('Value of {} is null'.format(attr))
                setattr(self, attr, clean_string(kwargs[attr]))
            else:
                setattr(self, attr, clean_string(kwargs.get(attr)))

        # self.doc_fopen = kwargs.get('fopen')

        # numero viene popolato a seguito di una protocollazione
        if kwargs.get('numero') and kwargs.get('anno'):
            self.numero = kwargs.get('numero')
            self.anno = kwargs.get('anno')
        else:
            self.numero = None
            self.anno = None

        # if kwargs.get('aoo'):
        # self.aoo = kwargs.get('aoo')

        # diventa vero solo se numero/anno sono stati opportunamente estratti e verificati dal server del protocollo
        self.protocollato = False

        self.docPrinc = None
        # lista di dizionari contenente la struttura di attributi + bytes stream per ogni allegato
        # es {  nome_file,
        #       descrizione,
        #       tipo,
        #       fopen }
        #
        self.allegati = []
        self.template_xml_flusso = template_xml_flusso

        # to be filled by connect() method
        self.username = username
        self.password = password
        self.wsdl_url = wsdl_url
        self.client = None
        self.login = None
Exemple #3
0
    def aggiungi_docPrinc(self, fopen, nome_doc=None, tipo_doc=None):
        if (nome_doc and not tipo_doc) or \
           (tipo_doc and not nome_doc):
            raise Exception(
                'tipo_doc e nome_doc devono essere configurati insieme')

        if nome_doc and tipo_doc:
            self.nome_doc = clean_string(nome_doc, save_extension=True)
            self.tipo_doc = clean_string(tipo_doc)
        # altrimenti utilizza quelle definite nel costruttore

        self.docPrinc = fopen
        self.docPrinc.seek(0)
        return True