Exemplo n.º 1
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.º 2
0
 def compiled_form(self, files=None,
                   remove_filefields=True,
                   remove_datafields=False):
     """
     Torna il form compilato senza allegati
     """
     modulo = self.get_form_module()
     if not modulo: return None
     extra_datas = {}
     extra_datas[TICKET_SUBJECT_ID] = self.subject
     extra_datas[TICKET_DESCRIPTION_ID] = self.description
     form = SavedFormContent.compiled_form(data_source=self.modulo_compilato,
                                           extra_datas=extra_datas,
                                           files=files,
                                           remove_filefields=remove_filefields,
                                           remove_datafields=remove_datafields,
                                           form_source=modulo)
     # modulo = self.get_form_module()
     # if not modulo: return False
     # json_dict = json.loads(self.modulo_compilato)
     # data = get_as_dict(compiled_module_json=json_dict,
                        # allegati=False)
     # data[TICKET_SUBJECT_ID] = self.subject
     # data[TICKET_DESCRIPTION_ID] = self.description
     # form = modulo.get_form(data=data,
                            # files=files,
                            # remove_filefields=remove_filefields,
                            # remove_datafields=remove_datafields)
     return form
Exemplo n.º 3
0
 def compiled_form(self,
                   files=None,
                   remove_filefields=True,
                   other_form_source=None):
     """
     Restituisce il form compilato senza allegati
     Integra django_form_builder.models.SavedFormContent.compiled_form
     """
     # imposta la classe che fornirà il metodo get_form()
     # other_form_source è una DescrizioneIndicatore forzata come argomento
     form_source = other_form_source or self.descrizione_indicatore
     form = SavedFormContent.compiled_form(data_source=self.modulo_compilato,
                                           files=files,
                                           remove_filefields=remove_filefields,
                                           form_source=form_source,
                                           domanda_bando=self.domanda_bando)
     return form
Exemplo n.º 4
0
def change_password(request):
    lu = LdapAcademiaUser.objects.filter(dn=request.user.dn).first()
    form = PasswordChangeForm(request.POST)

    delivery_dict = get_ldapuser_attrs_from_formbuilder_conf(lu)

    dyn_form = SavedFormContent.compiled_form(
        data_source=json.dumps(delivery_dict),
        constructor_dict=settings.DJANGO_FORM_BUILDER_FIELDS,
        ignore_format_field_name=True)

    d = {
        'form_delivery': dyn_form,
        'form_password': form,
        'lu': lu,
        'attrs': get_ldapuser_aai_html_attrs(lu)
    }

    if not form.is_valid():
        for k, v in get_labeled_errors(form).items():
            messages.add_message(request, messages.ERROR,
                                 "<b>{}</b>: {}".format(k, strip_tags(v)))
        return redirect('provisioning:dashboard')
    if lu.check_pwdHistory(form.cleaned_data['password']):
        messages.add_message(
            request, messages.ERROR,
            settings.MESSAGES_ALERT_TEMPLATE_DESC.format(
                **PASSWORD_ALREADYUSED))
        return redirect('provisioning:dashboard')
    try:
        lu.set_password(password=form.cleaned_data['password'],
                        old_password=form.cleaned_data['old_password'])
    except Exception as e:
        return render(request,
                      'custom_message.html',
                      INVALID_DATA_DISPLAY,
                      status=403)
    lu.set_default_schacExpiryDate()
    send_email_password_changed(lu, request)
    messages.add_message(
        request, messages.SUCCESS,
        settings.MESSAGES_ALERT_TEMPLATE.format(**PASSWORD_CHANGED))
    return redirect('provisioning:dashboard')
Exemplo n.º 5
0
    def get_modulo_anteprima(self, obj):
        json_dict = json.loads(obj.modulo_compilato)
        data = get_as_dict(json_dict, allegati=False)
        allegati = get_allegati(obj)
        form = SavedFormContent.compiled_form_readonly(obj.compiled_form())

        table_tmpl = '<table margin-left: 15px;">{}</table>'
        allegati_html = ''

        for k, v in allegati:
            allegato_url = reverse(
                'domande_peo:download_allegato',
                args=[obj.domanda_bando.bando.pk, obj.pk, k])
            allegati_html += '<tr><td>{}</td><td><a href="{}">{}</a><td></tr>'.format(
                k, allegato_url, v)

        value = form.as_table()
        v = table_tmpl.format(value)
        return mark_safe(v + table_tmpl.format(allegati_html))
Exemplo n.º 6
0
 def compiled_form(self,
                   files=None,
                   remove_filefields=True,
                   remove_datafields=False):
     """
     Torna il form compilato senza allegati
     """
     modulo = self.get_form_module()
     if not modulo: return None
     extra_datas = {}
     extra_datas[settings.TICKET_SUBJECT_ID] = self.subject
     extra_datas[settings.TICKET_DESCRIPTION_ID] = self.description
     form = SavedFormContent.compiled_form(
         data_source=json.dumps(self.get_modulo_compilato()),
         extra_datas=extra_datas,
         files=files,
         remove_filefields=remove_filefields,
         remove_datafields=remove_datafields,
         form_source=modulo)
     return form
