Exemplo n.º 1
0
    def new_func(*original_args, **original_kwargs):
        request = original_args[0]
        domanda = None

        if original_kwargs.get('modulo_compilato_id'):
            mdb = get_object_or_404(ModuloDomandaBando,
                                    pk=original_kwargs['modulo_compilato_id'])
            domanda = mdb.domanda_bando
        elif original_kwargs.get('domanda_bando_id'):
            domanda = get_object_or_404(DomandaBando,
                                        pk=original_kwargs['domanda_bando_id'])
        elif original_kwargs.get('bando_id'):
            bando = _get_bando_queryset(original_kwargs['bando_id']).first()
            dipendente = get_object_or_404(Dipendente,
                                           matricola=request.user.matricola)
            domanda = get_object_or_404(DomandaBando,
                                        bando=bando,
                                        dipendente=dipendente)
        if request.method == 'GET':
            return func_to_decorate(*original_args, **original_kwargs)
        elif request.method == 'POST':
            if domanda.modificabile():
                return func_to_decorate(*original_args, **original_kwargs)
            else:
                messages.error(
                    request,
                    'Non è possibile modificare una domanda già chiusa.')
                page_url = reverse('domande_peo:dashboard_domanda',
                                   args=[domanda.bando.slug]) + '#{}'.format(
                                       domanda.bando.slug)
                return HttpResponseRedirect(page_url)
Exemplo n.º 2
0
def vedi_modulo_inserito(request, bando_id, modulo_domanda_bando_id):
    """
        usato in admin per avere una anteprima dei campi scelti
    """
    modulo_domanda_bando = get_object_or_404(ModuloDomandaBando,
                                             pk=modulo_domanda_bando_id)
    bando = _get_bando_queryset(bando_id).first()
    descrizione_indicatore = modulo_domanda_bando.descrizione_indicatore
    json_dict = json.loads(modulo_domanda_bando.modulo_compilato)
    data = get_as_dict(json_dict, allegati=False)
    allegati = get_allegati_dict(modulo_domanda_bando)
    form = SavedFormContent.compiled_form_readonly(
        modulo_domanda_bando.compiled_form(remove_filefields=allegati))
    # form con i soli campi File da dare in pasto al tag della firma digitale
    form_allegati = descrizione_indicatore.get_form(remove_datafields=True)
    d = {
        'allegati': allegati,
        'form': form,
        'form_allegati': form_allegati,
        'bando': bando,
        'descrizione_indicatore': descrizione_indicatore,
        'modulo_domanda_bando': modulo_domanda_bando,
        'readonly': True
    }

    return render(request, 'modulo_form_readonly_user.html', d)
Exemplo n.º 3
0
def cancella_titolo(request, bando_id, modulo_compilato_id):
    """
        Deve essere chiamato da una dialog con checkbox di conferma
    """

    dipendente = get_object_or_404(Dipendente,
                                   matricola=request.user.matricola)
    bando = _get_bando_queryset(bando_id).first()

    mdb = get_object_or_404(ModuloDomandaBando,
                            pk=modulo_compilato_id,
                            domanda_bando__is_active=True,
                            domanda_bando__dipendente=dipendente)

    mdb.delete()
    mdb.domanda_bando.mark_as_modified()
    # Rimuove la folder relativa al modulo compilato,
    # comprensiva di allegati ('modulo_compilato_id' passato come argomento)
    elimina_directory(request.user.matricola, bando.slug, modulo_compilato_id)

    messages.success(request, 'Modulo rimosso con successo!')
    url = reverse('domande_peo:dashboard_domanda', args=[
        bando.pk,
    ])
    return HttpResponseRedirect(url + '#{}'.format(bando.slug))
Exemplo n.º 4
0
def anteprima_modulo_inserimento_frontend(request, bando_id,
                                          descrizione_indicatore_id):
    """
        usato in admin per avere una anteprima dei campi scelti
    """
    descrizione_indicatore = get_object_or_404(DescrizioneIndicatore,
                                               pk=descrizione_indicatore_id)
    bando = _get_bando_queryset(bando_id).first()
    dipendente = Dipendente.objects.filter(
        matricola=request.user.matricola).first()
    form = descrizione_indicatore.get_form()
    if request.method == 'POST':
        form = descrizione_indicatore.get_form(data=request.POST)
    page_title = 'Modulo Inserimento: "({}) {}"'.format(
        descrizione_indicatore.id_code, descrizione_indicatore.nome)
    d = {
        'page_title': page_title,
        'form': form,
        'bando': bando,
        'descrizione_indicatore': descrizione_indicatore,
        'dipendente': dipendente
    }
    messages.warning(
        request, "Questa è esclusivamente un'anteprima"
        " del modulo di inserimento e non ha alcun effetto"
        " sulla domanda")
    return render(request, 'modulo_form_readonly_frontend.html', d)
