Пример #1
0
def __export_csv(data_table, filename="tabella"):
    # Create the HttpResponse object with the appropriate CSV header.
    response = http.HttpResponse(mimetype='text/csv')
    response['Content-Disposition'] = 'attachment; filename="%s_%s.csv"' % (filename, datetime.datetime.today().strftime("%d-%m-%Y"))

    export_list = user_settings.settings_columView('export_table')

    response.write("\xEF\xBB\xBF")
    writer = tools.UnicodeWriter(response, delimiter=';')
    writer.writerow(["%s" % j.replace('_', ' ').capitalize() for j in export_list])

    for item_dict in data_table:
        l = []
        for i in export_list:
            l.append(data_render.formatFields(item_dict, i, default_text="-"))

        writer.writerow(l)

    return response
Пример #2
0
def __export_xls(data_table, filename="tabella"):
    # Create the HttpResponse object with the appropriate CSV header.
    response = http.HttpResponse(mimetype='application/ms-excel; charset=utf-8')
    response['Content-Disposition'] = 'attachment; filename="%s_%s.xls"' % (filename, datetime.datetime.today().strftime("%d-%m-%Y"))

    book = xlwt.Workbook(encoding='utf-8')
    sheet = book.add_sheet('Elenco')

    #Add header
    export_list = user_settings.settings_columView('export_table')
    for colum,j in enumerate(export_list):
        sheet.write(0, colum, "%s" % j.replace('_', ' ').capitalize())

    #Write table
    for row,i in enumerate(data_table):
        for colum,j in enumerate(export_list):
            #we should skip the header row.
            sheet.write(row + 1, colum, data_render.formatFields(i,j, default_text="-"))

    book.save(response)
    return response
Пример #3
0
def anagrafe(request):
    form = myforms.FullTextSearchForm()
    data = ''

    search_string = ""
    data_to_render = []
    order_by_field = ""
    ordering = ""

    form_dict = {
            'search_keys' : "",
            'order_by_field' : "",
            'ordering' : "",
    }

    if request.method == 'GET' and request.GET != {}:
        form = myforms.FullTextSearchForm(request.GET)
        if form.is_valid():
                form_dict['search_keys'] = form.cleaned_data['search_keys']
                form_dict['order_by_field'] = form.cleaned_data['order_by_field']
                form_dict['ordering'] = form.cleaned_data['ordering']

        data_to_render = database_manager.search_fullText(**form_dict)
        dr = data_render.DataRender(data_to_render)

        dr.selectColums(user_settings.settings_columView('anagrafe_view'))

        dr.msgItemsEmpty("<br><h3>La ricerca non ha prodotto risultati.</h3>")
        if search_string != "":
            dr.msgStatistics(("<br><h2>\"%s\" trovati:" % search_string) + " %s</h2><br>")
        dr.showStatistics()
        dr.orderUrl('anagrafe', form_dict)
        data += dr.toTable()

    return render(request, 'anagrafe.html',{'query_path':request.get_full_path(),
                                           'data': data,
                                           'data_form': form,
                                           'scripts': '',
                                           })