Exemplo n.º 7
0
def dashboard(request):
    d = {}
    if request.user.dn:
        try:
            lu = LdapAcademiaUser.objects.filter(dn=request.user.dn).first()
        except ldap.NO_SUCH_OBJECT as e:
            _msg = 'request.user {} authenticated but his DN dows not match with {}.'.format(
                request.user, request.user.dn)
            logger.error(_msg)
            return render(request,
                          'custom_message.html',
                          USER_DEFINITION_ERROR,
                          status=500)
        if not lu:
            return render(request,
                          'custom_message.html',
                          USER_DEFINITION_ERROR,
                          status=403)

        if not lu.schacExpiryDate:
            lu.set_default_schacExpiryDate()

        delivery_dict = get_ldapuser_attrs_from_formbuilder_conf(lu)
        dyn_form = SavedFormContent.compiled_form(
            data_source=json.dumps(delivery_dict),
            constructor_dict=settings.DJANGO_FORM_BUILDER_FIELDS,
            ignore_format_field_name=True)
        d = {'form_delivery': dyn_form,
             'password_reset_form': PasswordChangeForm(),
             'form_profile': ProfileForm(initial={'access_notification': \
                                                  request.user.access_notification}),
             'lu': lu,
             'attrs': get_ldapuser_aai_html_attrs(lu),
             'expiration_days': (lu.schacExpiryDate - timezone.localtime()).days}
        return render(request, 'dashboard.html', d)
    return render(request, 'empty_dashboard.html')
Exemplo n.º 8
0
def change_data(request, token_value=None):
    lu = LdapAcademiaUser.objects.filter(dn=request.user.dn).first()
    if request.method == 'GET' and token_value:
        # check token validity and commit changes
        id_prov = get_object_or_404(IdentityLdapChangeConfirmation,
                                    token=token_value)
        if not id_prov.token_valid():
            return render(request,
                          'custom_message.html',
                          INVALID_TOKEN_DISPLAY,
                          status=403)

        data = json.loads(id_prov.new_data)
        if 'access_notification' in data.keys():
            request.user.access_notification = data.pop('access_notification')
            request.user.save()

        for i in data:
            if not hasattr(lu, i): continue
            attr = getattr(lu, i)
            if isinstance(attr, list):
                if attr:
                    attr[0] = data[i]
                else:
                    attr.append(data[i])
            else:
                setattr(lu, i, data[i])
        try:
            lu.save()
            id_prov.mark_as_used()
        except ldap.CONSTRAINT_VIOLATION:
            logger.error(
                _('Error, {} tried to save data that violates a '
                  'LDAP constraint with : {}').format(lu, json.dumps(data)))
            return render(request,
                          'custom_message.html',
                          DATA_NOT_CHANGED,
                          status=403)

        return render(request, 'custom_message.html', DATA_CHANGED)

    elif request.method == 'POST':
        form = SavedFormContent.compiled_form(
            data_source=json.dumps(request.POST),
            constructor_dict=settings.DJANGO_FORM_BUILDER_FIELDS,
            ignore_format_field_name=True)
        d = {'form_delivery': form,
             'form_password': PasswordForm(),
             'form_profile': ProfileForm(initial={'access_notification': \
                                                  request.user.access_notification}),
             'lu': lu,
             'attrs': get_ldapuser_aai_html_attrs(lu)}

        if not form.is_valid():
            for k, v in get_labeled_errors(form).items():
                messages.add_message(request, messages.ERROR,
                                     "<b>{}</b>: {}".format(k, strip_tags(v)))
            return render(request, 'dashboard.html', d)

        # create token
        current_data = {}
        new_data = {k: v for k, v in form.cleaned_data.items()}
        for k in form.cleaned_data:
            if hasattr(lu, k): attr = getattr(lu, k)
            else: del new_data[k]
            if isinstance(attr, list):
                current_data[k] = attr[0] if attr else []
            else:
                current_data[k] = attr

        # profile options
        form_profile = ProfileForm(request.POST)
        if not form_profile.is_valid():
            return render(request, 'dashboard.html', d)

        access_notification = form_profile.cleaned_data.get(
            'access_notification')
        # Exclude processing if data aren't changed
        if request.user.access_notification != access_notification:
            new_data['access_notification'] = access_notification
            current_data[
                'access_notification'] = request.user.access_notification

        # data was not changed
        if current_data == new_data or not new_data:
            messages.add_message(request, messages.SUCCESS,
                                 _("No data edited"))
            return redirect('provisioning:dashboard')

        data = dict(ldap_dn=lu.dn,
                    is_active=True,
                    current_data=json.dumps(current_data),
                    new_data=json.dumps(new_data))
        data_check = {k: v for k, v in data.items()}
        id_change_conf = IdentityLdapChangeConfirmation.objects.filter(
            **data_check).first()
        if not id_change_conf or not id_change_conf.token_valid():
            id_change_conf = IdentityLdapChangeConfirmation.objects.create(
                **data)
            # send_email here. Only on creation
            id_change_conf.send_email(ldap_user=lu, lang=request.LANGUAGE_CODE)
        # messages.add_message(request, messages.SUCCESS,
        # settings.MESSAGES_ALERT_TEMPLATE_DESC.format(**CONFIRMATION_EMAIL))
        # return redirect('provisioning:dashboard')
        return render(request, 'custom_message.html', CONFIRMATION_EMAIL)
    else:
        return render(request,
                      'custom_message.html',
                      INVALID_DATA_DISPLAY,
                      status=403)
Exemplo n.º 9
0
def domanda_bando_readonly(compiled_form_source):
    form = compiled_form_source.compiled_form()
    return SavedFormContent.compiled_form_readonly(form=form,
                                                   fields_to_remove=[ETICHETTA_INSERIMENTI_ID,])