def show_record(request, cliente_id, detail_type=None, impianto_id=None, sub_impianto_id=None, message_hdr='', message='', message_type=''): data, data_list = view_record(cliente_id, detail_type, impianto_id, sub_impianto_id) # Breadcrumb genarate from current url. b = "" r = re.compile("\w+\/\d+") #['anagrafe/33', 'impianto/33', 'verifica/33'] l = r.findall(request.path) if l: url = "/" if len(l) > 1: for i in l[:-1]: url += i + "/" s = __breadcrumbName(i) b += BREADCRUMB_ELEMENT % (url, s, BREADCRUMB_DIVIDER) url += l[-1] + "/" s = __breadcrumbName(l[-1]) b += BREADCRUMB_ELEMENT % (url, s, "") if data is None: return errors.server_error(request) return render(request, 'anagrafe.html', { 'data': data, 'data_list': data_list, 'notification': data_render.notification(message_hdr, message, message_type), 'scripts':scripts.ANAGRAFE_JS, 'breadcrumb': b, })
def add_record(request, cliente_id=None, detail_type=None, impianto_id=None, sub_impianto_id=None): script = "" data = "" data_list = "" notification = "" if cliente_id is None: header_msg = "Aggiungi Nuovo Cliente" post_url = "add/" else: if detail_type == 'impianto': header_msg = "Aggiungi Nuovo Impianto" post_url = "%s/impianto/add/" % cliente_id if detail_type == 'verifica': header_msg = "Aggiungi Nuova Verifica e Manutenzione" post_url = "%s/impianto/%s/verifica/add/" % (cliente_id, impianto_id) if detail_type == 'intervento': header_msg = "Aggiungi Nuovo Intervento" post_url = "%s/impianto/%s/intervento/add/" % (cliente_id, impianto_id) if detail_type is None: return errors.server_error(request) if request.method == 'GET': if cliente_id is None: form = models.ClienteForm() else: if detail_type == 'impianto': form = models.ImpiantoForm(initial={'cliente_impianto': models.Cliente.objects.get(pk=cliente_id)}) script = scripts.IMPIANTO_JS data, data_list = view_record(cliente_id, detail_type, impianto_id) if detail_type == 'verifica': form = models.VerificaForm(initial={'verifica_impianto': models.Impianto.objects.get(pk=impianto_id)}) script = scripts.VERIFICA_JS data, data_list = view_record(cliente_id, detail_type, impianto_id) if detail_type == 'intervento': form = models.InterventoForm(initial={'intervento_impianto': models.Impianto.objects.get(pk=impianto_id)}) script = scripts.INTERVENTO_JS data, data_list = view_record(cliente_id, detail_type, impianto_id) if request.method == 'POST': ret, d = __editAdd_record(cliente_id, impianto_id, sub_impianto_id, detail_type, request) if ret: return show_record(**d) else: request = d['request'] form = d['form'] notification = data_render.notification(d['message_hdr'], d['message'], d['message_type']) return render(request, 'anagrafe_form.html', {'notification': notification, 'header_msg': data_render.TITLE_STYLE_FORM % header_msg, 'data_forms': form, 'data':data, 'scripts': script, 'post_url':post_url})
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, })