Пример #4
0
def view_record(cliente_id, detail_type=None, impianto_id=None, sub_impianto_id=None, show_title=False, show_cliente=False, show_toolbar=True):
    """
    Data: record table format
    Data_list: record in list format
    Return data, data_list
    """
    if cliente_id == "":
            return None, None

    data = ""
    data_list = ""
    data_to_render = database_manager.search_clienteId(cliente_id)
    if not show_cliente and data_to_render:
        tb=""
        if show_toolbar:
            tb = TOOLBAR_CLIENTE
        cliente_list = user_settings.settings_columView('anagrafe_cliente_view')
        data_list = data_render.render_toList(data_to_render[0], cliente_list, "Dettaglio Cliente",
                toolbar=tb)

    dr = None
    # Show cliente and its impianti
    if detail_type is None:
        data_to_render = database_manager.search_clienteImpiantoSet(cliente_id)
        dr = data_render.DataRender(data_to_render)
        dr.showTitle("Elenco impianti")
        dr.selectColums(user_settings.settings_columView('anagrafe_impianto_view'))

        # edit and delete icons with related link
        toolbar_left = [
              TOOLBAR_ICO_EDIT % ("/anagrafe/{cliente_id}/impianto/{impianto_id}/edit/", gestionale.settings.STATIC_URL),
              TOOLBAR_ICO_DELETE % ("Impianto", "Stai cancellando l'impianto selezionato, e anche tutte le verifiche e interventi relativi.",
                  "/anagrafe/{cliente_id}/impianto/{impianto_id}/delete/", gestionale.settings.STATIC_URL),
        ]

        # button to add new Impianto
        if data_to_render:
            toolbar_last = [
                TOOLBAR_BTN % ("/anagrafe/{cliente_id}/impianto/add/", "icon-plus", "Aggiungi un impianto"),
            ]
        else:
            toolbar_last = [
                TOOLBAR_BTN % ("/anagrafe/%s/impianto/add/" % (cliente_id), "icon-plus", "Aggiungi un impianto"),
            ]

        if show_toolbar:
            dr.toolbar(left=toolbar_left, last_row=toolbar_last)

        data += dr.toTable()

    # Show impianto and its verifiche/interventi
    elif detail_type == "impianto":
        data_to_render = database_manager.search_impiantoId(impianto_id)
        if data_to_render:
            data_list += data_render.render_toList(data_to_render[0], user_settings.settings_columView('anagrafe_impianto_view'), "Dettaglio Impianto",
                    toolbar=TOOLBAR_IMPIANTO)

            # Display all verifiche related to this impianto
            data_to_render = database_manager.search_impiantoVerificaSet(impianto_id)
            dr = data_render.DataRender(data_to_render)
            dr.showTitle("Elenco verifiche")
            dr.selectColums(user_settings.settings_columView('anagrafe_verifica_view'))
            # edit and delete icons with related link
            toolbar_left = [
                    TOOLBAR_ICO_EDIT % ("/anagrafe/{cliente_id}/impianto/{impianto_id}/verifica/{verifica_id}/edit/", gestionale.settings.STATIC_URL),
                    TOOLBAR_ICO_DELETE % ("Verifica", "Stai cancellando l'intervento selezionata.",
                        "/anagrafe/{cliente_id}/impianto/{impianto_id}/verifica/{verifica_id}/delete/", gestionale.settings.STATIC_URL)
            ]
            # button to add new Verifica
            if data_to_render:
                toolbar_last = [
                        TOOLBAR_BTN % ("/anagrafe/{cliente_id}/impianto/{impianto_id}/verifica/add/", "icon-plus", "Aggiungi una verifica.."),
                ]
            else:
                toolbar_last = [
                    TOOLBAR_BTN % ("/anagrafe/%s/impianto/%s/verifica/add/" % (cliente_id, impianto_id), "icon-plus", "Aggiungi un verifica.."),
                ]

            if show_toolbar:
                dr.toolbar(left=toolbar_left, last_row=toolbar_last)
            data += dr.toTable()


            # Display all intervento related to this impianto
            data_to_render = database_manager.search_impiantoInterventoSet(impianto_id)
            dr = data_render.DataRender(data_to_render)
            dr.showTitle("Elenco interventi")
            dr.selectColums(user_settings.settings_columView('anagrafe_intervento_view'))

            # edit and delete icons with related link
            toolbar_left = [
                    TOOLBAR_ICO_EDIT % ("/anagrafe/{cliente_id}/impianto/{impianto_id}/intervento/{intervento_id}/edit/",
                        gestionale.settings.STATIC_URL),
                    TOOLBAR_ICO_DELETE % ("Intervento", "Stai cancellando l'intervento selezionata.",
                        "/anagrafe/{cliente_id}/impianto/{impianto_id}/intervento/{intervento_id}/delete/", gestionale.settings.STATIC_URL)
            ]
            # button to add new Verifica
            if data_to_render:
                toolbar_last = [
                    TOOLBAR_BTN % ("/anagrafe/{cliente_id}/impianto/{impianto_id}/intervento/add/", "icon-plus", "Aggiungi un intervento.."),
                ]
            else:
                toolbar_last = [
                    TOOLBAR_BTN % ("/anagrafe/%s/impianto/%s/intervento/add/" % (cliente_id, impianto_id), "icon-plus", "Aggiungi un intervento.."),
                ]

            if show_toolbar:
                dr.toolbar(left=toolbar_left, last_row=toolbar_last)

            data += dr.toTable()

    elif detail_type == "verifica":
        data_to_render = database_manager.search_impiantoId(impianto_id)
        if data_to_render:
            data_list += data_render.render_toList(data_to_render[0], user_settings.settings_columView('anagrafe_impianto_view'), "Dettaglio Impianto",
                    toolbar=TOOLBAR_IMPIANTO)

        if sub_impianto_id is not None:
            if data_to_render:
                data_to_render = database_manager.search_verificaId(sub_impianto_id)
                data_list += data_render.render_toList(data_to_render[0], user_settings.settings_columView('anagrafe_verifica_view'), "Dettaglio Verifica e Manutenzioni",
                        toolbar=TOOLBAR_VERIFICA)

    elif detail_type == "intervento":
        data_to_render = database_manager.search_impiantoId(impianto_id)
        if data_to_render:
            data_list += data_render.render_toList(data_to_render[0], user_settings.settings_columView('anagrafe_impianto_view'), "Dettaglio Impianto",
                        toolbar=TOOLBAR_IMPIANTO)

        if sub_impianto_id is not None:
            data_to_render = database_manager.search_interventoId(sub_impianto_id)
            if data_to_render:
                data_list += data_render.render_toList(data_to_render[0], user_settings.settings_columView('anagrafe_intervento_view'), "Dettaglio Intervento",
                        toolbar=TOOLBAR_INTERVENTO)
    else:
        data = None
        data_list = None

    return data, data_list