Exemplo n.º 5
0
def anteprima_modulo_inserimento(request, bando_id, descrizione_indicatore_id):
    """
        usato in admin per avere una anteprima dei campi scelti
    """

    descrizione_indicatore = get_object_or_404(DescrizioneIndicatore,
                                               pk=descrizione_indicatore_id)
    bando = _get_bando_queryset(bando_id).first()
    dipendente = Dipendente.objects.filter(
        matricola=request.user.matricola).first()

    form = descrizione_indicatore.get_form()

    if request.method == 'POST':
        form = descrizione_indicatore.get_form(data=request.POST)

    page_title = 'Modulo Inserimento: "({}) {}"'.format(
        descrizione_indicatore.id_code, descrizione_indicatore.nome)

    d = {
        'page_title': page_title,
        'form': form,
        'bando': bando,
        'descrizione_indicatore': descrizione_indicatore,
        'dipendente': dipendente
    }

    return render(request, 'modulo_form_readonly.html', d)
Exemplo n.º 6
0
def download_allegato(request, bando_id, modulo_compilato_id, allegato):
    """
        Download del file allegato, dopo aver superato i check di proprietà
    """
    bando = _get_bando_queryset(bando_id).first()

    # se scarica un utente staff o la commissione può accedervi
    if _user_is_staff_or_in_commission(request.user, bando):
        mdb = get_object_or_404(ModuloDomandaBando,
                                pk=modulo_compilato_id)
        dipendente = get_object_or_404(Dipendente,
                                       matricola=mdb.domanda_bando.dipendente.matricola)
    # altrimenti solo se l'utente è il proprietario e la domanda è attiva
    else:
        dipendente = get_object_or_404(Dipendente,
                                       matricola=request.user.matricola)
        mdb = get_object_or_404(ModuloDomandaBando,
                                pk=modulo_compilato_id,
                                domanda_bando__is_active=True,
                                domanda_bando__dipendente=dipendente)

    return download_allegato_from_mdb(bando,
                                      mdb,
                                      dipendente,
                                      allegato)
Exemplo n.º 7
0
def accetta_condizioni_bando(request, bando_id):
    """
        Mostra la schermata di accettazione delle condizioni per la
        partecipazione al Bando PEO.
        Accettando le condizioni e proseguendo, viene creata un'istanza
        di Domanda PEO
    """
    dipendente = get_object_or_404(Dipendente,
                                   matricola=request.user.matricola)
    bando = _get_bando_queryset(bando_id).first()

    # se la domanda già esiste fare redirect!
    domanda_bando = DomandaBando.objects.filter(dipendente=dipendente,
                                                bando=bando)
    if domanda_bando:
        url = reverse('domande_peo:dashboard_domanda',
                      args=[domanda_bando.first().bando.slug])
        return HttpResponseRedirect(url)
    # else:
    # raise PermissionDenied(("La tua Domanda di partecipazione non "
    # "esiste oppure è stata disabilitata."))

    if request.method == 'POST':
        form = AccettazioneClausoleForm(request.POST)
        if form.is_valid():
            conferma = request.POST["accettazione"]
            if conferma:
                url = reverse('domande_peo:dashboard_domanda',
                              args=[
                                  bando.slug,
                              ])
                return HttpResponseRedirect(url)
            else:
                url = reverse('domande_peo:accetta_condizioni_bando',
                              args=[
                                  bando.slug,
                              ])
                return HttpResponseRedirect(url)
    else:
        form = AccettazioneClausoleForm()

    page_title = 'Partecipazione Bando {}'.format(bando.nome)
    page_url = reverse('domande_peo:dashboard_domanda', args=[bando.slug])
    _breadcrumbs.reset()
    _breadcrumbs.add_url((page_url, page_title))

    d = {
        'page_title': page_title,
        'breadcrumbs': _breadcrumbs,
        'bando': bando,
        'dipendente': dipendente,
        'form': form
    }

    return render(request, 'accetta_condizioni_bando.html', d)
Exemplo n.º 8
0
def scelta_titolo_da_aggiungere(request, bando_id):
    """
        Lista degli indicatori ponderati.
        L'utente sceglie che tipologia di titolo deve aggiungere
    """

    dipendente = get_object_or_404(Dipendente,
                                   matricola=request.user.matricola)
    bando = _get_bando_queryset(bando_id).first()
    indicatori_ponderati = bando.indicatoreponderato_set.all().order_by(
        'id_code')
    # recupero la domanda peo del dipendente
    domanda_bando = DomandaBando.objects.filter(bando=bando,
                                                dipendente=dipendente)

    # se non c'è alcuna domanda, la creo
    # se la domanda c'è ma is_active==False, ritorno un messaggio di errore
    # altrimenti si prosegue con la domanda attualmente presente
    if domanda_bando:
        domanda_bando = domanda_bando.last()
    elif not domanda_bando:
        domanda_bando = DomandaBando.objects.create(
            bando=bando,
            dipendente=dipendente,
            modified=timezone.localtime(),
            livello=dipendente.livello,
            data_presa_servizio=dipendente.get_data_presa_servizio_csa(),
            data_ultima_progressione=dipendente.get_data_progressione())
    if not domanda_bando.is_active:
        return render(
            request, 'custom_message.html', {
                'avviso': ("La tua Domanda è stata sospesa. Per avere "
                           "informazioni contatta l' Area Risorse Umane.")
            })

    dashboard_domanda_title = 'Partecipazione Bando {}'.format(bando.nome)
    dashboard_domanda_url = reverse('domande_peo:dashboard_domanda',
                                    args=[bando.slug])

    page_title = 'Selezione Modulo di Inserimento'

    _breadcrumbs.reset()
    _breadcrumbs.add_url((dashboard_domanda_url, dashboard_domanda_title))
    _breadcrumbs.add_url(('#', page_title))

    context = {
        'page_title': page_title,
        'breadcrumbs': _breadcrumbs,
        'bando': bando,
        'dipendente': dipendente,
        'domanda_bando': domanda_bando,
        'indicatori_ponderati': indicatori_ponderati,
        #"categorie_titoli": categorie_titoli,
    }
    return render(request, "scelta_titolo_da_aggiungere.html", context=context)
