def dynform(request): if request.method == 'GET': form = BaseDynamicForm.get_form( constructor_dict=constructor_dict, #data=data, #files=files, remove_filefields=False, remove_datafields=False) # if POST (form submitted) else: form = BaseDynamicForm.get_form(constructor_dict=constructor_dict, data=request.POST, files=request.FILES, remove_filefields=False, remove_datafields=False) if form.is_valid(): messages.add_message(request, messages.SUCCESS, "form is valid") else: # show all error messages for k, v in get_labeled_errors(form).items(): messages.add_message(request, messages.ERROR, "<b>{}</b>: {}".format(k, strip_tags(v))) d = {'form': form} return render(request, "form.html", d)
def test_float_invalid_2(self): """ Test invalid value in PositiveFloatField """ form = self.single_field_form('PositiveFloatField', 4.3333) logger.info("Test invalid PositiveFloatField") logger.info(get_labeled_errors(form)) self.assertFalse(form.is_valid())
def test_integer_invalid(self): """ Test invalid value in PositiveIntegerField Decimal value instead of Integer """ form = self.single_field_form('PositiveIntegerField', 16e50) logger.info("Test invalid PositiveIntegerField") logger.info(get_labeled_errors(form)) self.assertFalse(form.is_valid())
def ticket_close(request, ticket_id): """ Ticket closing by owner user :param ticket_id: String :type ticket_id: ticket code :return: render """ ticket = get_object_or_404(Ticket, code=ticket_id) if ticket.is_closed: # log action logger.info('[{}] user {} tried to close ' ' the already closed ticket {}'.format( timezone.now(), request.user, ticket)) return custom_message(request, _("Il ticket è già chiuso!")) title = _('Chiusura del ticket') sub_title = ticket form = ChiusuraForm() if request.method == 'POST': form = ChiusuraForm(request.POST) if form.is_valid(): motivazione = form.cleaned_data['note'] ticket.is_closed = True ticket.closing_reason = motivazione ticket.closed_date = timezone.now() ticket.save( update_fields=['is_closed', 'closing_reason', 'closed_date']) ticket.update_log(user=request.user, note=_( "Chiusura ticket: {}".format(motivazione))) messages.add_message( request, messages.SUCCESS, _("Ticket {} chiuso correttamente".format(ticket))) # log action logger.info('[{}] user {} closed ticket {}'.format( timezone.now(), request.user, ticket)) return redirect('uni_ticket:ticket_detail', ticket.code) else: for k, v in get_labeled_errors(form).items(): messages.add_message(request, messages.ERROR, "<b>{}</b>: {}".format(k, strip_tags(v))) template = "user/ticket_close.html" d = { 'form': form, 'sub_title': sub_title, 'ticket': ticket, 'title': title, } return render(request, template, d)
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')
def ticket_close(request, ticket_id): """ Ticket closing by owner user :param ticket_id: String :type ticket_id: ticket code :return: render """ ticket = get_object_or_404(Ticket, code=ticket_id) # Se il ticket non è chiudibile (per dipendenze attive) if ticket.is_closed: return custom_message(request, _("Il ticket è già chiuso!")) title = _('Chiusura del ticket') sub_title = ticket form = ChiusuraForm() if request.method=='POST': form = ChiusuraForm(request.POST) if form.is_valid(): motivazione = request.POST.get('note') ticket.is_closed = True ticket.motivazione_chiusura = motivazione ticket.data_chiusura = timezone.now() ticket.save(update_fields = ['is_closed', 'motivazione_chiusura', 'data_chiusura']) ticket.update_history(user = request.user, note = _("Chiusura ticket: {}".format(motivazione))) messages.add_message(request, messages.SUCCESS, _("Ticket {} chiuso correttamente".format(ticket))) return redirect('uni_ticket:ticket_detail', ticket.code) else: for k,v in get_labeled_errors(form).items(): messages.add_message(request, messages.ERROR, "<b>{}</b>: {}".format(k, strip_tags(v))) template = "user/ticket_close.html" d = {'form': form, 'sub_title': sub_title, 'ticket': ticket, 'title': title,} return render(request, template, d)
def ticket_message(request, ticket_id): """ Ticket messages page :param ticket_id: String :type ticket_id: ticket code :return: render """ ticket = get_object_or_404(Ticket, code=ticket_id) title = _("Messaggi") sub_title = ticket # Conversazione utente-operatori ticket_replies = TicketReply.objects.filter(ticket=ticket) form = ReplyForm() if ticket.is_open(): agent_replies = ticket_replies.exclude(owner=ticket.created_by, structure=None).filter(read_by=None) for reply in agent_replies: reply.read_by = request.user reply.read_date = timezone.now() reply.save(update_fields = ['read_by', 'read_date']) if request.method == 'POST': if not ticket.is_open(): return custom_message(request, _("Il ticket non è modificabile")) form = ReplyForm(request.POST, request.FILES) if form.is_valid(): ticket_reply = TicketReply() ticket_reply.subject = request.POST.get('subject') ticket_reply.text = request.POST.get('text') ticket_reply.attachment = request.FILES.get('attachment') ticket_reply.ticket = ticket ticket_reply.owner = request.user ticket_reply.save() # Send mail to ticket owner mail_params = {'hostname': settings.HOSTNAME, 'status': _('submitted'), 'ticket': ticket, 'user': request.user } m_subject = _('{} - ticket {} message submitted'.format(settings.HOSTNAME, ticket)) send_custom_mail(subject=m_subject, body=USER_TICKET_MESSAGE.format(**mail_params), recipient=request.user) # END Send mail to ticket owner messages.add_message(request, messages.SUCCESS, _("Messaggio inviato con successo")) return redirect('uni_ticket:ticket_message', ticket_id=ticket_id) else: for k,v in get_labeled_errors(form).items(): messages.add_message(request, messages.ERROR, "<b>{}</b>: {}".format(k, strip_tags(v))) d={'form': form, 'sub_title': sub_title, 'ticket': ticket, 'ticket_replies': ticket_replies, 'title': title,} template='user/ticket_assistance.html' return render(request, template, d)
def change_username(request, token_value=None): """ Ask a token to change his username """ _err_msg = None if not request.user.change_username: _err_msg = CANNOT_CHANGE_USERNAME elif ChangedUsername.objects.filter( Q(new_username=request.user.username) | Q(old_username=request.user.username)): _err_msg = ALREADY_CHANGED_USERNAME if _err_msg: return render(request, 'custom_message.html', _err_msg, status=403) 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) # logout first user = get_user_model().objects.get(username=request.user.username) logout(request) # Change username, uid and create a ChangedUsername record user = change_user_username(user=user, lu=lu, new_username=data['uid']) id_prov.mark_as_used() # Logout and redirect to login page # messages.add_message( request, messages.SUCCESS, settings.MESSAGES_ALERT_TEMPLATE_DESC.format( **USERNAME_SUCCESSIFULLY_CHANGED)) return redirect('provisioning:provisioning_login') elif request.method == 'GET': return render(request, 'provisioning_change_username.html', dict(change_username_form=IdentityUsernameChangeForm())) elif request.method == 'POST': form = IdentityUsernameChangeForm(request.POST) if form.is_valid(): old_username = form.cleaned_data['old_username'] new_username = form.cleaned_data['new_username'] user_username_match = old_username == request.user.username lu_uid_match = old_username == lu.uid _err_msg = None # If lu.uid and user.username don't match if not user_username_match or not lu_uid_match: _err_msg = settings.MESSAGES_ALERT_TEMPLATE_DESC.format( **NOT_YOUR_USERNAME) # If user has already changed if ChangedUsername.objects.filter(new_username=lu.uid): _err_msg = settings.MESSAGES_ALERT_TEMPLATE_DESC.format( **ALREADY_CHANGED_USERNAME) # If new username is in blacklist # If username exists in Django users if ChangedUsername.objects.filter(old_username=new_username) or \ get_user_model().objects.filter(username=new_username): _err_msg = settings.MESSAGES_ALERT_TEMPLATE_DESC.format( **USERNAME_IN_BLACKLIST) if _err_msg: messages.add_message(request, messages.ERROR, _err_msg) return redirect('provisioning:change_username') # create token current_data = {'uid': lu.uid} new_data = {'uid': form.cleaned_data['new_username']} 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') 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:change_username')
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)
def ticket_add_new(request, struttura_slug, categoria_slug): """ Create the ticket :type structure_slug: String :type categoria_slug: String :param structure_slug: slug of structure :param categoria_slug: slug of category :return: render """ if Ticket.number_limit_reached_by_user(request.user): messages.add_message(request, messages.ERROR, _("Hai raggiunto il limite massimo giornaliero" " di ticket: {}".format(MAX_DAILY_TICKET_PER_USER))) return redirect(reverse('uni_ticket:user_dashboard')) struttura = get_object_or_404(OrganizationalStructure, slug=struttura_slug, is_active=True) categoria = get_object_or_404(TicketCategory, slug=categoria_slug, is_active=True) if not categoria.allowed_to_user(request.user): return custom_message(request, _("Permesso negato a questa tipologia di utente."), struttura.slug) title = _("Apri un nuovo ticket") template = 'user/ticket_add_new.html' sub_title = _("Compila i campi richiesti") modulo = get_object_or_404(TicketCategoryModule, ticket_category=categoria, is_active=True) form = modulo.get_form(show_conditions=True) clausole_categoria = categoria.get_conditions() d={'categoria': categoria, 'conditions': clausole_categoria, 'form': form, 'struttura': struttura, 'sub_title': sub_title, 'title': title} if request.POST: form = modulo.get_form(data=request.POST, files=request.FILES, show_conditions=True) d['form'] = form if form.is_valid(): fields_to_pop = [TICKET_CONDITIONS_FIELD_ID, TICKET_SUBJECT_ID, TICKET_DESCRIPTION_ID] json_data = get_POST_as_json(request=request, fields_to_pop=fields_to_pop) # make a UUID based on the host ID and current time code = uuid_code() subject = request.POST.get(TICKET_SUBJECT_ID) description = request.POST.get(TICKET_DESCRIPTION_ID) ticket = Ticket(code=code, subject=subject, description=description, modulo_compilato=json_data, created_by=request.user, input_module=modulo) ticket.save() # salvataggio degli allegati nella cartella relativa json_dict = json.loads(ticket.modulo_compilato) json_stored = get_as_dict(compiled_module_json=json_dict) if request.FILES: json_stored["allegati"] = {} path_allegati = get_path_allegato(ticket) for key, value in request.FILES.items(): salva_file(request.FILES.get(key), path_allegati, request.FILES.get(key)._name) value = request.FILES.get(key)._name json_stored["allegati"]["{}".format(key)]="{}".format(value) set_as_dict(ticket, json_stored) office = categoria.organizational_office or struttura.get_default_office() if not office: messages.add_message(request, messages.ERROR, _("Nessun ufficio di default impostato")) return redirect(reverse('uni_ticket:user_dashboard')) ticket_assignment = TicketAssignment(ticket=ticket, office=office, assigned_by=request.user) ticket_assignment.save() ticket_detail_url = reverse('uni_ticket:ticket_detail', args=[code]) # Send mail to ticket owner mail_params = {'hostname': settings.HOSTNAME, 'user': request.user, 'status': _('submitted'), 'ticket': ticket } m_subject = _('{} - ticket {} submitted'.format(settings.HOSTNAME, ticket)) send_custom_mail(subject = m_subject, body=NEW_TICKET_UPDATE.format(**mail_params), recipient=request.user) # END Send mail to ticket owner messages.add_message(request, messages.SUCCESS, _("Ticket creato con successo " "con il codice <b>{}</b>").format(code)) return redirect('uni_ticket:ticket_detail', ticket_id=ticket.code) else: 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, template, d)
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)
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)
def commissione_domanda_aggiungi_titolo(request, commissione_id, domanda_id, descrizione_indicatore_id, commissione, commissione_user): """ Costruisce form da PeodynamicForm li valida e salva i dati all'occorrenza """ bando = commissione.bando # recupero la domanda peo del dipendente domanda_bando = get_object_or_404(DomandaBando, pk=domanda_id, bando=bando) dipendente = domanda_bando.dipendente 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 posizione o il ruolo del dipendente" " risultano disabilitati" " all'accesso a 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) url_commissioni = reverse('gestione_peo:commissioni') url_commissione = reverse('gestione_peo:dettaglio_commissione', args=[commissione_id]) url_manage = reverse('gestione_peo:manage_commissione', args=[commissione_id]) url_domanda = reverse('gestione_peo:commissione_domanda_manage', args=[commissione_id, domanda_id]) url_scelta_titolo = reverse( 'gestione_peo:commissione_domanda_scegli_titolo', args=[commissione_id, domanda_id]) page_url = reverse( 'gestione_peo:commissione_domanda_aggiungi_titolo', args=[commissione_id, domanda_id, descrizione_indicatore_id]) page_title = 'Selezione Modulo di Inserimento' _breadcrumbs.reset() _breadcrumbs.add_url((url_commissioni, 'Commissioni')) _breadcrumbs.add_url((url_commissione, commissione)) _breadcrumbs.add_url((url_manage, 'Gestione domande')) _breadcrumbs.add_url((url_domanda, 'Domanda {}'.format(domanda_bando))) _breadcrumbs.add_url((url_scelta_titolo, 'Scegli titolo')) _breadcrumbs.add_url((page_url, page_title)) commissioni = get_commissioni_attive(request.user) commissioni_in_corso = get_commissioni_in_corso(request.user, commissioni) d = { 'commissione': commissione, 'commissioni': commissioni, 'commissioni_in_corso': commissioni_in_corso, 'domanda_bando': domanda_bando, 'page_title': page_title, 'breadcrumbs': _breadcrumbs, 'form': form, 'bando': bando, 'dipendente': dipendente, 'descrizione_indicatore': descrizione_indicatore } if request.method == 'POST': return_url = reverse('gestione_peo:commissione_domanda_manage', args=[ commissione_id, domanda_id, ]) result = aggiungi_titolo_form( request=request, bando=bando, descrizione_indicatore=descrizione_indicatore, domanda_bando=domanda_bando, dipendente=dipendente, return_url=return_url, log=True) 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, 'commissione_modulo_form.html', d)
def commissione_modulo_domanda_modifica(request, commissione_id, domanda_id, modulo_id, commissione, commissione_user): """ 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 """ bando = commissione.bando domanda_bando = get_object_or_404(DomandaBando, pk=domanda_id, bando=bando) dipendente = domanda_bando.dipendente mdb = get_object_or_404(ModuloDomandaBando, pk=modulo_id, domanda_bando__dipendente=dipendente) descrizione_indicatore = mdb.descrizione_indicatore allegati = get_allegati_dict(mdb) form = mdb.compiled_form(remove_filefields=allegati) form_allegati = descrizione_indicatore.get_form(remove_datafields=True) 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) page_url = reverse('gestione_peo:commissione_modulo_domanda_modifica', args=[commissione_id, domanda_id, modulo_id]) url_commissioni = reverse('gestione_peo:commissioni') url_commissione = reverse('gestione_peo:dettaglio_commissione', args=[commissione_id]) url_manage = reverse('gestione_peo:manage_commissione', args=[commissione_id]) url_domanda = reverse('gestione_peo:commissione_domanda_manage', args=[commissione_id, domanda_id]) _breadcrumbs.reset() _breadcrumbs.add_url((url_commissioni, 'Commissioni')) _breadcrumbs.add_url((url_commissione, commissione)) _breadcrumbs.add_url((url_manage, 'Gestione domande')) _breadcrumbs.add_url((url_domanda, 'Domanda {}'.format(domanda_bando))) _breadcrumbs.add_url((page_url, page_title)) commissioni = get_commissioni_attive(request.user) commissioni_in_corso = get_commissioni_in_corso(request.user, commissioni) d = { 'allegati': allegati, 'bando': bando, 'breadcrumbs': _breadcrumbs, 'commissione': commissione, 'commissioni': commissioni, 'commissioni_in_corso': commissioni_in_corso, 'dipendente': dipendente, 'domanda_bando': domanda_bando, 'form': form, 'form_allegati': form_allegati, 'modulo_domanda_bando': mdb, 'page_title': page_title, 'path_allegati': path_allegati, } if request.method == 'POST': if request.POST.get('disable_input'): disabilita_abilita = request.POST.get( 'disabilita_abilita_inserimento') motivazione = request.POST.get('motivazione') or mdb.disabilita if disabilita_abilita and motivazione: etichetta = mdb.get_identificativo_veloce() mdb.disabilita = not mdb.disabilita mdb.motivazione = motivazione mdb.save(update_fields=['disabilita', 'motivazione']) if mdb.disabilita: msg = ( "Inserimento {} - Etichetta: {} - disabilitato con successo" ).format(mdb, etichetta) else: msg = ( "Inserimento {} - Etichetta: {} - abilitato con successo" ).format(mdb, etichetta) messages.add_message(request, messages.SUCCESS, msg) # Logging di ogni azione compiuta sulla domanda dalla commissione LogEntry.objects.log_action( user_id=request.user.pk, content_type_id=ContentType.objects.get_for_model( domanda_bando).pk, object_id=domanda_bando.pk, object_repr=domanda_bando.__str__(), action_flag=CHANGE, change_message=msg) # Per evitare che al refresh # possa essere effettuata una nuova richiesta POST url = reverse('gestione_peo:commissione_domanda_manage', args=[commissione_id, domanda_id]) return HttpResponseRedirect("{}#{}".format(url, mdb.pk)) else: msg = ( "Per disabilitare un inserimento è necessario inserire una motivazione" ) messages.add_message(request, messages.ERROR, msg) else: if mdb.added_by_user(): return render( request, 'custom_message.html', { 'avviso': ("Impossibile modificare inserimenti creati dal dipendente." ) }) return_url = reverse( 'gestione_peo:commissione_modulo_domanda_modifica', args=[commissione_id, domanda_id, modulo_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=True) 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, 'commissione_modulo_form_modifica.html', d)
def ticket_clone(request, ticket_id): master_ticket = get_object_or_404(Ticket, code=ticket_id, created_by=request.user) # if ticket is not closed and owner has closed it if not master_ticket.is_closed: return custom_message( request, _("Operazione non permessa. " "Il ticket è ancora attivo")) # if ticket module is out of date if not master_ticket.input_module.is_active: return custom_message( request, _("Il modulo che stai cercando " "di usare non è più attivo.")) category = master_ticket.input_module.ticket_category data = master_ticket.get_modulo_compilato() data['ticket_subject'] = master_ticket.subject data['ticket_description'] = master_ticket.description form = master_ticket.input_module.get_form(data=data, show_conditions=True) title = category template = 'user/ticket_add_new.html' sub_title = category.description if category.description else _( "Compila i campi richiesti") clausole_categoria = category.get_conditions() d = { 'categoria': category, 'category_conditions': clausole_categoria, 'form': form, 'struttura': category.organizational_structure, 'sub_title': '{} - {}'.format(category.organizational_structure, sub_title), 'title': title } if request.POST: form = master_ticket.input_module.get_form(data=request.POST, files=request.FILES, show_conditions=True) d['form'] = form if form.is_valid(): fields_to_pop = [ settings.TICKET_CONDITIONS_FIELD_ID, settings.TICKET_SUBJECT_ID, settings.TICKET_DESCRIPTION_ID ] json_data = get_POST_as_json(request=request, fields_to_pop=fields_to_pop) # make a UUID based on the host ID and current time code = uuid_code() subject = form.cleaned_data[settings.TICKET_SUBJECT_ID] description = form.cleaned_data[settings.TICKET_DESCRIPTION_ID] ticket = Ticket(code=code, subject=subject, description=description, modulo_compilato=json_data, created_by=request.user, input_module=master_ticket.input_module) ticket.save() # log action logger.info('[{}] user {} created new ticket {}' ' in category {}'.format(timezone.now(), request.user.username, ticket, category)) # salvataggio degli allegati nella cartella relativa json_dict = ticket.get_modulo_compilato() json_stored = get_as_dict(compiled_module_json=json_dict) _save_new_ticket_attachments(ticket=ticket, json_stored=json_stored, form=form, request_files=request.FILES) # Old version. Now a category MUST have an office! # office = categoria.organizational_office or struttura.get_default_office() office = category.organizational_office ticket_assignment = TicketAssignment(ticket=ticket, office=office) # assigned_by=request.user) ticket_assignment.save() if category.is_notify: random_office_operator = OrganizationalStructureOfficeEmployee.get_default_operator_or_manager( office) # if ticket is a notify, take the ticket _close_notification_ticket(ticket=ticket, user=request.user, operator=random_office_operator, ticket_assignment=ticket_assignment) # log action logger.info('[{}] ticket {} assigned to ' '{} office'.format(timezone.now(), ticket, office)) # category default tasks _assign_default_tasks_to_new_ticket(ticket=ticket, category=category, log_user=request.user) # Send mail to ticket owner ticket_message = ticket.input_module.ticket_category.confirm_message_text or \ settings.NEW_TICKET_CREATED_ALERT compiled_message = ticket_message.format(ticket.subject) mail_params = { 'hostname': settings.HOSTNAME, 'user': request.user, 'ticket': ticket.code, 'ticket_subject': subject, 'url': request.build_absolute_uri( reverse('uni_ticket:ticket_detail', kwargs={'ticket_id': ticket.code})), 'added_text': compiled_message } # if office operators must receive notification email if category.receive_email: # Send mail to ticket owner _send_new_ticket_mail_to_operators(request=request, ticket=ticket, category=category) m_subject = _('{} - {}'.format(settings.HOSTNAME, compiled_message)) m_subject = m_subject[:80] + (m_subject[80:] and '...') send_custom_mail(subject=m_subject, recipient=request.user, body=settings.NEW_TICKET_CREATED, params=mail_params) # END Send mail to ticket owner messages.add_message(request, messages.SUCCESS, compiled_message) return redirect('uni_ticket:ticket_detail', ticket_id=ticket.code) else: 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, template, d)
def ticket_message(request, ticket_id): """ Ticket messages page :param ticket_id: String :type ticket_id: ticket code :return: render """ ticket = get_object_or_404(Ticket, code=ticket_id) title = _("Messaggi") sub_title = ticket # Conversazione utente-operatori ticket_replies = TicketReply.objects.filter(ticket=ticket) form = ReplyForm() # if ticket.is_open(): agent_replies = ticket_replies.filter(read_by=None).exclude(structure=None) for reply in agent_replies: reply.read_by = request.user reply.read_date = timezone.now() reply.save(update_fields=['read_by', 'read_date']) if request.method == 'POST': if not ticket.is_open(): # log action logger.info('[{}] user {} tried to submit' ' a message for the not opened ticket {}'.format( timezone.now(), request.user, ticket)) return custom_message(request, _("Il ticket non è modificabile")) form = ReplyForm(request.POST, request.FILES) if form.is_valid(): ticket_reply = TicketReply() ticket_reply.subject = form.cleaned_data['subject'] ticket_reply.text = get_text_with_hrefs( escape(form.cleaned_data['text'])) ticket_reply.attachment = form.cleaned_data['attachment'] ticket_reply.ticket = ticket ticket_reply.owner = request.user ticket_reply.save() # log action logger.info('[{}] user {} submitted a message' ' for ticket {}'.format(timezone.now(), request.user, ticket)) # Send mail to ticket owner mail_params = { 'hostname': settings.HOSTNAME, 'status': _("inviato"), 'ticket': ticket, 'user': request.user, 'url': request.build_absolute_uri( reverse('uni_ticket:ticket_message', kwargs={'ticket_id': ticket.code})) } m_subject = _('{} - ticket {} messaggio inviato'.format( settings.HOSTNAME, ticket)) send_custom_mail(subject=m_subject, recipient=request.user, body=settings.USER_TICKET_MESSAGE, params=mail_params) # END Send mail to ticket owner messages.add_message(request, messages.SUCCESS, _("Messaggio inviato con successo")) return redirect('uni_ticket:ticket_message', ticket_id=ticket_id) else: for k, v in get_labeled_errors(form).items(): messages.add_message(request, messages.ERROR, "<b>{}</b>: {}".format(k, strip_tags(v))) d = { 'form': form, 'sub_title': sub_title, 'ticket': ticket, 'ticket_replies': ticket_replies, 'title': title, } template = 'user/ticket_assistance.html' return render(request, template, d)
def ticket_edit(request, ticket_id): """ Edit ticket details while it is unassigned Note: formset validation is in widget (._fill_body method) :type ticket_id: String :param ticket_id: ticket code :return: render """ ticket = get_object_or_404(Ticket, code=ticket_id) categoria = ticket.input_module.ticket_category title = _("Modifica ticket") sub_title = ticket allegati = ticket.get_allegati_dict() path_allegati = get_path(ticket.get_folder()) form = ticket.compiled_form(files=None, remove_filefields=allegati) form_allegati = ticket.compiled_form(files=None, remove_filefields=False, remove_datafields=True) template = "user/ticket_edit.html" d = { 'allegati': allegati, 'categoria': categoria, 'form': form, 'form_allegati': form_allegati, 'path_allegati': path_allegati, 'sub_title': sub_title, 'ticket': ticket, 'title': title, } if request.method == 'POST': fields_to_pop = [settings.TICKET_CONDITIONS_FIELD_ID] json_post = get_POST_as_json(request=request, fields_to_pop=fields_to_pop) json_response = json.loads(json_post) # Costruisco il form con il json dei dati inviati e tutti gli allegati # json_response[settings.ATTACHMENTS_DICT_PREFIX]=allegati # rimuovo solo gli allegati che sono stati già inseriti modulo = ticket.get_form_module() form = modulo.get_form(data=json_response, files=request.FILES, remove_filefields=allegati) d['form'] = form if form.is_valid(): if request.FILES: json_response[settings.ATTACHMENTS_DICT_PREFIX] = allegati path_allegati = get_path(ticket.get_folder()) for key, value in request.FILES.items(): nome_allegato = form.cleaned_data[key]._name # form.validate_attachment(request.FILES.get(key)) save_file(form.cleaned_data[key], path_allegati, nome_allegato) json_response[settings.ATTACHMENTS_DICT_PREFIX][ "{}".format(key)] = "{}".format(nome_allegato) elif allegati: # Se non ho aggiornato i miei allegati lasciandoli invariati rispetto # all'inserimento precedente json_response[settings.ATTACHMENTS_DICT_PREFIX] = allegati # salva il modulo ticket.save_data(form.cleaned_data[settings.TICKET_SUBJECT_ID], form.cleaned_data[settings.TICKET_DESCRIPTION_ID], json_response) # data di modifica ticket.update_log(user=request.user, note=_("Ticket modificato")) # log action logger.info('[{}] user {} edited ticket {}'.format( timezone.now(), request.user, ticket)) # Allega il messaggio al redirect messages.add_message(request, messages.SUCCESS, _("Modifica effettuata con successo")) return redirect('uni_ticket:ticket_edit', ticket_id=ticket_id) else: 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, template, d)
def ticket_add_new(request, structure_slug, category_slug): """ Create the ticket :type structure_slug: String :type category_slug: String :param structure_slug: slug of structure :param category_slug: slug of category :return: render """ struttura = get_object_or_404(OrganizationalStructure, slug=structure_slug, is_active=True) category = get_object_or_404(TicketCategory, slug=category_slug) if not category.is_active: return custom_message(request, category.not_available_message, status=404) # if anonymous user and category only for logged users if not category.allow_anonymous and not request.user.is_authenticated: return redirect('{}?next={}'.format(settings.LOGIN_URL, request.path)) # is user is authenticated if request.user.is_authenticated: # check ticket number limit if Ticket.number_limit_reached_by_user(request.user): messages.add_message( request, messages.ERROR, _("Hai raggiunto il limite massimo giornaliero" " di ticket: <b>{}</b>" "".format(settings.MAX_DAILY_TICKET_PER_USER))) return redirect('uni_ticket:user_dashboard') # check if user is allowed to access this category if not category.allowed_to_user(request.user): return custom_message( request, _("Permesso negato a questa tipologia di utente.")) title = category template = 'user/ticket_add_new.html' sub_title = category.description if category.description else _( "Compila i campi richiesti") modulo = get_object_or_404(TicketCategoryModule, ticket_category=category, is_active=True) form = modulo.get_form(show_conditions=True, current_user=request.user) clausole_categoria = category.get_conditions() d = { 'categoria': category, 'category_conditions': clausole_categoria, 'form': form, 'struttura': struttura, 'sub_title': '{} - {}'.format(struttura, sub_title), 'title': title } # after form submit if request.POST: form = modulo.get_form(data=request.POST, files=request.FILES, show_conditions=True, current_user=request.user) d['form'] = form if form.is_valid(): fields_to_pop = [ settings.TICKET_CONDITIONS_FIELD_ID, settings.TICKET_SUBJECT_ID, settings.TICKET_DESCRIPTION_ID, settings.TICKET_CAPTCHA_ID, settings.TICKET_CAPTCHA_HIDDEN_ID ] json_data = get_POST_as_json(request=request, fields_to_pop=fields_to_pop) # make a UUID based on the host ID and current time code = uuid_code() subject = form.cleaned_data[settings.TICKET_SUBJECT_ID] description = form.cleaned_data[settings.TICKET_DESCRIPTION_ID] # destination office office = category.organizational_office # take a random operator (or manager) # only if category is_notify or user is anonymous random_office_operator = None if category.is_notify or not request.user.is_authenticated: # get random operator from the office random_office_operator = OrganizationalStructureOfficeEmployee.get_default_operator_or_manager( office) # set users (for current operation and for log) current_user = request.user if request.user.is_authenticated else random_office_operator log_user = request.user.username if request.user.is_authenticated else 'anonymous' # create ticket ticket = Ticket(code=code, subject=subject, description=description, modulo_compilato=json_data, created_by=current_user, input_module=modulo) ticket.save() # log action logger.info('[{}] user {} created new ticket {}' ' in category {}'.format(timezone.now(), log_user, ticket, category)) # salvataggio degli allegati nella cartella relativa json_dict = json.loads(json_data) json_stored = get_as_dict(compiled_module_json=json_dict) _save_new_ticket_attachments(ticket=ticket, json_stored=json_stored, form=form, request_files=request.FILES) ticket_assignment = TicketAssignment(ticket=ticket, office=office) ticket_assignment.save() # if it's a notification ticket, take and close the ticket if category.is_notify: _close_notification_ticket(ticket=ticket, user=current_user, operator=random_office_operator, ticket_assignment=ticket_assignment) # log action logger.info('[{}] ticket {} assigned to ' '{} office'.format(timezone.now(), ticket, office)) # category default tasks _assign_default_tasks_to_new_ticket(ticket=ticket, category=category, log_user=log_user) ticket_message = ticket.input_module.ticket_category.confirm_message_text or \ settings.NEW_TICKET_CREATED_ALERT compiled_message = ticket_message.format(ticket.subject) messages.add_message(request, messages.SUCCESS, compiled_message) # if office operators must receive notification email if category.receive_email: # Send mail to ticket owner _send_new_ticket_mail_to_operators(request=request, ticket=ticket, category=category) # if user is authenticated send mail and redirect to ticket page if request.user.is_authenticated: # Send mail to ticket owner mail_params = { 'hostname': settings.HOSTNAME, 'user': request.user, 'ticket': ticket.code, 'ticket_subject': subject, 'url': request.build_absolute_uri( reverse('uni_ticket:ticket_detail', kwargs={'ticket_id': ticket.code})), 'added_text': compiled_message } m_subject = _('{} - {}'.format(settings.HOSTNAME, compiled_message)) m_subject = m_subject[:80] + (m_subject[80:] and '...') send_custom_mail(subject=m_subject, recipient=request.user, body=settings.NEW_TICKET_CREATED, params=mail_params) # END Send mail to ticket owner return redirect('uni_ticket:ticket_detail', ticket_id=ticket.code) else: return redirect('uni_ticket:add_new_ticket', structure_slug=structure_slug, category_slug=category_slug) else: 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, template, d)
def commissione_domanda_duplica_titolo_confirm(request, commissione_id, domanda_id, modulo_id, descrizione_indicatore_id, commissione, commissione_user): bando = commissione.bando # recupero la domanda peo del dipendente domanda_bando = get_object_or_404(DomandaBando, pk=domanda_id, bando=bando) dipendente = domanda_bando.dipendente descrizione_indicatore = get_object_or_404(DescrizioneIndicatore, pk=descrizione_indicatore_id) mdb = get_object_or_404(ModuloDomandaBando, pk=modulo_id, domanda_bando__dipendente=dipendente) # 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 posizione o il ruolo del dipendente" " risultano disabilitati" " all'accesso a questo modulo.") }) form = mdb.compiled_form(remove_filefields=False, other_form_source=descrizione_indicatore) 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) url_commissioni = reverse('gestione_peo:commissioni') url_commissione = reverse('gestione_peo:dettaglio_commissione', args=[commissione_id]) url_manage = reverse('gestione_peo:manage_commissione', args=[commissione_id]) url_domanda = reverse('gestione_peo:commissione_domanda_manage', args=[commissione_id, domanda_id]) url_modulo = reverse('gestione_peo:commissione_modulo_domanda_modifica', args=[commissione_id, domanda_id, modulo_id]) url_categoria_duplicazione = reverse( 'gestione_peo:commissione_domanda_duplica_titolo', args=[commissione_id, domanda_id, modulo_id]) page_url = reverse('gestione_peo:commissione_domanda_scegli_titolo', args=[commissione_id, domanda_id]) page_title = 'Duplicazione in ({}) {}'.format( descrizione_indicatore.id_code, descrizione_indicatore.nome) _breadcrumbs.reset() _breadcrumbs.add_url((url_commissioni, 'Commissioni')) _breadcrumbs.add_url((url_commissione, commissione)) _breadcrumbs.add_url((url_manage, 'Gestione domande')) _breadcrumbs.add_url((url_domanda, 'Domanda {}'.format(domanda_bando))) _breadcrumbs.add_url( (url_modulo, '({}) {}'.format(mdb.descrizione_indicatore.id_code, mdb.descrizione_indicatore.nome))) _breadcrumbs.add_url( (url_categoria_duplicazione, 'Selezione destinazione duplicazione')) _breadcrumbs.add_url((page_url, 'Compilazione')) commissioni = get_commissioni_attive(request.user) commissioni_in_corso = get_commissioni_in_corso(request.user, commissioni) d = { 'bando': bando, 'breadcrumbs': _breadcrumbs, 'commissione': commissione, 'commissioni': commissioni, 'commissioni_in_corso': commissioni_in_corso, 'descrizione_indicatore': descrizione_indicatore, 'dipendente': dipendente, 'domanda_bando': domanda_bando, 'form': form, 'mdb': mdb, 'page_title': page_title, } d['labeled_errors'] = get_labeled_errors(form) if request.method == 'POST': mdb.disabilita = True mdb.motivazione = MOTIVAZIONE_DISABILITAZIONE_DUPLICAZIONE.format( descrizione_indicatore.id_code, descrizione_indicatore.nome) mdb.save(update_fields=['disabilita', 'motivazione']) etichetta = mdb.get_identificativo_veloce() msg = ("Inserimento {} - Etichetta: {} - disabilitato con successo" ).format(mdb, etichetta) messages.add_message(request, messages.SUCCESS, msg) # Logging di ogni azione compiuta sulla domanda dalla commissione log_msg = LOG_DUPLICAZIONE_MESSAGE.format( origine=mdb, destinazione=descrizione_indicatore.id_code) LogEntry.objects.log_action( user_id=request.user.pk, content_type_id=ContentType.objects.get_for_model( domanda_bando).pk, object_id=domanda_bando.pk, object_repr=domanda_bando.__str__(), action_flag=CHANGE, change_message=log_msg) return_url = reverse('gestione_peo:commissione_domanda_manage', args=[ commissione_id, domanda_id, ]) result = aggiungi_titolo_form( request=request, bando=bando, descrizione_indicatore=descrizione_indicatore, domanda_bando=domanda_bando, dipendente=dipendente, return_url=return_url, log=True) 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, 'commissione_modulo_form_duplicazione.html', d)