Пример #5
0
def home(request, d={}):
    form = myforms.RangeDataSelect()
    data = ''
    notification = ''

    # Use default at first time when the home page is never loaded
    form_dict = {
            'search_keys' : "",
            'filter_type' : None,
            'ref_month' : None,
            'ref_year' : None,
            'order_by_field' : "",
            'ordering' : "",
    }

    if request.method == 'POST':
        selected_rows = request.POST.getlist('row_select', [])
        action = request.POST.get('button_action', '')
        if action == 'Lettera':
            ids = __getIds(selected_rows, data_render.CLIENTE_ID)
            data_to_render = database_manager.search_ids('main_cliente.id', ids)
            return generate_report(data_to_render)
        elif action == 'Scarica Tabella':
            ids = __getIds(selected_rows, data_render.CLIENTE_ID)
            data_to_render = database_manager.search_ids('main_cliente.id', ids)
            return __export_xls(data_to_render, "Elenco")
        else:
            for i in selected_rows:
                ids = i.split(',')
                verifica_id = ids[data_render.VERIFICA_ID]
                if verifica_id != 'None':
                    _id = int(verifica_id)
                    if action == 'Apri':
                        models.Verifica.objects.filter(id=_id).update(stato_verifica='A')
                    if action == 'Chiudi':
                        models.Verifica.objects.filter(id=_id).update(stato_verifica='C')
                    if action == 'Sospendi':
                        models.Verifica.objects.filter(id=_id).update(stato_verifica='S')


    if request.method == 'GET' and request.GET != {}:
        form = myforms.RangeDataSelect(request.GET)
        if form.is_valid():
            form_dict['search_keys'] = form.cleaned_data['search_keys']
            form_dict['filter_type'] = form.cleaned_data['filter_type']
            form_dict['ref_month'] = form.cleaned_data['ref_month']
            form_dict['ref_year'] = form.cleaned_data['ref_year']
            form_dict['order_by_field'] = form.cleaned_data['order_by_field']
            form_dict['ordering'] = form.cleaned_data['ordering']

    data_to_render = database_manager.search_inMonth(**form_dict)
    dr = data_render.DataRender(data_to_render)

    dr.selectColums(user_settings.settings_columView('home_view'))
    tb_top = [
            "<button class=\"btn btn-info dropdown-toggle\" data-toggle=\"dropdown\">Seleziona \
            <span class=\"caret\"></span></button> \
            <ul class=\"dropdown-menu\"> \
            <li><a id=\"action\" href=\"#\">Aperti</a></li> \
            <li><a id=\"action\" href=\"#\">Sospesi</a></li> \
            <li><a id=\"action\" href=\"#\">Chiusi</a></li> \
            <li class=\"divider\"></li> \
            <li><a id=\"action\" href=\"#\">Tutti</a></li> \
            <li><a id=\"action\" href=\"#\">Nessuno</a></li> \
            </ul>",
            "<input class=\"btn btn-info\" type=\"submit\" name=\"button_action\" value=\"Apri\">",
            "<input class=\"btn btn-info\" type=\"submit\" name=\"button_action\" value=\"Chiudi\">",
            "<input class=\"btn btn-info\" type=\"submit\" name=\"button_action\" value=\"Sospendi\">",
            "<input class=\"btn btn-info\" type=\"submit\" name=\"button_action\" value=\"Lettera\">",
            "<input class=\"btn btn-info\" type=\"submit\" name=\"button_action\" value=\"Scarica Tabella\">",
    ]

    tb_left = [
            "<input type=\"checkbox\" name=\"row_select\" id=\"{stato_verifica}\" value=\"{cliente_id},{impianto_id},{verifica_id},{intervento_id}\">"
    ]
    dr.toolbar(top=tb_top, left=tb_left)

    dr.msgItemsEmpty("<br><h3>La ricerca non ha prodotto risultati.</h3>")
    dr.msgStatistics(("<br><h2>Nel mese di %s " % myforms.monthStr(form_dict['ref_month'])) + "COUNT interventi in scadenza.</h2><br>")
    dr.showStatistics()

    dr.orderUrl('home', form_dict)
    data += dr.toTable()


    form_dict['status'] = True
    data_to_render = database_manager.search_inMonth(**form_dict)
    dr = data_render.DataRender(data_to_render)
    dr.selectColums(user_settings.settings_columView('home_view'))
    dr.toolbar(top=tb_top, left=tb_left)
    dr.msgItemsEmpty("")
    dr.msgStatistics(("<br><h2>N.COUNT interventi chiusi nel mese di %s" % myforms.monthStr(form_dict['ref_month'])) + ".</h2><br>")
    dr.showStatistics()
    data += dr.toTable()


    if d:
       notification = data_render.notification(d['message_hdr'], d['message'], d['message_type'])

    return render(request, 'home.html',{'query_path':request.get_full_path(),
                                       'notification': notification,
                                       'data': data,
                                       'data_form': form,
                                       'scripts': scripts.HOME_ADD_JS,
                                       })