Exemplo n.º 9
0
def dashboard_domanda(request, bando_id):
    """
        Pagina di gestione della propria domanda.
    """

    dipendente = get_object_or_404(Dipendente,
                                   matricola=request.user.matricola)
    bando = _get_bando_queryset(bando_id).first()

    # recupero la domanda peo del dipendente
    domanda_peo = DomandaBando.objects.filter(bando=bando,
                                              dipendente=dipendente)

    # se non c'è alcuna domanda, la creo
    # se la domanda c'è ma is_active==False, ritorno un messaggio di errore
    # altrimenti si prosegue con la domanda attualmente presente
    if domanda_peo:
        domanda_peo = domanda_peo.last()
    elif not domanda_peo:
        url = reverse('domande_peo:scelta_titolo_da_aggiungere',
                      args=[bando.slug])
        return HttpResponseRedirect(url)

    if not domanda_peo.modulodomandabando_set.all(
    ) and not domanda_peo.bando.indicatore_con_anzianita():
        url = reverse('domande_peo:scelta_titolo_da_aggiungere',
                      args=[bando.slug])
        return HttpResponseRedirect(url)

    if not domanda_peo.is_active:
        return render(
            request, 'custom_message.html', {
                'avviso': ("La tua Domanda è stata sospesa. Per avere "
                           "informazioni contatta l' Area Risorse Umane.")
            })

    page_title = 'Partecipazione Bando {}'.format(bando.nome)
    page_url = reverse('domande_peo:dashboard_domanda', args=[bando.slug])
    _breadcrumbs.reset()
    _breadcrumbs.add_url((page_url, page_title))

    context = {
        'page_title': page_title,
        'breadcrumbs': _breadcrumbs,
        'bando': bando,
        'dipendente': dipendente,
        'domanda_peo': domanda_peo
    }
    return render(request, "dashboard_domanda.html", context=context)
Exemplo n.º 10
0
def cancella_titolo(request, bando_id, modulo_compilato_id):
    """
        Deve essere chiamato da una dialog con checkbox di conferma
    """

    dipendente = get_object_or_404(Dipendente, matricola = request.user.matricola)
    bando = _get_bando_queryset(bando_id).first()
    mdb = get_object_or_404(ModuloDomandaBando,
                            pk=modulo_compilato_id,
                            domanda_bando__is_active=True,
                            domanda_bando__dipendente=dipendente)
    return_url = reverse('domande_peo:dashboard_domanda', args=[bando.pk,])
    return cancella_titolo_from_domanda(request,
                                        bando,
                                        dipendente,
                                        mdb,
                                        return_url,
                                        mark_domanda_as_modified=True,
                                        log=False)
Exemplo n.º 11
0
def cancella_domanda(request, bando_id, domanda_bando_id):
    """
        Deve essere chiamato da una dialog con checkbox di conferma
    """
    dipendente = get_object_or_404(Dipendente, matricola=request.user.matricola)
    bando = _get_bando_queryset(bando_id).first()

    domanda_bando = get_object_or_404(DomandaBando,
                                      pk=domanda_bando_id,
                                      dipendente=dipendente,
                                      is_active=True)

    domanda_bando.delete()

    # Rimuove la folder relativa alla DomandaPEO del dipendente, dello specifico Bando,
    # comprensiva di allegati ('modulo_compilato_id' NON passato come argomento)
    elimina_directory(request.user.matricola, bando.slug)

    url = reverse('risorse_umane:dashboard')
    return HttpResponseRedirect(url)
Exemplo n.º 12
0
    def new_func(*original_args, **original_kwargs):
        request = original_args[0]
        domanda = None

        if original_kwargs.get('modulo_compilato_id'):
            # views.modifica_titolo(request, bando_id, modulo_compilato_id)
            # views.cancella_titolo(request, bando_id, modulo_compilato_id)
            # views.elimina_allegato(request, bando_id, modulo_compilato_id, allegato)
            mdb = ModuloDomandaBando.objects.filter(
                pk=original_kwargs['modulo_compilato_id']).first()
            if mdb:
                domanda = mdb.domanda_bando
            else:
                raise Http404()
        elif original_kwargs.get('domanda_bando_id'):
            domanda = DomandaBando.objects.get(
                pk=original_kwargs['domanda_bando_id'])
        elif original_kwargs.get('bando_id'):
            # views.aggiungi_titolo(request, bando_id, descrizione_indicatore_id)
            # views.modifica_titolo(request, bando_id, modulo_compilato_id)
            # views.cancella_titolo(request, bando_id, modulo_compilato_id)
            # views.elimina_allegato(request, bando_id, modulo_compilato_id, allegato)
            # views.cancella_domanda(request, bando_id, domanda_bando_id)
            bando = _get_bando_queryset(original_kwargs['bando_id']).first()
            dipendente = get_object_or_404(Dipendente,
                                           matricola=request.user.matricola)
            domanda = DomandaBando.objects.get(bando=bando,
                                               dipendente=dipendente)
        if request.method == 'GET':
            return func_to_decorate(*original_args, **original_kwargs)
        elif request.method == 'POST':
            if domanda.modificabile():
                return func_to_decorate(*original_args, **original_kwargs)
            else:
                messages.error(
                    request,
                    'Non è possibile modificare una domanda già chiusa.')
                page_url = reverse('domande_peo:dashboard_domanda',
                                   args=[domanda.bando.slug]) + '#{}'.format(
                                       domanda.bando.slug)
                return HttpResponseRedirect(page_url)
Exemplo n.º 13
0
def riepilogo_domanda(request, bando_id, domanda_bando_id, pdf=None):
    """
        Esegue l'output in pdf
    """
    bando = _get_bando_queryset(bando_id).first()
    # se scarica un utente staff o un membro della commissione può accedervi
    if _user_is_staff_or_in_commission(request.user, bando):
        domanda_bando = get_object_or_404(DomandaBando,
                                          pk=domanda_bando_id,
                                          bando=bando)
    # altrimenti solo se l'utente è il proprietario e la domanda è attiva
    else:
        dipendente = get_object_or_404(Dipendente,
                                       matricola=request.user.matricola)
        domanda_bando = get_object_or_404(DomandaBando,
                                          pk=domanda_bando_id,
                                          bando=bando,
                                          dipendente=dipendente,
                                          is_active=True)
    page_title = 'Riepilogo Domanda'
    dashboard_domanda_title = 'Partecipazione Bando {}'.format(bando.nome)
    dashboard_domanda_url = reverse('domande_peo:dashboard_domanda',
                                    args=[bando.slug])

    _breadcrumbs.reset()
    _breadcrumbs.add_url((dashboard_domanda_url, dashboard_domanda_title))
    _breadcrumbs.add_url(('#', page_title))

    d = {
        'page_title': page_title,
        'breadcrumbs': _breadcrumbs,
        'bando': bando,
        'dipendente': domanda_bando.dipendente,
        'domanda_bando': domanda_bando,
        'MEDIA_URL': settings.MEDIA_URL
    }
    if pdf:
        return render(request, 'riepilogo_domanda_pdf.html', d)
    elif request.user != domanda_bando.dipendente.utente:
        return render(request, 'riepilogo_domanda_admin.html', d)
    return render(request, 'riepilogo_domanda.html', d)
Exemplo n.º 14
0
 def new_func(*original_args, **original_kwargs):
     request = original_args[0]
     dipendente = request.user.dipendente_set.filter(
         matricola=request.user.matricola).first()
     bando = _get_bando_queryset(original_kwargs['bando_id']).first()
     if not dipendente.carta_identita_front or not dipendente.carta_identita_retro:
         return render(
             request, 'custom_message.html', {
                 'avviso': ('Per utilizzare i servizi della '
                            'piattaforma è necessario caricare '
                            'il documento di identità')
             })
     elif request.user.is_staff and bando.collaudo:
         return func_to_decorate(*original_args, **original_kwargs)
     elif bando in dipendente.idoneita_peo_attivata():
         return func_to_decorate(*original_args, **original_kwargs)
     else:
         return render(
             request, 'custom_message.html', {
                 'avviso': ('Spiacenti ma non risulti '
                            'essere idoneo a partecipare')
             })
Exemplo n.º 15
0
def modifica_titolo(request, bando_id, modulo_compilato_id):
    """
        Costruisce form da PeodynamicForm
        li valida e salva i dati all'occorrenza

        remove_filefields prende il valore che concorre a selezionare il template readonly
        usato per readonly=pdf, inoltre rimuove i filefields dal form
    """
    dipendente = get_object_or_404(Dipendente,
                                   matricola=request.user.matricola)
    bando = _get_bando_queryset(bando_id).first()

    mdb = get_object_or_404(ModuloDomandaBando,
                            pk=modulo_compilato_id,
                            domanda_bando__is_active=True)

    # json_data = mdb.get_as_dict(allegati=False)
    descrizione_indicatore = mdb.descrizione_indicatore

    # Creo il form con i campi files=None e remove_filefields=False
    # perchè al momento della creazione non ci sono ovviamente allegati
    # già inseriti (ma se non setto remove_filefields=False il form
    # viene generato senza campi FileField)
    form = mdb.compiled_form(None, False)
    allegati = mdb.get_allegati_dict()

    # se non ci sono allegati preesistenti evita di distruggere il campo per
    # l'eventuale inserimento di un allegato
    if allegati:
        form.remove_files(allegati)

    # Nonostante sia reperibile anche da 'modulo_domanda_bando',
    # nel contesto devo passare anche 'descrizione_indicatore', altrimenti
    # nel breadcrumb di modulo_form.html non riesco a recuperare il nome.
    # Potrei anche duplicare la porzione di html del breadcrumb in modulo_form_modifica.html,
    # è indifferente

    dashboard_domanda_title = 'Partecipazione Bando {}'.format(bando.nome)
    dashboard_domanda_url = reverse('domande_peo:dashboard_domanda',
                                    args=[bando.slug])

    page_title = 'Modifica Inserimento: "({}) {}"'.format(
        descrizione_indicatore.id_code, descrizione_indicatore.nome)

    _breadcrumbs.reset()
    _breadcrumbs.add_url((dashboard_domanda_url, dashboard_domanda_title))
    _breadcrumbs.add_url(('#', page_title))

    d = {
        'page_title': page_title,
        'breadcrumbs': _breadcrumbs,
        'form': form,
        'dipendente': dipendente,
        'bando': bando,
        'modulo_domanda_bando': mdb,
        'allegati': allegati,
    }

    if request.method == 'POST':
        json_response = json.loads(get_POST_as_json(request))
        # Costruisco il form con il json dei dati inviati e tutti gli allegati
        json_response["allegati"] = allegati
        # rimuovo solo gli allegati che sono stati già inseriti
        form = descrizione_indicatore.get_form(json_response,
                                               request.FILES,
                                               mdb.domanda_bando.id,
                                               remove_filefields=allegati)
        if form.is_valid():
            if request.FILES:
                path_allegati = get_path_allegato(dipendente.matricola,
                                                  bando.slug, mdb.pk)
                for key, value in request.FILES.items():
                    form.validate_attachment(request.FILES[key])
                    salva_file(request.FILES[key], path_allegati,
                               request.FILES[key]._name)
                    nome_allegato = request.FILES[key]._name
                    json_response["allegati"]["{}".format(key)] = "{}".format(
                        nome_allegato)
            else:
                # Se non ho aggiornato i miei allegati lasciandoli invariati rispetto
                # all'inserimento precedente
                json_response["allegati"] = allegati

            # salva il modulo
            mdb.set_as_dict(json_response)
            # data di modifica
            mdb.mark_as_modified()
            #Allega il messaggio al redirect
            messages.success(request, 'Modifica effettuata con successo!')
            url = reverse('domande_peo:modifica_titolo',
                          args=[bando.pk, modulo_compilato_id])
            return HttpResponseRedirect(url + '#{}'.format(bando.slug))
        else:
            # il form non è valido, ripetere inserimento
            d['form'] = form

    return render(request, 'modulo_form_modifica.html', d)
Exemplo n.º 16
0
def aggiungi_titolo(request, bando_id, descrizione_indicatore_id):
    """
        Costruisce form da PeodynamicForm
        li valida e salva i dati all'occorrenza
    """
    dipendente = get_object_or_404(Dipendente,
                                   matricola=request.user.matricola)
    bando = _get_bando_queryset(bando_id).first()
    domanda_bando = get_object_or_404(DomandaBando,
                                      bando=bando,
                                      dipendente=dipendente,
                                      is_active=True)
    descrizione_indicatore = get_object_or_404(DescrizioneIndicatore,
                                               pk=descrizione_indicatore_id)

    # From gestione_peo/templatetags/indicatori_ponderati_tags
    if not descrizione_indicatore.is_available_for_cat_role(
            dipendente.livello.posizione_economica, dipendente.ruolo):
        return render(
            request, 'custom_message.html', {
                'avviso': ("La tua posizione o il tuo ruolo"
                           " risultano disabilitati"
                           " all'accesso a questo modulo.")
            })

    # From domande_peo/templatetags/domande_peo_tags
    if descrizione_indicatore.limite_inserimenti:
        mdb_presenti = domanda_bando.num_mdb_tipo_inseriti(
            descrizione_indicatore)
        if mdb_presenti == descrizione_indicatore.numero_inserimenti:
            return render(
                request, 'custom_message.html', {
                    'avviso': ("Hai raggiunto il numero di inserimenti"
                               " consentiti per questo modulo")
                })

    form = descrizione_indicatore.get_form(None, None, domanda_bando.id)

    dashboard_domanda_title = 'Partecipazione Bando {}'.format(bando.nome)
    dashboard_domanda_url = reverse('domande_peo:dashboard_domanda',
                                    args=[bando.slug])
    selezione_titolo_title = 'Selezione Modulo di Inserimento'
    selezione_titolo_url = reverse('domande_peo:scelta_titolo_da_aggiungere',
                                   args=[bando.slug])
    page_title = 'Modulo Inserimento: "({}) {}"'.format(
        descrizione_indicatore.id_code, descrizione_indicatore.nome)
    _breadcrumbs.reset()
    _breadcrumbs.add_url((dashboard_domanda_url, dashboard_domanda_title))
    _breadcrumbs.add_url((selezione_titolo_url, selezione_titolo_title))
    _breadcrumbs.add_url(('#', page_title))

    d = {
        'page_title': page_title,
        'breadcrumbs': _breadcrumbs,
        'form': form,
        'bando': bando,
        'dipendente': dipendente,
        'descrizione_indicatore': descrizione_indicatore
    }

    if request.method == 'POST':
        form = descrizione_indicatore.get_form(request.POST, request.FILES,
                                               domanda_bando.id)
        if form.is_valid():
            # qui chiedere conferma prima del salvataggio
            json_data = get_POST_as_json(request)
            mdb = ModuloDomandaBando.objects.create(
                domanda_bando=domanda_bando,
                modulo_compilato=json_data,
                descrizione_indicatore=descrizione_indicatore,
                modified=timezone.localtime(),
            )

            # salvataggio degli allegati nella cartella relativa
            # Ogni file viene rinominato con l'ID del ModuloDomandaBando
            # appena creato e lo "slug" del campo FileField
            json_stored = mdb.get_as_dict()
            if request.FILES:
                json_stored["allegati"] = {}
                path_allegati = get_path_allegato(dipendente.matricola,
                                                  bando.slug, mdb.pk)
                for key, value in request.FILES.items():
                    salva_file(request.FILES[key], path_allegati,
                               request.FILES[key]._name)
                    json_stored["allegati"]["{}".format(key)] = "{}".format(
                        request.FILES[key]._name)

            mdb.set_as_dict(json_stored)
            domanda_bando.mark_as_modified()
            #Allega il messaggio al redirect
            messages.success(request, 'Inserimento effettuato con successo!')

            url = reverse('domande_peo:dashboard_domanda', args=[
                bando.pk,
            ])
            return HttpResponseRedirect(url + '#{}'.format(bando.slug))
        else:
            # il form non è valido, ripetere inserimento
            d['form'] = form
            # print('ERRORE', request.POST)

    return render(request, 'modulo_form.html', d)
Exemplo n.º 17
0
def modifica_titolo(request, bando_id, modulo_compilato_id):
    """
        Costruisce form da PeodynamicForm
        li valida e salva i dati all'occorrenza

        remove_filefields prende il valore che concorre a selezionare il template readonly
        usato per readonly=pdf, inoltre rimuove i filefields dal form
    """
    dipendente = get_object_or_404(Dipendente,
                                   matricola=request.user.matricola)
    bando = _get_bando_queryset(bando_id).first()

    mdb = get_object_or_404(ModuloDomandaBando,
                            pk=modulo_compilato_id,
                            domanda_bando__is_active=True,
                            domanda_bando__dipendente=dipendente)

    descrizione_indicatore = mdb.descrizione_indicatore

    # Creo il form con i campi files=None e remove_filefields=False
    # perchè al momento della creazione non ci sono ovviamente allegati
    # già inseriti (ma se non setto remove_filefields=False il form
    # viene generato senza campi FileField)
    # form = mdb.compiled_form(files=None, remove_filefields=False)
    allegati = get_allegati_dict(mdb)
    form = mdb.compiled_form(remove_filefields=allegati)

    # form con i soli campi File da dare in pasto al tag della firma digitale
    form_allegati = descrizione_indicatore.get_form(remove_datafields=True)

    # Nonostante sia reperibile anche da 'modulo_domanda_bando',
    # nel contesto devo passare anche 'descrizione_indicatore', altrimenti
    # nel breadcrumb di modulo_form.html non riesco a recuperare il nome.
    # Potrei anche duplicare la porzione di html del breadcrumb in modulo_form_modifica.html,
    # è indifferente

    dashboard_domanda_title = 'Partecipazione Bando {}'.format(bando.nome)
    dashboard_domanda_url = reverse('domande_peo:dashboard_domanda',
                                    args=[bando.slug])

    path_allegati = get_path_allegato(dipendente.matricola, bando.slug, mdb.pk)

    page_title = 'Modifica Inserimento: "({}) {}"'.format(
        descrizione_indicatore.id_code, descrizione_indicatore.nome)

    _breadcrumbs.reset()
    _breadcrumbs.add_url((dashboard_domanda_url, dashboard_domanda_title))
    _breadcrumbs.add_url(('#', page_title))

    d = {
        'allegati': allegati,
        'bando': bando,
        'breadcrumbs': _breadcrumbs,
        'dipendente': dipendente,
        'form': form,
        'form_allegati': form_allegati,
        'modulo_domanda_bando': mdb,
        'page_title': page_title,
        'path_allegati': path_allegati,
    }

    if request.method == 'POST':
        return_url = reverse('domande_peo:modifica_titolo',
                             args=[bando.pk, modulo_compilato_id])
        result = modifica_titolo_form(
            request=request,
            bando=bando,
            descrizione_indicatore=descrizione_indicatore,
            mdb=mdb,
            allegati=allegati,
            path_allegati=path_allegati,
            return_url=return_url,
            log=False)
        if result:
            if isinstance(result, HttpResponseRedirect): return result
            for k in result:
                d[k] = result[k]

    d['labeled_errors'] = get_labeled_errors(d['form'])

    return render(request, 'modulo_form_modifica.html', d)
Exemplo n.º 18
0
def download_modulo_inserito_pdf(request, bando_id, modulo_compilato_id):
    """
        Esegue l'output in pdf
        riutilizzando le view precedenti evitiamo di rifare gli stessi controlli
        ricicliamo query e decoratori
    """
    dipendente = get_object_or_404(Dipendente,
                                   matricola=request.user.matricola)
    bando = _get_bando_queryset(bando_id).first()
    mdb = get_object_or_404(ModuloDomandaBando, pk=modulo_compilato_id)
    # se l'utente non fa parte dello staff e il pdf non gli appartiene nega l'accesso
    if not request.user.is_staff:
        mdb = ModuloDomandaBando.objects.filter(
            domanda_bando__dipendente=dipendente).first()
        if not mdb:
            return 404 ()

    descrizione_indicatore = mdb.descrizione_indicatore
    form = mdb.compiled_form(remove_filefields=True)
    d = {
        'form': form,
        'dipendente': dipendente,
        'bando': bando,
        'modulo_domanda_bando': mdb,
        'descrizione_indicatore': descrizione_indicatore
    }

    response = render(request, 'modulo_form_readonly_pdf.html', d)
    # file names
    pdf_fname = 'modulo_inserito_{}.pdf'.format(mdb.pk)
    pdf_path = settings.TMP_DIR + os.path.sep + pdf_fname

    # prendo il pdf principale
    main_pdf_file = response_as_pdf(response, pdf_fname).content
    merger = PdfFileMerger(strict=False)
    main_pdf_file = BytesIO(main_pdf_file)
    merger.append(main_pdf_file)
    try:
        # gli appendo gli allegati
        for allegato in mdb.get_allegati_path():
            merger.append(allegato)
        merger.write(pdf_path)

        # torno il tutto in response
        f = open(pdf_path, 'rb')
        response = HttpResponse(f.read(), content_type='application/pdf')
        response['Content-Disposition'] = 'inline; filename=' + pdf_fname
    except Exception as e:
        mdb_dict = mdb.get_as_dict()
        return render(
            request, 'custom_message.html', {
                'avviso':
                ("E' stato incorso un errore relativo alla interpretazione "
                 "dei file PDF da te immessi come allegato.<br>"
                 "Nello specifico: '{}' presenta delle anomalie di formato"
                 ". Questo è dovuto "
                 "al processo di produzione "
                 "del PDF. <br>E' necessario ricreare il PDF "
                 "con una procedura differente da quella "
                 "precedenemente utilizzata oppure, più "
                 "semplicemente, ristampare il PDF come file, "
                 "rimuovere il vecchio allegato dal modulo inserito "
                 "e caricare il nuovo appena ristampato/riconvertito.").format(
                     mdb_dict.get('allegati'))
            })
    # pulizia
    f.close()
    main_pdf_file.close()
    os.remove(pdf_path)
    return response
Exemplo n.º 19
0
def chiudi_apri_domanda(request, bando_id, domanda_bando_id, azione='chiudi'):
    """
    in base alla azione viene chiusa la domanda o riaperta
    se la domanda va protocollata se viene riaperta produce rettifica di protocollo
    """
    dipendente = get_object_or_404(Dipendente,
                                   matricola=request.user.matricola)
    bando = _get_bando_queryset(bando_id).first()

    domanda_bando = get_object_or_404(DomandaBando,
                                      pk=domanda_bando_id,
                                      dipendente=dipendente,
                                      is_active=True)
    # la rettifica è identica sia con protocollo che senza
    if azione == 'riapri':
        # creazione rettifica
        rettifica = RettificaDomandaBando.objects.create(
            domanda_bando=domanda_bando,
            data_chiusura=domanda_bando.data_chiusura,
            numero_protocollo=domanda_bando.numero_protocollo,
            data_protocollazione=domanda_bando.data_protocollazione,
        )
        # eventuale protocollo e data protocollo vengono sovrascritti solo ad ulteriore chiusura
        # se già protocollato e rettificato vale sempre quello già protocollato
        domanda_bando.data_chiusura = None
        domanda_bando.save()
        page_url = reverse('domande_peo:dashboard_domanda', args=[
            bando.pk,
        ])
        return HttpResponseRedirect(page_url)

    # check se protocollazione richiesta e se la domanda non è stata già chiusa
    if azione == 'chiudi' and not domanda_bando.data_chiusura:
        if bando.protocollo_required:
            peo_dict = {
                'wsdl_url':
                settings.PROT_URL,
                'username':
                settings.PROT_LOGIN,
                'password':
                settings.PROT_PASSW,
                'aoo':
                settings.PROT_AOO,
                'template_xml_flusso':
                bando.protocollo_template,
                'oggetto':
                '{} - {}'.format(bando, dipendente),
                # Variabili
                'matricola_dipendente':
                dipendente.matricola,
                'denominazione_persona':
                ' '.join((
                    dipendente.nome,
                    dipendente.cognome,
                )),

                # attributi creazione protocollo
                'id_titolario':
                bando.
                protocollo_cod_titolario,  # settings.PROTOCOLLO_TITOLARIO_DEFAULT,
                'fascicolo_numero':
                bando.
                protocollo_fascicolo_numero,  # settings.PROTOCOLLO_FASCICOLO_DEFAULT,
                'fascicolo_anno':
                timezone.localtime().year
            }

            protclass = __import__(settings.CLASSE_PROTOCOLLO, globals(),
                                   locals(), ['*'])
            wsclient = protclass.Protocollo(**peo_dict)

            docPrinc = BytesIO()
            docPrinc.write(
                download_domanda_pdf(request, bando_id,
                                     domanda_bando_id).content)
            docPrinc.seek(0)
            wsclient.aggiungi_docPrinc(
                docPrinc,
                nome_doc="domanda_{}_{}.pdf".format(dipendente.matricola,
                                                    bando.pk),
                tipo_doc='{} - {}'.format(bando.pk, dipendente.matricola))

            for modulo in domanda_bando.modulodomandabando_set.all():
                # aggiungi come allegati solo i moduli che hanno allegati
                if not modulo.get_allegati(): continue
                allegato = BytesIO()
                allegato.write(
                    download_modulo_inserito_pdf(request, bando_id,
                                                 modulo.pk).content)
                allegato.seek(0)
                wsclient.aggiungi_allegato(
                    nome="domanda_{}_{}-{}.pdf".format(dipendente, bando.pk,
                                                       modulo.pk),
                    descrizione='{} - {}'.format(
                        modulo.descrizione_indicatore.id_code,
                        modulo.get_identificativo_veloce()),
                    fopen=allegato)
            # print(wsclient.is_valid())
            if settings.DEBUG: print(wsclient.render_dataXML())
            prot_resp = wsclient.protocolla()
            domanda_bando.numero_protocollo = wsclient.numero
            domanda_bando.data_protocollazione = timezone.localtime()
            # se non torna un numero di protocollo emerge l'eccezione
            assert wsclient.numero

        # chiusura in locale
        domanda_bando.data_chiusura = timezone.localtime()
        domanda_bando.save()

        # invio email di notifica
        if bando.email_avvenuto_completamento and request.user.email:
            smd = {
                'url':
                settings.URL,
                'domanda_url':
                reverse('domande_peo:riepilogo_domanda',
                        args=[bando.pk, domanda_bando.pk]),
                'bando':
                bando,
                'dipendente':
                dipendente
            }
            send_mail(
                gestione_peo.settings.COMPLETE_EMAIL_SUBJECT.format(bando),
                gestione_peo.settings.COMPLETE_EMAIL_BODY.format(**smd),
                gestione_peo.settings.COMPLETE_EMAIL_SENDER, [
                    request.user.email,
                ],
                fail_silently=False,
                auth_user=None,
                auth_password=None,
                connection=None,
                html_message=None)
    domanda_bando.mark_as_modified()

    _breadcrumbs.add_url(('#', 'Chiusura Domanda'))
    d = {
        'bando': domanda_bando.bando,
        'domanda_peo': domanda_bando,
        'dipendente': dipendente,
        'MEDIA_URL': settings.MEDIA_URL
    }
    return render(request, 'chiusura_domanda.html', d)
Exemplo n.º 20
0
def aggiungi_titolo(request, bando_id, descrizione_indicatore_id):
    """
        Costruisce form da PeodynamicForm
        li valida e salva i dati all'occorrenza
    """
    dipendente = get_object_or_404(Dipendente,
                                   matricola=request.user.matricola)
    bando = _get_bando_queryset(bando_id).first()
    domanda_bando = get_object_or_404(DomandaBando,
                                      bando=bando,
                                      dipendente=dipendente,
                                      is_active=True)
    descrizione_indicatore = get_object_or_404(DescrizioneIndicatore,
                                               pk=descrizione_indicatore_id)

    # From gestione_peo/templatetags/indicatori_ponderati_tags
    if not descrizione_indicatore.is_available_for_cat_role(
            dipendente.livello.posizione_economica, dipendente.ruolo):
        return render(
            request, 'custom_message.html', {
                'avviso': ("La tua posizione o il tuo ruolo"
                           " risultano disabilitati"
                           " all'accesso a questo modulo.")
            })

    # From domande_peo/templatetags/domande_peo_tags
    if descrizione_indicatore.limite_inserimenti:
        mdb_presenti = domanda_bando.num_mdb_tipo_inseriti(
            descrizione_indicatore)
        if mdb_presenti == descrizione_indicatore.numero_inserimenti:
            return render(
                request, 'custom_message.html', {
                    'avviso': ("Hai raggiunto il numero di inserimenti"
                               " consentiti per questo modulo")
                })

    form = descrizione_indicatore.get_form(data=None,
                                           files=None,
                                           domanda_bando=domanda_bando)

    dashboard_domanda_title = 'Partecipazione Bando {}'.format(bando.nome)
    dashboard_domanda_url = reverse('domande_peo:dashboard_domanda',
                                    args=[bando.slug])
    selezione_titolo_title = 'Selezione Modulo di Inserimento'
    selezione_titolo_url = reverse('domande_peo:scelta_titolo_da_aggiungere',
                                   args=[bando.slug])
    page_title = 'Modulo Inserimento: "({}) {}"'.format(
        descrizione_indicatore.id_code, descrizione_indicatore.nome)
    _breadcrumbs.reset()
    _breadcrumbs.add_url((dashboard_domanda_url, dashboard_domanda_title))
    _breadcrumbs.add_url((selezione_titolo_url, selezione_titolo_title))
    _breadcrumbs.add_url(('#', page_title))

    d = {
        'page_title': page_title,
        'breadcrumbs': _breadcrumbs,
        'form': form,
        'bando': bando,
        'dipendente': dipendente,
        'descrizione_indicatore': descrizione_indicatore
    }

    if request.method == 'POST':
        return_url = reverse('domande_peo:dashboard_domanda',
                             args=[
                                 bando.pk,
                             ])
        result = aggiungi_titolo_form(
            request=request,
            bando=bando,
            descrizione_indicatore=descrizione_indicatore,
            domanda_bando=domanda_bando,
            dipendente=dipendente,
            return_url=return_url,
            log=False)
        if result:
            if isinstance(result, HttpResponseRedirect): return result
            for k in result:
                d[k] = result[k]

    d['labeled_errors'] = get_labeled_errors(d['form'])

    return render(request, 'modulo_form.html', d)